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

Use factories for component specs #1825

Merged
merged 1 commit into from
Nov 27, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions spec/components/embed/download/geo_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
let(:viewer) { Embed::Viewer::Geo.new(request) }
let(:response) { geo_purl_public }

let(:purl) { build(:purl, contents:) }
let(:contents) { [build(:resource, :file)] }

before do
stub_purl_xml_response_with_fixture(response)
allow(Embed::Purl).to receive(:find).and_return(purl)
render_inline(described_class.new(viewer:))
end

context 'when hide_download' do
let(:viewer) do
Embed::Viewer::Geo.new(
Embed::Request.new(
url: 'http://purl.stanford.edu/abc123', hide_download: 'true'
url: 'http://purl.stanford.edu/bc123df4567', hide_download: 'true'
)
)
end
Expand All @@ -28,21 +31,26 @@
end
end

it 'generates a file list when file has resources' do
expect(page).to have_css 'li', visible: :all, count: 3
expect(page).to have_link href: 'https://stacks.stanford.edu/file/druid:abc123/data.zip?download=true', visible: :all
context 'when the file has multiple resources' do
let(:contents) { [build(:resource, :file, files:), build(:resource, :file, files: [build(:resource_file)])] }
let(:files) { [build(:resource_file, :video, :world_downloadable, filename: 'data.zip'), build(:resource_file, :video, :world_downloadable, filename: 'data.zip')] }

it 'generates a file list' do
expect(page).to have_css 'li', visible: :all, count: 3
expect(page).to have_link href: 'https://stacks.stanford.edu/file/druid:bc123df4567/data.zip?download=true', visible: :all
end
end

context 'with stanford only' do
let(:response) { stanford_restricted_multi_file_purl_xml }
let(:contents) { [build(:resource, :file, files: [build(:resource_file, :stanford_only)])] }

it 'has the stanford-only class (with screen reader text)' do
expect(page).to have_css 'li .sul-embed-stanford-only-text .sul-embed-text-hide', text: 'Stanford only', visible: :all
end
end

context 'with location restrictions' do
let(:response) { single_video_purl }
let(:contents) { [build(:resource, :file, files: [build(:resource_file, :location_restricted)])] }

it 'includes text to indicate that they are restricted' do
expect(page).to have_css 'li .sul-embed-location-restricted-text', text: '(Restricted)', visible: :all
Expand Down
4 changes: 3 additions & 1 deletion spec/components/embed/file/header_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
let(:request) { Embed::Request.new(url: 'http://purl.stanford.edu/abc123') }
let(:viewer) { Embed::Viewer::File.new(request) }

let(:purl) { build(:purl, title: 'File Title') }

before do
stub_purl_xml_response_with_fixture(file_purl_xml)
allow(Embed::Purl).to receive(:find).and_return(purl)
render_inline(described_class.new(viewer:))
end

Expand Down
3 changes: 2 additions & 1 deletion spec/components/embed/footer_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
let(:request) { Embed::Request.new(url: 'http://purl.stanford.edu/abc123') }
let(:object) { Embed::Purl.find('12345') }
let(:viewer) { Embed::Viewer::Geo.new(request) }
let(:purl) { build(:purl) }

before do
stub_purl_xml_response_with_fixture(image_purl_xml)
allow(Embed::Purl).to receive(:find).and_return(purl)
render_inline(described_class.new(viewer:))
end

Expand Down
10 changes: 6 additions & 4 deletions spec/components/embed/legacy_media_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
end
let(:object) { Embed::Purl.find('12345') }
let(:viewer) { Embed::Viewer::Media.new(request) }
let(:response) { video_purl }
let(:purl) { build(:purl, :video) }

before do
stub_purl_xml_response_with_fixture(video_purl)
allow(Embed::Purl).to receive(:find).and_return(purl)
render_inline(described_class.new(viewer:))
end

it 'renders a video tag' do
expect(page).to have_css('video', visible: :all)
end

