blacklight-maps 0.5.2 → 1.2.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 (75) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +33 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +103 -0
  5. data/.solr_wrapper.yml +8 -0
  6. data/Gemfile +38 -8
  7. data/README.md +15 -13
  8. data/Rakefile +35 -32
  9. data/app/assets/images/blacklight/maps.svg +1 -0
  10. data/app/assets/javascripts/blacklight-maps/blacklight-maps-browse.js +7 -8
  11. data/app/assets/javascripts/blacklight-maps.js +1 -4
  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/controller.rb +27 -0
  32. data/lib/blacklight/maps/engine.rb +15 -14
  33. data/lib/blacklight/maps/export.rb +114 -93
  34. data/lib/blacklight/maps/geometry.rb +30 -18
  35. data/lib/blacklight/maps/maps_search_builder.rb +4 -3
  36. data/lib/blacklight/maps/render_constraints_override.rb +63 -29
  37. data/lib/blacklight/maps/version.rb +3 -1
  38. data/lib/blacklight/maps.rb +8 -2
  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/lib/railties/blacklight_maps.rake +10 -7
  42. data/spec/controllers/catalog_controller_spec.rb +20 -10
  43. data/spec/fixtures/sample_solr_documents.yml +909 -906
  44. data/spec/helpers/blacklight_maps_helper_spec.rb +60 -108
  45. data/spec/lib/blacklight/maps/export_spec.rb +109 -143
  46. data/spec/lib/blacklight/maps/geometry_spec.rb +34 -21
  47. data/spec/lib/blacklight/maps/maps_search_builder_spec.rb +17 -21
  48. data/spec/lib/blacklight/maps/render_constraints_override_spec.rb +42 -69
  49. data/spec/spec_helper.rb +18 -21
  50. data/spec/system/index_view_spec.rb +128 -0
  51. data/spec/system/initial_view_spec.rb +28 -0
  52. data/spec/system/map_view_spec.rb +50 -0
  53. data/spec/system/show_view_maplet_spec.rb +78 -0
  54. data/spec/test_app_templates/lib/generators/test_app_generator.rb +6 -21
  55. data/vendor/assets/images/layers-2x.png +0 -0
  56. data/vendor/assets/images/layers.png +0 -0
  57. data/vendor/assets/images/marker-icon-2x.png +0 -0
  58. data/vendor/assets/images/marker-icon.png +0 -0
  59. data/vendor/assets/images/marker-shadow.png +0 -0
  60. data/vendor/assets/javascripts/leaflet.js.erb +13922 -0
  61. data/vendor/assets/javascripts/leaflet.markercluster.js +3 -0
  62. data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
  63. data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
  64. data/vendor/assets/stylesheets/leaflet.css +635 -0
  65. metadata +85 -90
  66. data/.travis.yml +0 -25
  67. data/config/jetty.yml +0 -7
  68. data/lib/blacklight/maps/controller_override.rb +0 -20
  69. data/lib/generators/blacklight_maps/templates/saved_searches_controller.rb +0 -5
  70. data/spec/features/initial_view_spec.rb +0 -21
  71. data/spec/features/maps_spec.rb +0 -202
  72. data/spec/features/show_view_maplet_spec.rb +0 -93
  73. data/spec/test_app_templates/Gemfile.extra +0 -5
  74. /data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/schema.xml +0 -0
  75. /data/{solr_conf → lib/generators/blacklight_maps/templates/solr}/conf/solrconfig.xml +0 -0
@@ -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
data/spec/spec_helper.rb CHANGED
@@ -1,36 +1,33 @@
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'
33
25
 
34
26
  RSpec.configure do |config|
35
27
  config.infer_spec_type_from_file_location!
28
+ config.fixture_paths = ["#{Blacklight::Maps.root}/spec/fixtures"]
29
+
30
+ config.before(:each, :js, type: :system) do
31
+ driven_by :selenium, using: :headless_chrome, screen_size: [1024, 768]
32
+ end
36
33
  end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'catalog#index map view', :js 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_field 'subject_geo_ssim', label: 'Region'
