Skip to content

Commit

Permalink
HYC-2047 - Prevent error when depts are select in the advanced search (
Browse files Browse the repository at this point in the history
…#1148)

* Prevent error when depts are select in the advanced search, which produces a list of dept keys

* Rubocop
  • Loading branch information
bbpennel authored Feb 26, 2025
1 parent b88d102 commit b26a07a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/helpers/hyc_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/hyc_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down

0 comments on commit b26a07a

Please sign in to comment.