blacklight-maps 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,62 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'spec_helper'
2
3
 
3
4
  describe BlacklightMapsHelper do
4
- include ERB::Util
5
- include BlacklightMapsHelper
6
5
 
7
6
  let(:blacklight_config) { Blacklight::Configuration.new }
8
-
9
- describe "show_map_div" do
10
- before :each do
11
- helper.stub(blacklight_config: blacklight_config)
7
+
8
+ def create_response
9
+ raw_response = eval(mock_query_response)
10
+ Blacklight::SolrResponse.new(raw_response, raw_response['params'])
11
+ end
12
+
13
+ let(:r) { create_response }
14
+
15
+ before :each do
16
+ CatalogController.blacklight_config = Blacklight::Configuration.new
17
+ CatalogController.configure_blacklight do |config|
18
+ config.view.maps.type = 'placename_coord'
19
+
20
+ # These fields also need to be added for some reason for the tests to pass
21
+ # Link in list is not being generated correctly if not passed
22
+ config.index.title_field = 'title_display'
12
23
  end
24
+ helper.stub(blacklight_config: blacklight_config)
25
+ helper.instance_variable_set(:@response, r)
26
+ @request = ActionDispatch::TestRequest.new
27
+ @catalog = CatalogController.new
28
+ @catalog.request = @request
29
+ helper.instance_variable_set(:@_controller, @catalog)
30
+ end
31
+
32
+ describe "#blacklight_map_tag" do
13
33
 
14
- it "should have #map div" do
15
- expect(helper.show_map_div).to have_selector("div#blacklight-map")
34
+ context "with default values" do
35
+ subject { helper.blacklight_map_tag('blacklight-map') }
36
+ it { should have_selector "div#blacklight-map" }
37
+ it { should have_selector "div[data-maxzoom='8'][data-tileurl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'][data-mapattribution='Map data &copy; <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>']" }
16
38
  end
17
39
 
18
- it "should contain data-attributes" do
19
- expect(helper.show_map_div).to have_selector("div[data-maxzoom='8']")
40
+ context "with custom values" do
41
+ subject { helper.blacklight_map_tag('blacklight-map', data: {maxzoom: 6, tileurl: 'http://example.com/', mapattribution: 'hello world' }) }
42
+ it { should have_selector "div[data-maxzoom='6'][data-tileurl='http://example.com/'][data-mapattribution='hello world']" }
20
43
  end
21
44
 
45
+ context "when a block is provided" do
46
+ subject { helper.blacklight_map_tag('foo') { content_tag(:span, 'bar') } }
47
+ it { should have_selector('div > span', text: 'bar') }
48
+ end
49
+
50
+ end
51
+
52
+ describe "serialize_geojson" do
53
+ it "should return geojson of documents" do
54
+ expect(helper.serialize_geojson).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
55
+ end
22
56
  end
23
57
 
