Skip to content

Commit cf5624d

Browse files
authored
Merge pull request #261 from MITLibraries/use-152
Show Primo continuation partial only beyond page 1
2 parents 17e522b + 82f441c commit cf5624d

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)