blacklight-maps 0.5.2 → 1.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.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +99 -0
  4. data/.solr_wrapper.yml +7 -0
  5. data/.travis.yml +19 -16
  6. data/Gemfile +40 -7
  7. data/README.md +13 -12
  8. data/Rakefile +35 -32
  9. data/app/assets/images/blacklight/maps.svg +1 -0
  10. data/app/assets/javascripts/blacklight-maps.js +1 -4
  11. data/app/assets/javascripts/blacklight-maps/blacklight-maps-browse.js +7 -8
  12. data/app/assets/stylesheets/blacklight_maps/blacklight-maps.scss +1 -2
  13. data/app/assets/stylesheets/blacklight_maps/default.scss +7 -10
  14. data/app/helpers/blacklight/blacklight_maps_helper_behavior.rb +81 -86
  15. data/app/helpers/blacklight_maps_helper.rb +2 -0
  16. data/app/views/catalog/_show_maplet_default.html.erb +8 -9
  17. data/app/views/catalog/map.html.erb +2 -2
  18. data/blacklight-maps.gemspec +27 -26
  19. data/config/locales/blacklight-maps-zh.yml +7 -7
  20. data/config/locales/blacklight-maps.ar.yml +21 -0
  21. data/config/locales/blacklight-maps.de.yml +21 -0
  22. data/config/locales/blacklight-maps.en.yml +1 -1
  23. data/config/locales/blacklight-maps.es.yml +21 -0
  24. data/config/locales/blacklight-maps.fr.yml +8 -8
  25. data/config/locales/blacklight-maps.hu.yml +21 -0
  26. data/config/locales/blacklight-maps.it.yml +8 -8
  27. data/config/locales/blacklight-maps.nl.yml +21 -0
  28. data/config/locales/blacklight-maps.pt-BR.yml +21 -0
  29. data/config/locales/blacklight-maps.sq.yml +21 -0
  30. data/config/routes.rb +3 -2
  31. data/lib/blacklight/maps.rb +8 -2
  32. data/lib/blacklight/maps/controller.rb +27 -0
  33. data/lib/blacklight/maps/engine.rb +12 -13
  34. data/lib/blacklight/maps/export.rb +112 -93
  35. data/lib/blacklight/maps/geometry.rb +30 -18
  36. data/lib/blacklight/maps/maps_search_builder.rb +4 -3
  37. data/lib/blacklight/maps/render_constraints_override.rb +63 -29
  38. data/lib/blacklight/maps/version.rb +3 -1
  39. data/lib/generators/blacklight_maps/install_generator.rb +38 -31
  40. data/lib/generators/blacklight_maps/templates/search_history_controller.rb +2 -0
  41. data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/schema.xml +0 -0
  42. data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/solrconfig.xml +0 -0
  43. data/lib/railties/blacklight_maps.rake +10 -7
  44. data/spec/controllers/catalog_controller_spec.rb +20 -10
  45. data/spec/fixtures/sample_solr_documents.yml +909 -906
  46. data/spec/helpers/blacklight_maps_helper_spec.rb +60 -108
  47. data/spec/lib/blacklight/maps/export_spec.rb +109 -143
  48. data/spec/lib/blacklight/maps/geometry_spec.rb +34 -21
  49. data/spec/lib/blacklight/maps/maps_search_builder_spec.rb +17 -21
  50. data/spec/lib/blacklight/maps/render_constraints_override_spec.rb +42 -69
  51. data/spec/spec_helper.rb +19 -21
  52. data/spec/system/index_view_spec.rb +127 -0
  53. data/spec/system/initial_view_spec.rb +28 -0
  54. data/spec/system/map_view_spec.rb +50 -0
  55. data/spec/system/show_view_maplet_spec.rb +78 -0
  56. data/spec/test_app_templates/lib/generators/test_app_generator.rb +6 -21
  57. data/vendor/assets/images/layers-2x.png +0 -0
  58. data/vendor/assets/images/layers.png +0 -0
  59. data/vendor/assets/images/marker-icon-2x.png +0 -0
  60. data/vendor/assets/images/marker-icon.png +0 -0
  61. data/vendor/assets/images/marker-shadow.png +0 -0
  62. data/vendor/assets/javascripts/leaflet.js.erb +13922 -0
  63. data/vendor/assets/javascripts/leaflet.markercluster.js +3 -0
  64. data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
  65. data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
  66. data/vendor/assets/stylesheets/leaflet.css +635 -0
  67. metadata +86 -91
  68. data/config/jetty.yml +0 -7
  69. data/lib/blacklight/maps/controller_override.rb +0 -20
  70. data/lib/generators/blacklight_maps/templates/saved_searches_controller.rb +0 -5
  71. data/spec/features/initial_view_spec.rb +0 -21
  72. data/spec/features/maps_spec.rb +0 -202
  73. data/spec/features/show_view_maplet_spec.rb +0 -93
  74. data/spec/test_app_templates/Gemfile.extra +0 -5
