Skip to content

Commit 82f441c

Browse files
committed
Show Primo continuation partial only beyond page 1
Why these changes are being introduced: A condition in the `load_primo_results` method in the Search Controller renders the Primo continuation partial if results are empty. This is necessary because of erratic behavior by the Primo search API, but it is problematic because the condition also triggers if the search returns no results. Relevant ticket(s): - [USE-152](https://mitlibraries.atlassian.net/browse/USE-152) How this addresses that need: This updates the problematic branch of the conditional so it also checks if the current page is 2 or higher before rendering the Primo continuation partial. Side effects of this change: None.
1 parent 17e522b commit 82f441c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/controllers/search_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def load_primo_results
7777
if @results.empty?
7878
docs = primo_response['docs'] if primo_response.is_a?(Hash)
7979
if docs.nil? || docs.empty?
80-
@show_primo_continuation = true
80+
# Only show continuation for pagination scenarios (page > 1), not for searches with no results
81+
@show_primo_continuation = true if current_page > 1
8182
else
8283
@errors = [{ 'message' => 'No more results available at this page number.' }]
8384
end

test/controllers/search_controller_test.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,45 @@ def source_filter_count(controller)
675675
assert_select '.primo-continuation', count: 1
676676
assert_select '.primo-continuation h2', text: /Continue your search in Search Our Collections/
677677
end
678+
679+
test 'primo results shows no results message when search returns no results on first page' do
680+
mock_primo = mock('primo_search')
681+
mock_primo.expects(:search).returns({ 'docs' => [], 'total' => 0 })
682+
PrimoSearch.expects(:new).returns(mock_primo)
683+
684+
mock_normalizer = mock('normalizer')
685+
mock_normalizer.expects(:normalize).returns([])
686+
NormalizePrimoResults.expects(:new).returns(mock_normalizer)
687+
688+
get '/results?q=nonexistentterm&tab=primo'
689+
assert_response :success
690+
assert_select '.no-results', count: 1
691+
assert_select '.no-results p', text: /No results found for your search/
692+
refute_select '.primo-continuation'
693+
end
694+
695+
test 'timdex results shows no results message when search returns no results on first page' do
696+
mock_response = mock('timdex_response')
697+
mock_errors = mock('timdex_errors')
698+
mock_errors.stubs(:details).returns({})
699+
mock_response.stubs(:errors).returns(mock_errors)
700+
701+
mock_data = mock('timdex_data')
702+
mock_data.stubs(:to_h).returns({
703+
'search' => {
704+
'hits' => 0,
705+
'aggregations' => {},
706+
'records' => []
707+
}
708+
})
709+
mock_response.stubs(:data).returns(mock_data)
710+
711+
TimdexBase::Client.expects(:query).returns(mock_response)
712+
713+
get '/results?q=nonexistentterm&tab=timdex'
714+
assert_response :success
715+
assert_select '.no-results', count: 1
716+
assert_select '.no-results p', text: /No results found for your search/
717+
refute_select '.primo-continuation'
718+
end
678719
end

0 commit comments

Comments
 (0)