# frozen_string_literal: true require 'spec_helper' require 'byebug' describe ModsDisplay::Helpers::RecordHelper, type: :helper do let(:empty_field) { OpenStruct.new(label: 'test', values: ['']) } describe 'display_content_field' do let(:values) { ['guitar (1)', 'solo cowbell, trombone (2)'] } let(:content) { OpenStruct.new(label: 'Instrumentation', values: values) } it 'should return dt with label and dd with values' do expect(helper.display_content_field(content)).to have_css('dt', text: 'Instrumentation') expect(helper.display_content_field(content)).to have_css('dd', count: 2) end end describe 'display_content_label' do it 'should return correct dt' do expect(helper.display_content_label('test')).to have_css('dt', text: 'test') end end describe 'display_content_values' do let(:values) { ['guitar (1)', 'solo cowbell, trombone (2)'] } it 'should return dds of values' do expect(helper.display_content_values(values)).to have_css('dd', count: 2) expect(helper.display_content_values(values)).to have_css('dd', text: 'guitar (1)') expect(helper.display_content_values(values)).to have_css('dd', text: 'solo cowbell, trombone (2)') end end describe 'mods_display_label' do it 'should return correct label' do expect(helper.mods_display_label('test:')).not_to have_content ':' expect(helper.mods_display_label('test:')).to have_css('dt', text: 'test') end end describe 'mods_display_content' do it 'should return correct content' do expect(helper.mods_display_content('hello, there')).to have_css('dd', text: 'hello, there') end it 'should return multiple dd elements when a multi-element array is passed' do expect(helper.mods_display_content(%w(hello there))).to have_css('dd', count: 2) end it 'should handle nil values correctly' do expect(helper.mods_display_content(['something', nil])).to have_css('dd', count: 1) end end describe 'mods_record_field' do let(:mods_field) { OpenStruct.new(label: 'test', values: ['hello, there']) } let(:url_field) { OpenStruct.new(label: 'test', values: ['https://library.stanford.edu']) } let(:multi_values) { double(label: 'test', values: %w(123 321)) } it 'should return correct content' do expect(helper.mods_record_field(mods_field)).to have_css('dt', text: 'test') expect(helper.mods_record_field(mods_field)).to have_css('dd', text: 'hello, there') end it 'should link fields with URLs' do expect(mods_record_field(url_field)).to have_css("a[href='https://library.stanford.edu']", text: 'https://library.stanford.edu') end it 'should not print empty labels' do expect(helper.mods_record_field(empty_field)).not_to be_present end it 'should join values with a