Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Merge c847ef0 into 5f8d6a0
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Mar 12, 2019
2 parents 5f8d6a0 + c847ef0 commit fd61cbf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/cho/work/submission_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ def title_field_method
end

def thumbnail_path
thumbnail = resource.representative_file_set.thumbnail
thumbnail = resource.representative_file_set.thumbnail || select_thumbnail
return if thumbnail.nil?

thumbnail.path.to_s
end

def select_thumbnail
possible_thumbnails = resource.file_sets.select(&:thumbnail)
return if possible_thumbnails.empty?
possible_thumbnails.first.thumbnail
end
end
end
53 changes: 53 additions & 0 deletions spec/cho/work/submissions/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,57 @@
expect(page).to have_xpath("//img[@alt='Work1 thumb']")
end
end

context 'when attaching a zip file with an alternate thumbnail' do
let!(:archival_collection) { create(:archival_collection, title: 'Collection with alternate thumbnail') }

let(:bag) do
ImportFactory::Bag.create(
batch_id: 'batch1_2019-03-12',
data: {
work1: [
'work1_00001_preservation.tif',
'work1_00001_service.jp2',
'work1_00001_text.txt',
'work1_00001_thumb.png',
'work1_access.pdf'
]
}
)
end

let(:zip_file) { ImportFactory::Zip.create(bag) }

it 'creates a new work object with file sets, files, and a thumbnail from the zip' do
visit(root_path)
click_link('Create Work')
click_link('Generic')
expect(page).to have_content('New Generic Work')
fill_in('work_submission[title]', with: 'Work and file sets with an alternate thumbnail')
fill_in('work_submission[member_of_collection_ids]', with: archival_collection.id)
attach_file('File Selection', zip_file)
click_button('Create Work')
expect(page).to have_content('Work and file sets with an alternate thumbnail')
expect(page).to have_content('Generic')
expect(page).to have_xpath("//img[@src='/files/work1_00001_thumb.png']")
expect(page).to have_xpath("//img[@alt='Work1 00001 thumb']")
expect(page).to have_link('Edit')
expect(page).to have_selector('h2', text: 'Files')
expect(page).to have_link('work1_00001_preservation.tif')
expect(page).to have_link('work1_access.pdf')

# Check thumbnail display on the preservation file set
click_link('work1_00001_preservation.tif')
expect(page).to have_selector('h1', text: 'work1_00001_preservation.tif')
expect(page).to have_xpath("//img[@src='/files/work1_00001_thumb.png']")
expect(page).to have_xpath("//img[@alt='Work1 00001 thumb']")

# Thumbnail does not appear on the representative file set
click_link('Work and file sets with an alternate thumbnail')
click_link('work1_access.pdf')
expect(page).to have_selector('h1', text: 'work1_access.pdf')
expect(page).not_to have_xpath("//img[@src='/files/work1_00001_thumb.png']")
expect(page).not_to have_xpath("//img[@alt='Work1 00001 thumb']")
end
end
end

0 comments on commit fd61cbf

Please sign in to comment.