diff --git a/app/helpers/hyc_helper.rb b/app/helpers/hyc_helper.rb index 27bb8977a..51653a0da 100644 --- a/app/helpers/hyc_helper.rb +++ b/app/helpers/hyc_helper.rb @@ -22,8 +22,12 @@ def language_links_facets(options) # Format affiliation to display short label if available, otherwise display the original facet value def format_affiliation_facet(facet_value) - label = DepartmentsService.short_label(facet_value) - label.blank? ? facet_value : label + if facet_value.kind_of?(Array) + facet_value.map { |value| format_affiliation_facet(value) || value } + else + label = DepartmentsService.short_label(facet_value) + label.blank? ? facet_value : label + end end def get_work_url(model, id) diff --git a/spec/helpers/hyc_helper_spec.rb b/spec/helpers/hyc_helper_spec.rb index 301ed86ac..23ef69821 100644 --- a/spec/helpers/hyc_helper_spec.rb +++ b/spec/helpers/hyc_helper_spec.rb @@ -53,6 +53,14 @@ end end + context 'with array facet value' do + let(:facet_value) { ['Department of Chemistry', 'Carolina Center for Genome Sciences'] } + + it 'returns the short label for the facet value' do + expect(helper.format_affiliation_facet(facet_value)).to eq ['Test short Department of Chemistry', 'Test short Carolina Center for Genome Sciences'] + end + end + context 'with invalid facet value' do let(:invalid_facet_value) { 'not-a-department' }