require 'spec_helper'
def mods_display_id(mods_record)
ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
end
describe ModsDisplay::Note do
before(:all) do
@id = Stanford::Mods::Record.new.from_str('12345', false).identifier
@display_label = Stanford::Mods::Record.new.from_str(
"54321", false
).identifier
@issue_label = Stanford::Mods::Record.new.from_str(
"Issue 1", false
).identifier
@type_label = Stanford::Mods::Record.new.from_str(
"98765", false
).identifier
@complex_label = Stanford::Mods::Record.new.from_str(
"
12345
54321
12345
98765
", false
).identifier
end
describe 'label' do
it 'should have a default label' do
expect(mods_display_id(@id).fields.first.label).to eq('Identifier:')
end
it 'should use the displayLabel attribute when one is available' do
expect(mods_display_id(@display_label).fields.first.label).to eq('Special Label:')
end
it 'should use get a label from a list of translations' do
expect(mods_display_id(@issue_label).fields.first.label).to eq('Issue number:')
end
it 'should use use the raw type attribute if one is present' do
expect(mods_display_id(@type_label).fields.first.label).to eq('Some other Type:')
end
end
describe 'fields' do
it 'should handle matching adjacent labels' do
fields = mods_display_id(@complex_label).fields
expect(fields.length).to eq(3)
expect(fields.first.label).to eq('Identifier:')
expect(fields.first.values.length).to eq(2)
expect(fields.first.values).to eq(%w(12345 54321))
expect(fields[1].label).to eq('Issue number:')
expect(fields[1].values.length).to eq(1)
expect(fields[1].values).to eq(['12345'])
expect(fields.last.label).to eq('Identifier:')
expect(fields.last.values.length).to eq(1)
expect(fields.last.values).to eq(['98765'])
end
end
end