24
- # TODO Test geoJSON serialization
25
-
26
-
58
+ def mock_query_response
59
+ %({"responseHeader"=>{"status"=>0, "QTime"=>14, "params"=>{"q"=>"tibet", "spellcheck.q"=>"tibet", "qt"=>"search", "wt"=>"ruby", "rows"=>"10"}}, "response"=>{"numFound"=>2, "start"=>0, "maxScore"=>0.016135123, "docs"=>[{"published_display"=>["Dharamsala, H.P."], "author_display"=>"Thub-bstan-yar-ʼphel, Rnam-grwa", "lc_callnum_display"=>["DS785 .T475 2005"], "pub_date"=>["2005"], "format"=>"Book", "material_type_display"=>["a-e, iv, ii, 407 p."], "title_display"=>"Bod gaṅs can gyi rgyal rabs mdor bsdus dris lan brgya pa rab gsal śel gyi me loṅ źes bya ba bźugs so", "id"=>"2008308202", "subject_geo_facet"=>["Tibet (China)"], "language_facet"=>["Tibetan"], "placename_coords"=>["Tibet (China)-|-29.646923-|-91.117212"], "place_bbox"=>"78.3955448 26.8548157 99.116241 36.4833345", "score"=>0.016135123}, {"published_display"=>["Dharamsala, Distt. Kangra, H.P."], "pub_date"=>["2007"], "format"=>"Book", "title_display"=>"Ses yon", "material_type_display"=>["xii, 419 p."], "id"=>"2008308478", "subject_geo_facet"=>["China", "Tibet", "India"], "subject_topic_facet"=>["Education and state", "Tibetans", "Tibetan language", "Teaching"], "language_facet"=>["Tibetan"], "placename_coords"=>["China-|-35.86166-|-104.195397", "Tibet-|-29.646923-|-91.117212", "India-|-20.593684-|-78.96288"], "place_bbox"=>"68.162386 6.7535159 97.395555 35.5044752", "score"=>0.0026767207}]}, "facet_counts"=>{"facet_queries"=>{}, "facet_fields"=>{"format"=>["Book", 2], "lc_1letter_facet"=>["D - World History", 1], "lc_alpha_facet"=>["DS", 1], "lc_b4cutter_facet"=>["DS785", 1], "language_facet"=>["Tibetan", 2], "pub_date"=>["2005", 1, "2007", 1], "subject_era_facet"=>[], "subject_geo_facet"=>["China", 1, "India", 1, "Tibet", 1, "Tibet (China)", 1], "subject_topic_facet"=>["Education and state", 1, "Teaching", 1, "Tibetan language", 1, "Tibetans", 1]}, "facet_dates"=>{}, "facet_ranges"=>{}}, "spellcheck"=>{"suggestions"=>["tibet", {"numFound"=>1, "startOffset"=>0, "endOffset"=>5, "origFreq"=>2, "suggestion"=>[{"word"=>"tibetan", "freq"=>6}]}, "correctlySpelled", true]}})
60
+ end
27
61
 