@@ -1,43 +1,56 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe BlacklightMaps::Geometry do
6
+ describe BlacklightMaps::Geometry::BoundingBox do
7
+ let(:bbox) { described_class.from_lon_lat_string('-100 -50 100 50') }
8
+ let(:bbox_california) { described_class.from_wkt_envelope('ENVELOPE(-124, -114, 42, 32)') }
9
+ let(:bbox_dateline) { described_class.from_lon_lat_string('165 30 -172 -20') }
4
10
 
5
- describe "BlacklightMaps::Geometry::BoundingBox" do
11
+ it 'instantiates Geometry::BoundingBox' do
12
+ expect(bbox.class).to eq(described_class)
13
+ end
6
14
 
7
- let(:bbox) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-100 -50 100 50') }
8
- let(:bbox_california) { BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('-124.4096196 32.5342321 -114.131211 42.0095169') }
9
- let(:bbox_dateline) {BlacklightMaps::Geometry::BoundingBox.from_lon_lat_string('165 30 -172 -20') }
15
+ describe '#find_center' do
16
+ it 'returns center of simple bounding box' do
17
+ expect(bbox.find_center).to eq([0.0, 0.0])
18
+ end
19
+ end
10
20
 
11
- it "should instantiate Geometry::BoundingBox" do
12
- expect(bbox.class).to eq(::BlacklightMaps::Geometry::BoundingBox)
21
+ describe '#to_a' do
22
+ it 'returns the coordinates as an array' do
23
+ expect(bbox.to_a).to eq([-100, -50, 100, 50])
24
+ end
13
25
  end
14
26
 
15
- it "should return center of simple bounding box" do
16
- expect(bbox.find_center).to eq([0.0, 0.0])
27
+ describe '#geojson_geometry_array' do
28
+ it 'returns the coordinates as a multi dimensional array' do
29
+ expect(bbox.geojson_geometry_array).to eq(
30
+ [[[-100, -50], [100, -50], [100, 50], [-100, 50], [-100, -50]]]
31
+ )
32
+ end
17
33
  end
18
34
 
19
- it "should return center of California bounding box" do
20
- expect(bbox_california.find_center).to eq([-119.2704153, 37.271874499999996])
35
+ it 'returns center of California bounding box' do
36
+ expect(bbox_california.find_center).to eq([-119.0, 37.0])
21
37
  end
22
38
 
23
- it "should return correct dateline bounding box" do
39
+ it 'returns correct dateline bounding box' do
24
40
  expect(bbox_dateline.find_center).to eq([-183.5, 5])
25
41
  end
26
42
  end
27
43
 
28
- describe "BlacklightMaps::Geometry::Point" do
44
+ describe BlacklightMaps::Geometry::Point do
45
+ let(:point) { described_class.from_lat_lon_string('20,120') }
46
+ let(:unparseable_point) { described_class.from_lat_lon_string('35.86166,-184.195397') }
29
47
 