describe 'media tag' do
let(:response) { video_with_spaces_in_filename_purl }
context 'with spaces in file names' do
let(:purl) { build(:purl, :video, contents:) }
let(:contents) { [build(:resource, :video, files:)] }
let(:files) { [build(:resource_file, :video, :world_downloadable, filename: 'A video title.mp4')] }

it 'does not do URL escaping on sources' do
source = page.find_css('video source', visible: :all).first
Expand Down
3 changes: 2 additions & 1 deletion spec/components/embed/m3_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

let(:request) { Embed::Request.new(url: 'http://purl.stanford.edu/abc123', canvas_index: 3, search: 'xyz', suggested_search: 'abc') }
let(:viewer) { Embed::Viewer::M3Viewer.new(request) }
let(:purl) { build(:purl) }

before do
stub_purl_xml_response_with_fixture(image_purl_xml)
allow(Embed::Purl).to receive(:find).and_return(purl)
render_inline(described_class.new(viewer:))
end

Expand Down
3 changes: 2 additions & 1 deletion spec/components/embed/media/metadata_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

let(:request) { Embed::Request.new(url: 'http://purl.stanford.edu/abc123') }
let(:viewer) { Embed::Viewer::Media.new(request) }
let(:purl) { build(:purl) }

before do
stub_purl_xml_response_with_fixture(video_purl)
allow(Embed::Purl).to receive(:find).and_return(purl)
render_inline(described_class.new(viewer:))
end

Expand Down
7 changes: 5 additions & 2 deletions spec/components/embed/was_seed_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
Embed::Request.new(url: 'http://purl.stanford.edu/abc123')
end
let(:viewer) { Embed::Viewer::WasSeed.new(request) }
let(:purl) { build(:purl, :was_seed) }

before do
allow(Embed::Purl).to receive(:find).and_return(purl)
end

context 'with current timemap behavior' do
let(:fake_connection) do
Expand All @@ -19,7 +24,6 @@
before do
allow_any_instance_of(Embed::WasTimeMap).to receive(:redirectable_connection).and_return(fake_connection)
expect(fake_connection).to receive(:get).once
stub_purl_xml_response_with_fixture(was_seed_purl)
render_inline(described_class.new(viewer:))
end

Expand Down Expand Up @@ -49,7 +53,6 @@
before do
allow_any_instance_of(Embed::WasTimeMap).to receive(:redirectable_connection).and_return(fake_connection)
expect(fake_connection).to receive(:get).once
stub_purl_xml_response_with_fixture(was_seed_purl)
render_inline(described_class.new(viewer:))
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
FactoryBot.define do
factory :resource_file, class: 'Embed::Purl::ResourceFile' do
druid { 'bc123df4567' }
filename { 'data.zip' }

trait :document do
mimetype { 'application/pdf' }
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/purls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
factory :purl, class: 'Embed::Purl' do
druid { 'abc123' }
contents { [build(:resource, :file)] }
collections { [] }

trait :embargoed do
embargoed { true }
Expand All @@ -21,5 +22,10 @@
external_url { 'https://swap.stanford.edu/*/http://naca.central.cranfield.ac.uk/' }
contents { [build(:resource, :image)] }
end

trait :video do
type { 'media' }
contents { [build(:resource, :video)] }
end
end
end
23 changes: 0 additions & 23 deletions spec/fixtures/purl_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -899,29 +899,6 @@ def video_purl
XML
end

def video_with_spaces_in_filename_purl
<<-XML
<publicObject>
<identityMetadata>
<objectLabel>Title of a video with spaces in the file name</objectLabel>
</identityMetadata>
<contentMetadata type="media">
<resource sequence="1" id="abc123_1" type="video">
<file id="A video title.mp4" mimetype="video/mp4" size="152000000">
<videoData duration="P0DT1H2M3S" height="288" width="352"/>
</file>
</resource>
</contentMetadata>
<rightsMetadata>
#{access_read_world}
</rightsMetadata>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>stupid dc title of video</dc:title>
</oai_dc>
</publicObject>
XML
end

def invalid_video_duration_purl
<<-XML
<publicObject>
Expand Down