require 'spec_helper'
describe ModsDisplay::Location do
let(:location_mods) do
<<-XML
On Shelf A
XML
end
let(:url_mods) do
<<-XML
http://library.stanford.edu
http://purl.stanford.edu
XML
end
let(:repository_mods) do
<<-XML
Location Field
XML
end
let(:location) do
mods = Stanford::Mods::Record.new.from_str(location_mods, false).location
described_class.new(mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
end
let(:urls) do
mods = Stanford::Mods::Record.new.from_str(url_mods, false).location
described_class.new(mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
end
let(:repository_label) do
mods = Stanford::Mods::Record.new.from_str(repository_mods, false).location
described_class.new(mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
end
describe 'label' do
it 'should have a default label' do
expect(location.first.label).to eq 'Location:'
end
it 'should handle the URL labels correctly' do
expect(urls.map(&:label)).to eq ['Location:', 'PURL:']
end
it 'should use get a label from a list of translations' do
expect(repository_label.first.label).to eq 'Repository:'
end
end
describe 'fields' do
describe 'URLs' do
it 'should link and use the displayLabel as text' do
expect(urls.length).to eq(2)
field = urls.find { |f| f.label == 'Location:' }
expect(field.values).to eq(["Stanford University Library"])
end
it 'should link the URL itself in the absence of a displayLabel on the url element' do
expect(urls.length).to eq(2)
field = urls.find { |f| f.label == 'PURL:' }
expect(field.values).to eq(["http://purl.stanford.edu"])
end
end
end
end