30
- let(:point) { BlacklightMaps::Geometry::Point.from_lat_lon_string('20,120') }
31
- let(:unparseable_point) { BlacklightMaps::Geometry::Point.from_lat_lon_string('35.86166,-184.195397') }
32
-
33
- it "should instantiate Geometry::Point" do
34
- expect(point.class).to eq(::BlacklightMaps::Geometry::Point)
48
+ it 'instantiates Geometry::Point' do
49
+ expect(point.class).to eq(described_class)
35
50
  end
36
51
 
37
- it "should return a Solr-parseable coordinate if @long is > 180 or < -180" do
38
- expect(unparseable_point.normalize_for_search).to eq([175.804603,35.86166])
52
+ it 'returns a Solr-parseable coordinate if @long is > 180 or < -180' do
53
+ expect(unparseable_point.normalize_for_search).to eq([175.804603, 35.86166])
39
54
  end
40
-
41
55
  end
42
-
43
56
  end
@@ -1,46 +1,42 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe BlacklightMaps::MapsSearchBuilderBehavior do
4
-
5
6
  let(:blacklight_config) { CatalogController.blacklight_config.deep_copy }
6
- let(:user_params) { Hash.new }
7
+ let(:user_params) { {} }
7
8
  let(:context) { CatalogController.new }
8
-
9
- before { allow(context).to receive(:blacklight_config).and_return(blacklight_config) }
10
-
11
9
  let(:search_builder_class) do
12
10
  Class.new(Blacklight::SearchBuilder) do
13
11
  include Blacklight::Solr::SearchBuilderBehavior
14
12
  include BlacklightMaps::MapsSearchBuilderBehavior
15
13
  end
16
14
  end
17
-
18
15
  let(:search_builder) { search_builder_class.new(context) }
19
16
 
20
- describe 'add_spatial_search_to_solr' do
17
+ before { allow(context).to receive(:blacklight_config).and_return(blacklight_config) }
21
18
 
19
+ describe 'add_spatial_search_to_solr' do
22
20
  describe 'coordinate search' do
23
-
24
- subject { search_builder.with({coordinates: '35.86166,104.195397', spatial_search_type: 'point'}) }
25
-
26
- it 'should return a coordinate point spatial search if coordinates are given' do
27
- expect(subject[:fq].first).to include('geofilt')
28
- expect(subject[:pt]).to eq('35.86166,104.195397')
21
+ let(:coordinate_search) do
22
+ search_builder.with(coordinates: '35.86166,104.195397', spatial_search_type: 'point')
29
23
  end
30
24
 
25
+ it 'returns a coordinate point spatial search if coordinates are given' do
26
+ expect(coordinate_search[:fq].first).to include('geofilt')
27
+ expect(coordinate_search[:pt]).to eq('35.86166,104.195397')
28
+ end
31
29
  end
32
30
 
33
31
  describe 'bbox search' do
34
-
35
- subject { search_builder.with({coordinates: '[6.7535159,68.162386 TO 35.5044752,97.395555]',
36
- spatial_search_type: 'bbox'}) }
37
-
38
- it 'should return a bbox spatial search if a bbox is given' do
39
- expect(subject[:fq].first).to include(blacklight_config.view.maps.coordinates_field)
32
+ let(:bbox_search) do
33
+ search_builder.with(coordinates: '[6.7535159,68.162386 TO 35.5044752,97.395555]',
34
+ spatial_search_type: 'bbox')
40
35
  end
41
36
 
37
+ it 'returns a bbox spatial search if a bbox is given' do
38
+ expect(bbox_search[:fq].first).to include(blacklight_config.view.maps.coordinates_field)
39
+ end
42
40
  end
43
-
44
41
  end
45
-
46
42
  end
@@ -1,95 +1,68 @@
1
- require 'spec_helper'
2
-
3
- describe BlacklightMaps::RenderConstraintsOverride do
1
+ # frozen_string_literal: true
4
2
 
5
- class BlacklightMapsControllerTestClass < CatalogController
6
- attr_accessor :params
7
- end
3
+ require 'spec_helper'
8
4
 
