From b0b8c2438dcf9c91d009b4a3628836d712853c7c Mon Sep 17 00:00:00 2001 From: MazOneTwoOne <76905544+MazOneTwoOne@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:15:50 +0000 Subject: [PATCH] - add and update test suite --- fala/apps/adviser/models.py | 11 ++++-- ...ategory_search_page_journeys_playwright.py | 35 +++++++++---------- fala/apps/adviser/views.py | 5 ++- fala/playwright/setup.py | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/fala/apps/adviser/models.py b/fala/apps/adviser/models.py index c5f2f642..34b568c6 100644 --- a/fala/apps/adviser/models.py +++ b/fala/apps/adviser/models.py @@ -163,12 +163,13 @@ def get_context_data(self): class SingleSearchErrorState(object): - def __init__(self, form, category_display_name, category_message, category_code, search_url): + def __init__(self, form, category_display_name, category_message, category_code, search_url, category_slug): self._form = form - self._category_display_name = category_display_name + self.category_display_name = category_display_name self.category_message = category_message self.category_code = category_code self.search_url = search_url + self.category_slug = category_slug @property def template_name(self): @@ -187,12 +188,16 @@ def get_context_data(self): item = {"text": error[0], "href": f"#id_{field}"} errorList.append(item) + if self.category_slug == "hlpas": + self.category_display_name = "Housing Loss Prevention Advice Service" + return { "form": self._form, "data": {}, "errorList": errorList, + "category_slug": self.category_slug, "category_code": self.category_code, - "category_display_name": self._category_display_name, + "category_display_name": self.category_display_name, "category_message": self.category_message, "search_url": self.search_url, } diff --git a/fala/apps/adviser/tests/test_single_category_search_page_journeys_playwright.py b/fala/apps/adviser/tests/test_single_category_search_page_journeys_playwright.py index 7d4d3f45..414d959c 100644 --- a/fala/apps/adviser/tests/test_single_category_search_page_journeys_playwright.py +++ b/fala/apps/adviser/tests/test_single_category_search_page_journeys_playwright.py @@ -4,11 +4,16 @@ class SingleCategorySearchPageEndToEndJourneys(PlaywrightTestSetup): hlpas_front_page_heading = "Find a legal aid adviser for Housing Loss Prevention Advice Service" + med_front_page_heading = "Find a legal aid adviser for clinical negligence" - def test_landing_page(self): - page = self.visit_single_category_search_page("categories=hlpas") + def test_landing_page_with_hlpas(self): + page = self.visit_single_category_search_page("?categories=hlpas") expect(page.h1).to_have_text(f"{self.hlpas_front_page_heading}") + def test_landing_page_with_med(self): + page = self.visit_single_category_search_page("?categories=med") + expect(page.h1).to_have_text(f"{self.med_front_page_heading}") + def test_postcode_search_journey(self): test_cases = [ "SW1H 9AJ", @@ -18,20 +23,6 @@ def test_postcode_search_journey(self): with self.subTest(postcode=postcode): page = self.visit_results_page(postcode=postcode) expect(page.h1).to_have_text("Search results") - expect(page.change_search_grey_box.nth(0)).to_have_text(f"Postcode: {postcode}") - expect(page.item_from_text("in order of closeness")).to_be_visible() - - def test_full_search_journey(self): - page = self.visit_results_page_with_full_search( - "SE11", "Islington Law Centre", ["Housing Loss Prevention Advice Service"] - ) - expect(page.h1).to_have_text("Search results") - # this selector matches multiple things so picking out the things we want using 'nth()' - expect(page.change_search_grey_box.nth(0)).to_have_text("Postcode: SE11") - expect(page.change_search_grey_box.nth(1)).to_have_text("Organisation: Islington Law Centre") - expect(page.change_search_grey_box.nth(2)).to_have_text( - "Legal problem: Housing Loss Prevention Advice Service" - ) def test_invalid_postcode_journey(self): test_cases = [ @@ -43,9 +34,15 @@ def test_invalid_postcode_journey(self): for postcode in test_cases: with self.subTest(postcode=postcode): page = self.browser.new_page() - page.goto(f"{self.live_server_url}") - expect(page.locator("h1")).to_have_text(f"{self.front_page_heading}") + page.goto(f"{self.live_server_url}/single-category-search?categories=hlpas") + expect(page.locator("h1")).to_have_text(f"{self.hlpas_front_page_heading}") + page.get_by_label("Postcode").fill(f"{postcode}") + page.get_by_role("button", name="Search").click() + expect(page.locator("h1")).to_have_text(f"{self.hlpas_front_page_heading}") + expect(page.locator("css=.govuk-error-summary")).to_be_visible() + page.goto(f"{self.live_server_url}/single-category-search?categories=med") + expect(page.locator("h1")).to_have_text(f"{self.med_front_page_heading}") page.get_by_label("Postcode").fill(f"{postcode}") page.get_by_role("button", name="Search").click() - expect(page.locator("h1")).to_have_text(f"{self.front_page_heading}") + expect(page.locator("h1")).to_have_text(f"{self.med_front_page_heading}") expect(page.locator("css=.govuk-error-summary")).to_be_visible() diff --git a/fala/apps/adviser/views.py b/fala/apps/adviser/views.py index 37729ca2..315de9b0 100644 --- a/fala/apps/adviser/views.py +++ b/fala/apps/adviser/views.py @@ -175,8 +175,11 @@ def get(self, request, *args, **kwargs): category_code = self.request.GET.get("categories", "") search_url = reverse("search") + # this is so that we can get correct hlpas display name onto SingleSearchErrorState view + category_slug = self.request.GET.get("categories") + self.state = SingleSearchErrorState( - form, category_display_name, category_message, category_code, search_url + form, category_display_name, category_message, category_code, search_url, category_slug ) else: self.state = ErrorState(form) diff --git a/fala/playwright/setup.py b/fala/playwright/setup.py index d38ba8df..765874c7 100644 --- a/fala/playwright/setup.py +++ b/fala/playwright/setup.py @@ -77,7 +77,7 @@ def visit_search_page(self): def visit_single_category_search_page(self, url_params): page = self.browser.new_page() - page.goto(f"{self.live_server_url}/?single-category-search/{url_params}") + page.goto(f"{self.live_server_url}/single-category-search{url_params}") return SingleCategorySearchPage(page) def visit_cookies_page_from_footer(self):