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
3 changes: 2 additions & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def load_primo_results
if @results.empty?
docs = primo_response['docs'] if primo_response.is_a?(Hash)
if docs.nil? || docs.empty?
@show_primo_continuation = true
# Only show continuation for pagination scenarios (page > 1), not for searches with no results
@show_primo_continuation = true if current_page > 1
else
@errors = [{ 'message' => 'No more results available at this page number.' }]
end
Expand Down
41 changes: 41 additions & 0 deletions test/controllers/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,45 @@ def source_filter_count(controller)
assert_select '.primo-continuation', count: 1
assert_select '.primo-continuation h2', text: /Continue your search in Search Our Collections/
end

test 'primo results shows no results message when search returns no results on first page' do
mock_primo = mock('primo_search')
mock_primo.expects(:search).returns({ 'docs' => [], 'total' => 0 })
PrimoSearch.expects(:new).returns(mock_primo)

mock_normalizer = mock('normalizer')
mock_normalizer.expects(:normalize).returns([])
NormalizePrimoResults.expects(:new).returns(mock_normalizer)

get '/results?q=nonexistentterm&tab=primo'
assert_response :success
assert_select '.no-results', count: 1
assert_select '.no-results p', text: /No results found for your search/
refute_select '.primo-continuation'
end

test 'timdex results shows no results message when search returns no results on first page' do
mock_response = mock('timdex_response')
mock_errors = mock('timdex_errors')
mock_errors.stubs(:details).returns({})
mock_response.stubs(:errors).returns(mock_errors)

mock_data = mock('timdex_data')
mock_data.stubs(:to_h).returns({
'search' => {
'hits' => 0,
'aggregations' => {},
'records' => []
}
})
mock_response.stubs(:data).returns(mock_data)

TimdexBase::Client.expects(:query).returns(mock_response)

get '/results?q=nonexistentterm&tab=timdex'
assert_response :success
assert_select '.no-results', count: 1
assert_select '.no-results p', text: /No results found for your search/
refute_select '.primo-continuation'
end
end