9
- before(:each) do
10
- @fake_controller = BlacklightMapsControllerTestClass.new
11
- @fake_controller.extend(BlacklightMaps::RenderConstraintsOverride)
12
- @fake_controller.params = { coordinates: "35.86166,104.195397", spatial_search_type: "point" }
5
+ describe BlacklightMaps::RenderConstraintsOverride, type: :helper do
6
+ let(:mock_controller) { CatalogController.new }
7
+ let(:blacklight_config) { Blacklight::Configuration.new }
8
+ let(:test_params) { { coordinates: '35.86166,104.195397', spatial_search_type: 'point' } }
9
+ let(:test_search_state) do
10
+ Blacklight::SearchState.new(test_params, blacklight_config, mock_controller)
13
11
  end
14
12
 
15
- describe "testing for spatial parameters" do
16
-
17
- describe "has_spatial_parameters?" do
18
-
19
- it "should be true if coordinate params are present" do
20
- expect(@fake_controller.has_spatial_parameters?).to be true
21
- end
13
+ describe 'has_search_parameters?' do
14
+ before { mock_controller.params = test_params }
22
15
 
16
+ it 'returns true if coordinate params are present' do
17
+ expect(mock_controller.has_search_parameters?).to be_truthy
23
18
  end
19
+ end
24
20
 
25
- describe "has_search_parameters?" do
26
-
27
- it "should be true if coordinate params are present" do
28
- expect(@fake_controller.has_search_parameters?).to be true
29
- end
30
-
21
+ describe 'has_spatial_parameters?' do
22
+ it 'returns true if coordinate params are present' do
23
+ expect(helper.has_spatial_parameters?(test_search_state)).to be_truthy
31
24
  end
32
-
33
25
  end
34
26
 
35
- describe "render spatial constraints" do
36
-
37
- before do
38
- @test_params = @fake_controller.params
27
+ describe 'query_has_constraints?' do
28
+ it 'returns true if there are coordinate params' do
29
+ expect(helper.query_has_constraints?(test_search_state)).to be_truthy
39
30
  end
31
+ end
40
32
 
41
- describe "query_has_constraints?" do
42
-
43
- it "should be true if there are coordinate params" do
44
- expect(@fake_controller.query_has_constraints?).to be true
45
- end
33
+ describe 'spatial_constraint_label' do
34
+ let(:bbox_params) { { spatial_search_type: 'bbox' } }
46
35
 
36
+ it 'returns the point label' do
37
+ expect(helper.spatial_constraint_label(test_search_state)).to eq(I18n.t('blacklight.search.filters.coordinates.point'))
47
38
  end
48
39
 
49
- describe "spatial_constraint_label" do
40
+ it 'returns the bbox label' do
41
+ expect(helper.spatial_constraint_label(bbox_params)).to eq(I18n.t('blacklight.search.filters.coordinates.bbox'))
42
+ end
43
+ end
50
44
 
51
- it "should return the point label" do
52
- expect(@fake_controller.spatial_constraint_label(@test_params)).to eq(I18n.t('blacklight.search.filters.coordinates.point'))
45
+ describe 'render spatial constraints' do
46
+ describe 'render_spatial_query' do
47
+ before do
48
+ allow(helper).to receive_messages(search_action_path: search_catalog_path)
53
49
  end
54
50
 
55
- it "should return the bbox label" do
56
- @test_params = { spatial_search_type: "bbox" }
57
- expect(@fake_controller.spatial_constraint_label(@test_params)).to eq(I18n.t('blacklight.search.filters.coordinates.bbox'))
51
+ it 'renders the coordinates' do
52
+ expect(helper.render_spatial_query(test_search_state)).to have_content(test_params[:coordinates])
58
53
  end
59
54
 
60
- end
61
-
62
- describe "render_spatial_query" do
63
-
64
- before :each do
65
- # have to create a request or call to 'url _for' returns an error
66
- @fake_controller.request = ActionDispatch::Request.new(params:{controller: 'catalog', action: 'index'})
67
- @fake_controller.request.path_parameters[:controller] = 'catalog'
55
+ it 'removes the spatial params' do
56
+ expect(helper.remove_spatial_params(test_search_state)).not_to have_content('spatial_search_type')
68
57
  end
