Skip to content

Commit

Permalink
Merge pull request #907 from nationalarchives/fcl-97-search-pages-on-…
Browse files Browse the repository at this point in the history
…pui-do-not-have-useful-breadcrumbs

Reinstate breadcrumbs on search results
  • Loading branch information
jacksonj04 authored Oct 3, 2023
2 parents 90f200e + 0ea84ae commit 2aa0776
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions judgments/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,25 @@ def test_judgment_advanced_search_shows_message_with_crossed_dates(
self.assertContains(
response, f'<div class="page-notification--failure">{message}</div>'
)


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"'}
]
7 changes: 7 additions & 0 deletions judgments/views/advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)

0 comments on commit 2aa0776

Please sign in to comment.