diff --git a/app/components/embed/download/file_list_item_component.html.erb b/app/components/embed/download/file_list_item_component.html.erb index 16a88cabb..5fc9243b5 100644 --- a/app/components/embed/download/file_list_item_component.html.erb +++ b/app/components/embed/download/file_list_item_component.html.erb @@ -1,6 +1,6 @@
  • - Download <%= file.label %> + Download <%= file.label_or_filename %> <%= render 'embed/restrictions_text_for_file', file: file %> <%= file_size %> diff --git a/app/components/embed/media_wrapper_component.rb b/app/components/embed/media_wrapper_component.rb index cfc7249da..e08adf4f2 100644 --- a/app/components/embed/media_wrapper_component.rb +++ b/app/components/embed/media_wrapper_component.rb @@ -19,7 +19,7 @@ def call # rubocop:disable Metrics/MethodLength action: 'thumbnail-clicked@window->media-wrapper#toggleVisibility', stanford_only: @file.stanford_only?, location_restricted: @file.location_restricted?, - file_label: @file.label, + file_label: @file.label_or_filename, slider_object: @file_index, thumbnail_url: @thumbnail.presence, default_icon: @type == 'audio' ? 'sul-i-file-music-1' : 'sul-i-file-video-3', diff --git a/app/models/embed/purl/resource_file.rb b/app/models/embed/purl/resource_file.rb index f6ae96fc0..39718ea34 100644 --- a/app/models/embed/purl/resource_file.rb +++ b/app/models/embed/purl/resource_file.rb @@ -38,6 +38,10 @@ def stacks_url "#{Settings.stacks_url}/file/druid:#{@druid}" end + def label_or_filename + label.presence || filename + end + def hierarchical_title title.split('/').last end diff --git a/app/views/embed/body/_resource_file.html.erb b/app/views/embed/body/_resource_file.html.erb index 17da5950c..4e562b4e1 100644 --- a/app/views/embed/body/_resource_file.html.erb +++ b/app/views/embed/body/_resource_file.html.erb @@ -23,7 +23,7 @@ <% end %>
    - <%= file.label %> + <%= file.label_or_filename %>
    diff --git a/spec/components/embed/media_wrapper_component_spec.rb b/spec/components/embed/media_wrapper_component_spec.rb index 5bed688aa..b8f1c86c3 100644 --- a/spec/components/embed/media_wrapper_component_spec.rb +++ b/spec/components/embed/media_wrapper_component_spec.rb @@ -20,7 +20,7 @@ end describe 'data-default-icon attribute' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: false, label: 'ignored', duration: nil) } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: false, label_or_filename: 'ignored', duration: nil) } context 'with audio' do it 'renders the page' do @@ -39,7 +39,7 @@ describe 'data-stanford-only attribute' do context 'with Stanford only files' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: true, location_restricted?: false, label: 'ignored', duration: nil) } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: true, location_restricted?: false, label_or_filename: 'ignored', duration: nil) } it 'renders the page' do expect(page).to have_css('[data-stanford-only="true"]') @@ -47,7 +47,7 @@ end context 'with public files' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: false, label: 'ignored', duration: nil) } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: false, label_or_filename: 'ignored', duration: nil) } it 'renders the page' do expect(page).to have_css('[data-stanford-only="false"]') @@ -57,7 +57,7 @@ describe 'duration' do context 'when the resource file has duration' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: false, label: 'ignored', duration: '1:02') } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: false, label_or_filename: 'ignored', duration: '1:02') } it 'renders the page' do expect(page).to have_css('[data-duration="1:02"]') @@ -65,7 +65,7 @@ end context 'when the resource file is missing duration' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: true, location_restricted?: false, label: 'ignored', duration: nil) } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: true, location_restricted?: false, label_or_filename: 'ignored', duration: nil) } it 'renders the page' do expect(page).not_to have_css('[data-duration]') @@ -75,7 +75,7 @@ describe 'data-location-restricted attribute' do context 'when location restricted' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: true, label: 'ignored', duration: nil) } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: false, location_restricted?: true, label_or_filename: 'ignored', duration: nil) } it 'renders the page' do expect(page).to have_css('[data-location-restricted="true"]') @@ -83,7 +83,7 @@ end context 'when not location restricted' do - let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: true, location_restricted?: false, label: 'ignored', duration: nil) } + let(:file) { instance_double(Embed::Purl::ResourceFile, stanford_only?: true, location_restricted?: false, label_or_filename: 'ignored', duration: nil) } it 'renders the page' do expect(page).to have_css('[data-location-restricted="false"]') diff --git a/spec/models/embed/purl/resource_file_spec.rb b/spec/models/embed/purl/resource_file_spec.rb index 8d5c7ff07..ef67dbdbd 100644 --- a/spec/models/embed/purl/resource_file_spec.rb +++ b/spec/models/embed/purl/resource_file_spec.rb @@ -75,6 +75,22 @@ end end + describe '#label_or_filename' do + subject { resource_file.label_or_filename } + + context 'with a label' do + let(:resource_file) { described_class.new(label: 'The Resource Description') } + + it { is_expected.to eq 'The Resource Description' } + end + + context 'without a blank label' do + let(:resource_file) { described_class.new(label: '', filename: 'llama.mp3') } + + it { is_expected.to eq 'llama.mp3' } + end + end + describe 'image?' do it 'returns true if the mimetype of the file is an image' do stub_purl_xml_response_with_fixture(image_purl_xml)