69
-
70
- # TODO: can't get these specs to pass, getting error:
71
- # NoMethodError: undefined method `render_constraint_element'
72
-
73
- it "should render the coordinates" #do
74
- #expect(@fake_controller.render_spatial_query(@test_params)).to have_content(@fake_controller.params[:coordinates])
75
- #end
76
-
77
- it "should remove spatial params in the 'remove' link" #do
78
- #expect(@fake_controller.render_spatial_query(@test_params)).to_not have_content("spatial_search_type")
79
- #end
80
-
81
58
  end
82
59
 
83
- describe "render_search_to_s_coord" do
84
-
85
- it "should return render_search_to_s_element when coordinates are present" do
86
- expect(@fake_controller).to receive(:render_search_to_s_element)
87
- expect(@fake_controller).to receive(:render_filter_value)
88
- @fake_controller.render_search_to_s_coord(@test_params)
60
+ describe 'render_search_to_s_coord' do
61
+ it 'returns render_search_to_s_element when coordinates are present' do
62
+ expect(helper).to receive(:render_search_to_s_element)
63
+ expect(helper).to receive(:render_filter_value)
64
+ helper.render_search_to_s_coord(test_params)
89
65
  end
90
-
91
66
  end
92
-
93
67
  end
94
-
95
- end
68
+ end
@@ -1,36 +1,34 @@
1
- ENV["RAILS_ENV"] ||= 'test'
1
+ # frozen_string_literal: true
2
2
 
3
- require 'engine_cart'
3
+ # testing environent:
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+
6
+ require 'simplecov'
4
7
  require 'coveralls'
5
8
  Coveralls.wear!('rails')
6
- EngineCart.load_application!
7
-
8
- require 'capybara/poltergeist'
9
- Capybara.javascript_driver = :poltergeist
10
9
 
11
- Capybara.register_driver :poltergeist do |app|
12
- options = {}
13
-
14
- options[:timeout] = 120 if RUBY_PLATFORM == "java"
15
-
16
- Capybara::Poltergeist::Driver.new(app, options)
10
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
17
13
  end
18
14
 
19
- if ENV["COVERAGE"] or ENV["CI"]
20
- require 'simplecov'
21
-
22
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
23
- SimpleCov.start do
24
- add_filter "/spec/"
25
- end
26
- end
15
+ # engine_cart:
16
+ require 'bundler/setup'
17
+ require 'engine_cart'
18
+ EngineCart.load_application!
27
19
 
28
20
  require 'blacklight/maps'
29
21
 
30
22
  require 'rspec/rails'
31
23
  require 'capybara/rspec'
32
-
24
+ require 'selenium-webdriver'
25
+ require 'webdrivers'
33
26
 
34
27
  RSpec.configure do |config|
35
28
  config.infer_spec_type_from_file_location!
29
+ config.fixture_path = "#{Blacklight::Maps.root}/spec/fixtures"
30
+
31
+ config.before(:each, type: :system, js: true) do
32
+ driven_by :selenium, using: :headless_chrome, screen_size: [1024, 768]
33
+ end
36
34
  end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'catalog#index map view', js: true do
