diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f8fb3edd..285202de 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb index fbe872a9..4f5d0615 100644 --- a/test/controllers/search_controller_test.rb +++ b/test/controllers/search_controller_test.rb @@ -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