Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/helpers/results_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@ module ResultsHelper
def results_summary(hits)
hits.to_i >= 10_000 ? '10,000+ results' : "#{number_with_delimiter(hits)} results"
end

# Provides a description for the current tab in search results.
def tab_description
case params[:tab]
when 'all'
'All MIT Libraries sources'
when 'cdi'
'Journal and newspaper articles, book chapters, and more'
when 'alma', 'timdex_alma'
'Books, journals, streaming and physical media, and more'
when 'primo'
'Articles, books, chapters, streaming and physical media, and more'
when 'aspace'
'Archives, manuscripts, and other unique materials related to MIT'
when 'timdex'
'Digital collections, images, documents, and more from MIT Libraries'
when 'website'
'Information about the library: events, news, services, and more'
else
Rails.logger.error "Unknown tab parameter in `tab_description` helper: #{params[:tab]}"
end
end
end
2 changes: 1 addition & 1 deletion app/views/search/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<% elsif @results.present? && @errors.blank? %>

<h2 class="results-context"><%= results_summary(@pagination[:hits]) %></h2>
<p class="results-context-description">From all MIT Libraries sources</p>
<p class="results-context-description"><%= tab_description %></p>
<div id="results-layout-wrapper">
<main id="results">
<ol class="results-list use" start="<%= @pagination[:start] %>">
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ def source_filter_count(controller)
assert_response :success
assert_select '.results-context', text: /10 results/
assert_select '.results-context-description', count: 1
assert_select '.results-context-description', text: /From all MIT Libraries sources/
assert_select '.results-context-description',
text: /Articles, books, chapters, streaming and physical media, and more/
end

test 'primo results shows continuation partial when page exceeds API offset limit' do
Expand Down
34 changes: 34 additions & 0 deletions test/helpers/results_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,38 @@ class ResultsHelperTest < ActionView::TestCase
hits = 9000
assert_equal '9,000 results', results_summary(hits)
end

test 'result helper handles tab descriptions for tabs based on params hash' do
params[:tab] = 'all'
description = 'All MIT Libraries sources'
assert_equal description, tab_description

params[:tab] = 'cdi'
description = 'Journal and newspaper articles, book chapters, and more'
assert_equal description, tab_description

params[:tab] = 'alma'
description = 'Books, journals, streaming and physical media, and more'
assert_equal description, tab_description

params[:tab] = 'timdex_alma'
description = 'Books, journals, streaming and physical media, and more'
assert_equal description, tab_description

params[:tab] = 'primo'
description = 'Articles, books, chapters, streaming and physical media, and more'
assert_equal description, tab_description

params[:tab] = 'aspace'
description = 'Archives, manuscripts, and other unique materials related to MIT'
assert_equal description, tab_description

params[:tab] = 'timdex'
description = 'Digital collections, images, documents, and more from MIT Libraries'
assert_equal description, tab_description

params[:tab] = 'website'
description = 'Information about the library: events, news, services, and more'
assert_equal description, tab_description
end
end