12
+ config.add_facet_fields_to_solr_request!
13
+ end
14
+ visit search_catalog_path q: 'korea', view: 'maps'
15
+ end
16
+
17
+ it 'displays map elements' do
18
+ expect(page).to have_selector('#documents.map')
19
+ expect(page).to have_selector('#blacklight-index-map')
20
+ end
21
+
22
+ it 'displays tile layer attribution' do
23
+ expect(find('div.leaflet-control-container')).to have_content('OpenStreetMap contributors, CC-BY-SA')
24
+ end
25
+
26
+ describe '#sortAndPerPage' do
27
+ it 'shows the mapped item count' do
28
+ expect(page).to have_selector('.mapped-count .badge', text: '4')
29
+ end
30
+
31
+ it 'shows the mapped item caveat' do
32
+ expect(page).to have_selector('.mapped-caveat')
33
+ end
34
+
35
+ # TODO: placeholder spec: #sortAndPerPage > .view-type > .view-type-group
36
+ # shows active map icon. however, this spec doesn't work because
37
+ # Blacklight::ConfigurationHelperBehavior#has_alternative_views? returns false,
38
+ # so catalog/_view_type_group partial renders no content, can't figure out why
39
+ it 'shows the map view icon' do
40
+ pending("expect(page).to have_selector('.view-type-maps.active')")
41
+ fail
42
+ end
43
+ end
44
+
45
+ describe 'data attributes' do
46
+ let(:maxzoom) { CatalogController.blacklight_config.view.maps.maxzoom }
47
+ let(:tileurl) { CatalogController.blacklight_config.view.maps.tileurl }
48
+
49
+ it 'has maxzoom value from config' do
50
+ expect(page).to have_selector("#blacklight-index-map[data-maxzoom='#{maxzoom}']")
51
+ end
52
+
53
+ it 'has tileurl value from config' do
54
+ expect(page).to have_selector("#blacklight-index-map[data-tileurl='#{tileurl}']")
55
+ end
56
+ end
57
+
58
+ describe 'marker clusters' do
59
+ before do
60
+ 3.times do # zoom out to create cluster
61
+ find('a.leaflet-control-zoom-out').click
62
+ sleep(1) # give Leaflet time to combine clusters or spec can fail
63
+ end
64
+ end
65
+
66
+ it 'has one marker cluster' do
67
+ expect(page).to have_selector('div.marker-cluster', count: 1)
68
+ end
69
+
70
+ it 'shows the result count' do
71
+ expect(find('div.marker-cluster')).to have_content(4)
72
+ end
73
+
74
+ describe 'click marker cluster' do
75
+ before { find('div.marker-cluster').click }
76
+
77
+ it 'splits into two marker clusters' do
78
+ expect(page).to have_selector('div.marker-cluster', count: 2)
79
+ end
80
+ end
81
+ end
82
+
83
+ describe 'marker popups' do
84
+ before do
85
+ find('.marker-cluster', text: '1', match: :first).click
86
+ end
87
+
88
+ it 'shows a popup with correct content' do
89
+ expect(page).to have_selector('div.leaflet-popup-content-wrapper')
90
+ expect(page).to have_css('.geo_popup_heading', text: 'Seoul (Korea)')
91
+ end
92
+
93
+ describe 'click search link' do
94
+ before { find('div.leaflet-popup-content a').click }
95
+
96
+ it 'runs a new search' do
97
+ expect(page).to have_selector('.constraint-value .filter-value', text: 'Seoul (Korea)')
98
+ end
99
+
100
+ it 'uses the default view type' do
101
+ expect(current_url).to include('view=list')
102
+ end
103
+ end
104
+ end
105
+
106
+ describe 'map search control' do
107
+ it 'has a search control' do
108
+ expect(page).to have_selector('.leaflet-control .search-control')
109
+ end
110
+
111
+ describe 'search control hover' do
112
+ before { find('.search-control').hover }
113
+
114
+ it 'adds a border to the map' do
115
+ expect(page).to have_selector('.leaflet-overlay-pane path')
116
+ end
117
+ end
118
+
119
+ describe 'search control click' do
120
+ before { find('.search-control').click }
121
+
122
+ it 'runs a new search' do
123
+ expect(page).to have_selector('.constraint.coordinates')
124
+ expect(current_url).to include('view=list')
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Initial map bounds view parameter', :js do
6
+ before(:all) do
7
+ CatalogController.configure_blacklight do |config|
8
+ config.view.maps.facet_mode = 'coordinates'
9
+ config.view.maps.coordinates_facet_field = 'coordinates_ssim'
10
+ config.add_facet_field 'coordinates_ssim', limit: -2, label: 'Coordinates', show: false
11
+ end
12
+ end
13
+
14
+ it 'defaults to zoom area of markers' do
15
+ visit search_catalog_path f: { format: ['Book'] }, view: 'maps'
16
+ expect(page).to have_selector('.leaflet-marker-icon.marker-cluster', count: 9)
17
+ end
18
+
19
+ describe 'with provided initialview' do
20
+ let(:map_tag) { '<div id="blacklight-index-map" data-initialview="[[37.65, -122.56],[37.89, -122.27]]" data-maxzoom="18" data-tileurl="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" data-mapattribution="Map data &amp;copy; &lt;a href=&quot;http://openstreetmap.org&quot;&gt;OpenStreetMap&lt;/a&gt; contributors, &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/2.0/&quot;&gt;CC-BY-SA&lt;/a&gt;" data-searchcontrol="true" data-catalogpath="/catalog" data-placenamefield="placename_field" data-clustercount="hits" />'.html_safe }
21
+
22
+ it 'sets map to correct bounds when initialview provided' do
23
+ allow_any_instance_of(Blacklight::BlacklightMapsHelperBehavior).to receive(:blacklight_map_tag).and_return(map_tag)
24
+ visit search_catalog_path f: { format: ['Book'] }, view: 'maps'
25
+ expect(page).not_to have_selector('.leaflet-marker-icon.marker-cluster')
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'catalog#map view', :js do
6
+ before do
7
+ CatalogController.blacklight_config = Blacklight::Configuration.new
8
+ CatalogController.configure_blacklight do |config|
9
+ # use coordinates_facet facet for blacklight-maps catalog#map view specs
10
+ config.view.maps.facet_mode = 'coordinates'
11
+ config.view.maps.coordinates_facet_field = 'coordinates_ssim'
12
+ config.add_facet_field 'coordinates_ssim', limit: -2, label: 'Coordinates', show: false
13
+ config.add_facet_fields_to_solr_request!
14
+ end
15
+ visit map_path
16
+ end
17
+
18
+ it 'displays map elements' do
19
+ expect(page).to have_selector('#documents.map')
20
+ expect(page).to have_selector('#blacklight-index-map')
21
+ end
22
+
23
+ it 'displays some markers' do
24
+ expect(page).to have_selector('div.marker-cluster')
25
+ end
26
+
27
+ describe 'marker popups' do
28
+ before do
29
+ 2.times do # zoom out to create cluster
30
+ find('a.leaflet-control-zoom-in').click
31
+ sleep(1) # give Leaflet time to split clusters or spec can fail
32
+ end
33
+ find('.marker-cluster:first-child').click
34
+ end
35
+
36
+ it 'shows a popup with correct content' do
37
+ expect(page).to have_selector('.leaflet-popup-content-wrapper')
38
+ expect(page).to have_css('.geo_popup_heading', text: '[35.86166, 104.195397]')
39
+ end
40
+
41
+ describe 'click search link' do
42
+ before { find('div.leaflet-popup-content a').click }
43
+
44
+ it 'runs a new search' do
45
+ expect(page).to have_selector('.constraint-value .filter-value', text: '35.86166,104.195397')
46
+ expect(current_url).to include('view=list')
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'catalog#show view', :js do
6
+ before(:all) do
7
+ CatalogController.blacklight_config = Blacklight::Configuration.new
8
+ CatalogController.configure_blacklight do |config|
9
+ config.show.partials << :show_maplet # add maplet to show view partials
10
+ end
11
+ end
12
+
13
+ describe 'item with point feature' do
14
+ before { visit solr_document_path('00314247') }
15
+
16
+ it 'displays the maplet' do
17
+ expect(page).to have_selector('#blacklight-show-map-container')
18
+ end
19
+
20
+ it 'has a single marker icon' do
21
+ expect(page).to have_selector('.leaflet-marker-icon', count: 1)
22
+ end
23
+
24
+ describe 'click marker icon' do
25
+ before { find('.leaflet-marker-icon').click }
26
+
27
+ it 'shows a popup with correct content' do
28
+ expect(page).to have_selector('div.leaflet-popup-content-wrapper')
29
+ expect(page).to have_content('Japan')
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'item with point and bbox system' do
35
+ before { visit solr_document_path('2008308175') }
36
+
37
+ it 'shows the correct mapped item count' do
38
+ expect(page).to have_selector('.mapped-count .badge', text: '2')
39
+ end
40
+
41
+ it 'shows a bounding box and a point marker' do
42
+ expect(page).to have_selector('.leaflet-overlay-pane path.leaflet-interactive')
43
+ expect(page).to have_selector('.leaflet-marker-icon')
44
+ end
45
+
46
+ describe 'click bbox path' do
47
+ before do
48
+ 0.upto(4) { find('a.leaflet-control-zoom-in').click } # so bbox not covered by point
49
+ find('.leaflet-overlay-pane svg').click
50
+ end
51
+
52
+ it 'shows a popup with correct content' do
53
+ expect(page).to have_selector('div.leaflet-popup-content-wrapper')
54
+ expect(page).to have_content('[68.162386, 6.7535159, 97.395555, 35.5044752]')
55
+ end
56
+ end
57
+ end
58
+
59
+ describe 'item with bbox feature' do
60
+ before do
61
+ CatalogController.configure_blacklight do |config|
62
+ # set zoom config so we can test whether setMapBounds() is correct
63
+ config.view.maps.maxzoom = 8
64
+ config.view.maps.show_initial_zoom = 10
65
+ end
66
+ visit solr_document_path('2009373514')
67
+ end
68
+
69
+ it 'displays a bounding box' do
70
+ expect(page).to have_selector('.leaflet-overlay-pane path.leaflet-interactive')
71
+ end
72
+
73
+ it 'zooms to the correct map bounds' do
74
+ # if setMapBounds() zoom >= maxzoom, zoom-in control will be disabled
75
+ expect(page).to have_selector('a.leaflet-control-zoom-in.leaflet-disabled')
76
+ end
77
+ end
78
+ end
@@ -1,32 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
 
3
5
  class TestAppGenerator < Rails::Generators::Base
4
- source_root "../../spec/test_app_templates"
5
-
6
- def remove_index
7
- remove_file "public/index.html"
8
- end
6
+ source_root './spec/test_app_templates'
9
7
 
10
- def run_blacklight_generator
11
- say_status("warning", "GENERATING BL", :yellow)
12
-
13
- Bundler.with_clean_env do
14
- run "bundle install"
15
- end
16
-
17
- generate 'blacklight:install'
18
- end
19
-
20
- def run_gallery_install
8
+ def install_engine
21
9
  generate 'blacklight_maps:install'
22
10
  end
23
11
 
24
12
  def configure_test_assets
25
- insert_into_file 'config/environments/test.rb', :after => 'Rails.application.configure do' do
26
- %q{
27
- config.assets.digest = false
28
- }
13
+ insert_into_file 'config/environments/test.rb', after: 'Rails.application.configure do' do
14
+ "\nconfig.assets.digest = false"
29
15
  end
30
16
  end
31
-
32
17
  end
Binary file
Binary file