28
- end
62
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe "BlacklightMaps::GeojsonExport" do
4
+
5
+ before do
6
+ CatalogController.blacklight_config = Blacklight::Configuration.new
7
+ CatalogController.configure_blacklight do |config|
8
+ config.view.maps.type = 'placename_coord'
9
+
10
+ # These fields also need to be added for some reason for the tests to pass
11
+ # Link in list is not being generated correctly if not passed
12
+ config.index.title_field = 'title_display'
13
+ end
14
+ @controller = CatalogController.new
15
+ @request = ActionDispatch::TestRequest.new
16
+ @controller.request = @request
17
+ @response = ActionDispatch::TestResponse.new
18
+ @response.stub(:docs) {[{ "published_display"=>["Dharamsala, Distt. Kangra, H.P."], "pub_date"=>["2007"], "format"=>"Book", "title_display"=>"Ses yon", "material_type_display"=>["xii, 419 p."], "id"=>"2008308478", "subject_geo_facet"=>["China", "Tibet", "India"], "subject_topic_facet"=>["Education and state", "Tibetans", "Tibetan language", "Teaching"], "language_facet"=>["Tibetan"], "placename_coords"=>["China-|-35.86166-|-104.195397", "Tibet-|-29.646923-|-91.117212", "India-|-20.593684-|-78.96288"], "place_bbox"=>["68.162386 6.7535159 97.395555 35.5044752"], "score"=>0.0026767207 }]}
19
+ end
20
+
21
+ subject {BlacklightMaps::GeojsonExport.new(@controller, @response.docs)}
22
+
23
+ it "should instantiate GeojsonExport" do
24
+ expect(subject.class).to eq(::BlacklightMaps::GeojsonExport)
25
+ end
26
+
27
+ it "should return maps config" do
28
+ expect(subject.send(:blacklight_maps_config).class).to eq(::Blacklight::Configuration::ViewConfig)
29
+ end
30
+
31
+ it "should return type" do
32
+ expect(subject.send(:type)).to eq('placename_coord')
33
+ end
34
+
35
+ it "should return placename field" do
36
+ expect(subject.send(:placename_coord_field)).to eq('placename_coords')
37
+ end
38
+
39
+ it "should return placename delimiter" do
40
+ expect(subject.send(:placename_coord_delimiter)).to eq('-|-')
41
+ end
42
+
43
+ it "should return bbox field" do
44
+ expect(subject.send(:bbox_field)).to eq('place_bbox')
45
+ end
46
+
47
+ it "should return point feature with no properties" do
48
+ expect(subject.send(:build_point_feature, 100, -50)).to eq({:type=>"Feature", :geometry=>{:type=>"Point", :coordinates=>[100.0, -50.0]}, :properties=>{}})
49
+ end
50
+
51
+ it "should return point feature with properties" do
52
+ expect(subject.send(:build_point_feature, 100, -50, { name: 'Jane Smith' })[:properties]).to have_key(:name)
53
+ end
54
+
55
+ it "should build bbox correct features" do
56
+ expect(subject.send(:build_bbox_features).length).to eq(1)
57
+ expect(subject.send(:build_bbox_features)[0][:geometry][:type]).to eq('Point')
58
+ end
59
+
60
+ it "should render correct sidebar div" do
61
+ expect(subject.send(:render_leaflet_sidebar_partial, @response.docs[0])).to include('href="/catalog/2008308478">')
62
+ end
63
+
64
+ it "should render feature collection as json" do
65
+ expect(subject.to_geojson).to include('{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point"')
66
+ end
67
+
68
+
69
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "BlacklightMaps::Geometry::BoundingBox" do
4
+
5
+ let(:bbox) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-100 -50 100 50') }
6
+ let(:bbox_california) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-124.4096196 32.5342321 -114.131211 42.0095169') }
7
+
8
+ it "should instantiate Geometry::BoundingBox" do
9
+ expect(bbox.class).to eq(::BlacklightMaps::Geometry::BoundingBox)
10
+ end
11
+
12
+ it "should return center of simple bounding box" do
13
+ expect(bbox.find_center).to eq([0.0, 0.0])
14
+ end
15
+
16
+ it "should return center of California bounding box" do
17
+ expect(bbox_california.find_center).to eq([-119.2704153, 37.271874499999996])
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -35,4 +35,4 @@ require 'capybara/rspec'
35
35
 
36
36
  RSpec.configure do |config|
37
37
 
38
- end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-12 00:00:00.000000000 Z
12
+ date: 2014-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -222,6 +222,8 @@ files:
222
222
  - docs/map-view.png
223
223
  - lib/blacklight/maps.rb
224
224
  - lib/blacklight/maps/engine.rb
225
+ - lib/blacklight/maps/export.rb
226
+ - lib/blacklight/maps/geometry.rb
225
227
  - lib/blacklight/maps/version.rb
226
228
  - lib/generators/blacklight_maps/install_generator.rb
227
229
  - lib/generators/blacklight_maps/templates/blacklight_maps.css.scss
@@ -231,6 +233,8 @@ files:
231
233
  - spec/features/maps_spec.rb
232
234
  - spec/fixtures/sample_solr_documents.yml
233
235
  - spec/helpers/blacklight_maps_helper_spec.rb
236
+ - spec/lib/blacklight/maps/export_spec.rb
237
+ - spec/lib/blacklight/maps/geometry_spec.rb
234
238
  - spec/spec_helper.rb
235
239
  - spec/test_app_templates/Gemfile.extra
236
240
  - spec/test_app_templates/lib/generators/test_app_generator.rb
@@ -262,6 +266,8 @@ test_files:
262
266
  - spec/features/maps_spec.rb
263
267
  - spec/fixtures/sample_solr_documents.yml
264
268
  - spec/helpers/blacklight_maps_helper_spec.rb
269
+ - spec/lib/blacklight/maps/export_spec.rb
270
+ - spec/lib/blacklight/maps/geometry_spec.rb
265
271
  - spec/spec_helper.rb
266
272
  - spec/test_app_templates/Gemfile.extra
267
273
  - spec/test_app_templates/lib/generators/test_app_generator.rb