From 9432e6ccba984cf8bf84a172f542212b40dc21e9 Mon Sep 17 00:00:00 2001 From: Jessie Keck Date: Tue, 30 Aug 2016 14:42:31 -0700 Subject: [PATCH] Update the height of the file viewer based on the number of resources being displayed. --- lib/embed/viewer/file.rb | 18 +++++++++++++++++- spec/features/embed_this_panel_spec.rb | 2 +- spec/lib/embed/viewer/file_spec.rb | 13 ++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/embed/viewer/file.rb b/lib/embed/viewer/file.rb index cab5f13b7..8bdc3c4dc 100644 --- a/lib/embed/viewer/file.rb +++ b/lib/embed/viewer/file.rb @@ -65,7 +65,23 @@ def file_type_icon(mimetype) end def default_body_height - 400 - (header_height + footer_height) + file_specific_body_height - (header_height + footer_height) + end + + # This is neccessary because the file viewer's height is meant to be dynamic, + # however we need to specify the exact height of the containing iframe (which + # will give us extra whitespace below the embed viewer unless we do this) + def file_specific_body_height + case @purl_object.all_resource_files.count + when 1 + 200 + when 2 + 275 + when 3 + 375 + else + 400 + end end def preview_file_toggle(file, doc, file_count) diff --git a/spec/features/embed_this_panel_spec.rb b/spec/features/embed_this_panel_spec.rb index bb015b9fa..d23fdd30a 100644 --- a/spec/features/embed_this_panel_spec.rb +++ b/spec/features/embed_this_panel_spec.rb @@ -22,7 +22,7 @@ end it 'includes height and width attributes' do page.find('[data-sul-embed-toggle="sul-embed-embed-this-panel"]', match: :first).trigger('click') - expect(page.find('.sul-embed-embed-this-panel textarea').value).to match(//) + expect(page.find('.sul-embed-embed-this-panel textarea').value).to match(//) expect(page.find('.sul-embed-embed-this-panel textarea').value).to match(//) end end diff --git a/spec/lib/embed/viewer/file_spec.rb b/spec/lib/embed/viewer/file_spec.rb index e392de08b..519ec4e3e 100644 --- a/spec/lib/embed/viewer/file_spec.rb +++ b/spec/lib/embed/viewer/file_spec.rb @@ -23,15 +23,26 @@ end describe 'body_height' do it 'defaults to 400 minus the footer and header height' do - stub_request(request) + stub_purl_response_and_request(multi_resource_multi_type_purl, request) expect(file_viewer.send(:body_height)).to eq 307 end + it 'consumer requested maxheight minus the header/footer height' do height_request = Embed::Request.new(url: 'http://purl.stanford.edu/abc123', maxheight: '500') stub_request(height_request) viewer = Embed::Viewer::File.new(height_request) expect(viewer.send(:body_height)).to eq 407 end + + it 'reduces the height based on the number of files in the object (1 file)' do + stub_purl_response_and_request(file_purl, request) + expect(file_viewer.send(:body_height)).to eq 107 + end + + it 'reduces the height based on the number of files in the object (2 files)' do + stub_purl_response_and_request(image_purl, request) + expect(file_viewer.send(:body_height)).to eq 182 + end end describe 'header tools' do it 'includes the search in the header tools' do