6
+ before do
7
+ CatalogController.blacklight_config = Blacklight::Configuration.new
8
+ CatalogController.configure_blacklight do |config|
9
+ # use geojson facet for blacklight-maps catalog#index map view specs
10
+ config.add_facet_field 'geojson_ssim', limit: -2, label: 'GeoJSON', show: false
11
+ config.add_facet_fields_to_solr_request!
12
+ end
13
+ visit search_catalog_path q: 'korea', view: 'maps'
14
+ end
15
+
16
+ it 'displays map elements' do
17
+ expect(page).to have_selector('#documents.map')
18
+ expect(page).to have_selector('#blacklight-index-map')
19
+ end
20
+
21
+ it 'displays tile layer attribution' do
22
+ expect(find('div.leaflet-control-container')).to have_content('OpenStreetMap contributors, CC-BY-SA')
23
+ end
24
+
25
+ describe '#sortAndPerPage' do
26
+ it 'shows the mapped item count' do
27
+ expect(page).to have_selector('.mapped-count .badge', text: '4')
28
+ end
29
+
30
+ it 'shows the mapped item caveat' do
31
+ expect(page).to have_selector('.mapped-caveat')
32
+ end
33
+
34
+ # TODO: placeholder spec: #sortAndPerPage > .view-type > .view-type-group
35
+ # shows active map icon. however, this spec doesn't work because
36
+ # Blacklight::ConfigurationHelperBehavior#has_alternative_views? returns false,
37
+ # so catalog/_view_type_group partial renders no content, can't figure out why
38
+ it 'shows the map view icon' do
39
+ pending("expect(page).to have_selector('.view-type-maps.active')")
40
+ fail
41
+ end
42
+ end
43
+
44
+ describe 'data attributes' do
45
+ let(:maxzoom) { CatalogController.blacklight_config.view.maps.maxzoom }
46
+ let(:tileurl) { CatalogController.blacklight_config.view.maps.tileurl }
47
+
48
+ it 'has maxzoom value from config' do
49
+ expect(page).to have_selector("#blacklight-index-map[data-maxzoom='#{maxzoom}']")
50
+ end
51
+
52
+ it 'has tileurl value from config' do
53
+ expect(page).to have_selector("#blacklight-index-map[data-tileurl='#{tileurl}']")
54
+ end
55
+ end
56
+
57
+ describe 'marker clusters' do
58
+ before do
59
+ 3.times do # zoom out to create cluster
60
+ find('a.leaflet-control-zoom-out').click
61
+ sleep(1) # give Leaflet time to combine clusters or spec can fail
62
+ end
63
+ end
64
+
65
+ it 'has one marker cluster' do
66
+ expect(page).to have_selector('div.marker-cluster', count: 1)
67
+ end
68
+
69
+ it 'shows the result count' do
70
+ expect(find('div.marker-cluster')).to have_content(4)
71
+ end
72
+
73
+ describe 'click marker cluster' do
74
+ before { find('div.marker-cluster').click }
75
+
76
+ it 'splits into two marker clusters' do
77
+ expect(page).to have_selector('div.marker-cluster', count: 2)
78
+ end
79
+ end
80
+ end
81
+
82
+ describe 'marker popups' do
83
+ before do
84
+ find('.marker-cluster', text: '1', match: :first).click
85
+ end
86
+
87
+ it 'shows a popup with correct content' do
88
+ expect(page).to have_selector('div.leaflet-popup-content-wrapper')
89
+ expect(page).to have_css('.geo_popup_heading', text: 'Seoul (Korea)')
90
+ end
91
+
92
+ describe 'click search link' do
93
+ before { find('div.leaflet-popup-content a').click }
94
+
95
+ it 'runs a new search' do
96
+ expect(page).to have_selector('.constraint-value .filter-value', text: 'Seoul (Korea)')
97
+ end
98
+
99
+ it 'uses the default view type' do
100
+ expect(current_url).to include('view=list')
101
+ end
102
+ end
103
+ end
104
+
105
+ describe 'map search control' do
106
+ it 'has a search control' do
107
+ expect(page).to have_selector('.leaflet-control .search-control')
108
+ end
109
+
110
+ describe 'search control hover' do
111
+ before { find('.search-control').hover }
112
+
113
+ it 'adds a border to the map' do
114
+ expect(page).to have_selector('.leaflet-overlay-pane path')
115
+ end
116
+ end
117
+
118
+ describe 'search control click' do
119
+ before { find('.search-control').click }
120
+
121
+ it 'runs a new search' do
122
+ expect(page).to have_selector('.constraint.coordinates')
123
+ expect(current_url).to include('view=list')
124
+ end
125
+ end
126
+ end
127
+ end