From 0ea84ae5a48ddb327a520b9519144d1d7bf8c8e9 Mon Sep 17 00:00:00 2001 From: Nick Jackson Date: Tue, 3 Oct 2023 11:18:25 +0100 Subject: [PATCH] Add breadcrumbs back to search results --- judgments/tests/test_search.py | 22 ++++++++++++++++++++++ judgments/views/advanced_search.py | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/judgments/tests/test_search.py b/judgments/tests/test_search.py index f1b582dbe..13f481265 100644 --- a/judgments/tests/test_search.py +++ b/judgments/tests/test_search.py @@ -173,3 +173,25 @@ def test_judgment_advanced_search_shows_message_with_crossed_dates( self.assertContains( response, f'
{message}
' ) + + +class TestSearchBreadcrumbs(TestCase): + @patch("judgments.views.advanced_search.api_client") + @patch("judgments.views.advanced_search.search_judgments_and_parse_response") + def test_search_breadcrumbs_without_query_string( + self, mock_search_judgments_and_parse_response, mock_api_client + ): + mock_search_judgments_and_parse_response.return_value = FakeSearchResponse() + response = self.client.get("/judgments/search") + assert response.context["breadcrumbs"] == [{"text": "Search results"}] + + @patch("judgments.views.advanced_search.api_client") + @patch("judgments.views.advanced_search.search_judgments_and_parse_response") + def test_search_breadcrumbs_with_query_string( + self, mock_search_judgments_and_parse_response, mock_api_client + ): + mock_search_judgments_and_parse_response.return_value = FakeSearchResponse() + response = self.client.get("/judgments/search?query=waltham+forest") + assert response.context["breadcrumbs"] == [ + {"text": 'Search results for "waltham forest"'} + ] diff --git a/judgments/views/advanced_search.py b/judgments/views/advanced_search.py index fe32a06f3..036433d21 100644 --- a/judgments/views/advanced_search.py +++ b/judgments/views/advanced_search.py @@ -132,11 +132,18 @@ def advanced_search(request): except MarklogicResourceNotFoundError: raise Http404("Search failed") # TODO: This should be something else! + + # If we have a search query, stick it in the breadcrumbs. Otherwise, don't bother. + if query_params["query"]: + breadcrumbs = [{"text": f'Search results for "{query_params["query"]}"'}] + else: + breadcrumbs = [{"text": "Search results"}] return TemplateResponse( request, "judgment/results.html", context={ "context": context, + "breadcrumbs": breadcrumbs, "feedback_survey_type": "structured_search", }, )