Skip to content

Commit

Permalink
- add and update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
MazOneTwoOne committed Dec 12, 2024
1 parent b5acc83 commit b0b8c24
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
11 changes: 8 additions & 3 deletions fala/apps/adviser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = [
Expand All @@ -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()
5 changes: 4 additions & 1 deletion fala/apps/adviser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fala/playwright/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b0b8c24

Please sign in to comment.