Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add geojson files to be identified as an index map #2119

Merged
merged 1 commit into from Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/viewers/embed/viewer/geo.rb
Expand Up @@ -33,7 +33,7 @@ def self.show_download?
end

def index_map
purl_object.contents.map(&:files).flatten.find { |file| file.title == 'index_map.json' }
purl_object.contents.map(&:files).flatten.find { |file| index_map_files.include? file.title }
end

def index_map?
Expand All @@ -57,6 +57,10 @@ def external_url_text

private

def index_map_files
%w[index_map.geojson index_map.json]
end

def default_height
493
end
Expand Down
42 changes: 30 additions & 12 deletions spec/features/geo_viewer_spec.rb
Expand Up @@ -87,7 +87,7 @@
build(:resource, :file, files: [
build(:resource_file, filename: 'data.zip'),
build(:resource_file, filename: 'data_EPSG_4326.zip'),
build(:resource_file, druid: 'ts545zc6250', filename: 'index_map.json')
build(:resource_file, druid: 'ts545zc6250', filename:)
]),
build(:resource, :image)
])
Expand All @@ -97,17 +97,35 @@
visit_iframe_response 'ts545zc6250'
end

describe 'loads viewer' do
it 'shows the geojson' do
# This is a hack, but there is no other way (that we know of) to
# find this svg element on the page.
# We also need to explicitly wait for the JS to run.
expect(page).to have_css('.sul-embed-geo', count: 1, visible: :visible)
expect(page).to have_css '[data-index-map="https://stacks.stanford.edu/file/druid:ts545zc6250/index_map.json"]'
# only count paths within .leaflet-overlay-pane for testing
# (page.body contains SVG logos we don't care to count)
find '.leaflet-overlay-pane'
expect(Nokogiri::HTML.parse(page.body).search('.leaflet-overlay-pane').css('path').length).to eq 480
context 'when index_map.json' do
let(:filename) { 'index_map.json' }

describe 'loads viewer' do
it 'shows the geojson' do
# This is a hack, but there is no other way (that we know of) to
# find this svg element on the page.
# We also need to explicitly wait for the JS to run.
expect(page).to have_css('.sul-embed-geo', count: 1, visible: :visible)
expect(page).to have_css "[data-index-map=\"https://stacks.stanford.edu/file/druid:ts545zc6250/#{filename}\"]"
# only count paths within .leaflet-overlay-pane for testing
# (page.body contains SVG logos we don't care to count)
find '.leaflet-overlay-pane'
expect(Nokogiri::HTML.parse(page.body).search('.leaflet-overlay-pane').css('path').length).to eq 480
end
end
end

context 'when index_map.geojson' do
let(:filename) { 'index_map.geojson' }

describe 'loads viewer' do
it 'lists the geojson' do
# This is a hack, but there is no other way (that we know of) to
# find this svg element on the page.
# We also need to explicitly wait for the JS to run.
expect(page).to have_css('.sul-embed-geo', count: 1, visible: :visible)
expect(page).to have_css "[data-index-map=\"https://stacks.stanford.edu/file/druid:ts545zc6250/#{filename}\"]"
end
end
end
end
Expand Down