Skip to content

Commit

Permalink
WIP:
Browse files Browse the repository at this point in the history
- add tests
  • Loading branch information
MazOneTwoOne committed Dec 12, 2024
1 parent df4b245 commit b5acc83
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
3 changes: 1 addition & 2 deletions fala/apps/adviser/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,12 @@ def clean(self):
self.add_error("postcode", _("Enter a postcode"))
return data

# Validate postcode and set `_country_from_valid_postcode`
if postcode:
valid_postcode = self.validate_postcode_and_return_country(postcode)
if not valid_postcode:
self.add_error("postcode", _("Enter a valid postcode"))
else:
self._country_from_valid_postcode = valid_postcode # This is used by the `region` property
self._country_from_valid_postcode = valid_postcode

# Check if categories are provided
if not categories:
Expand Down
14 changes: 14 additions & 0 deletions fala/apps/adviser/tests/page_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,19 @@ def search(self, postcode):
self._page.locator("#searchButton").click()


class SingleCategorySearchPage(FalaPage):
@property
def postcode_input_field(self):
return self._page.get_by_label("Postcode")

@property
def search_button(self):
return self.item_from_text("Search")

def search(self, postcode):
self._page.locator("#id_postcode").fill(postcode)
self._page.locator("#searchButton").click()


class CookiesPage(FalaPage):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from playwright.sync_api import expect
from fala.playwright.setup import PlaywrightTestSetup


class SingleCategorySearchPageEndToEndJourneys(PlaywrightTestSetup):
hlpas_front_page_heading = "Find a legal aid adviser for Housing Loss Prevention Advice Service"

def test_landing_page(self):
page = self.visit_single_category_search_page("categories=hlpas")
expect(page.h1).to_have_text(f"{self.hlpas_front_page_heading}")

def test_postcode_search_journey(self):
test_cases = [
"SW1H 9AJ",
"SE11",
]
for postcode in test_cases:
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 = [
"ZZZ1",
"G12 OGJKLJGK",
"LS25 ghjkhjkh",
"IM4 TESTTTTTTTTTTTT",
]
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.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("css=.govuk-error-summary")).to_be_visible()
13 changes: 12 additions & 1 deletion fala/playwright/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import os
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from playwright.sync_api import sync_playwright
from fala.apps.adviser.tests.page_objects import ResultsPage, OtherRegionPage, SearchPage, CookiesPage
from fala.apps.adviser.tests.page_objects import (
ResultsPage,
OtherRegionPage,
SearchPage,
CookiesPage,
SingleCategorySearchPage,
)


class PlaywrightTestSetup(StaticLiveServerTestCase):
Expand Down Expand Up @@ -69,6 +75,11 @@ def visit_search_page(self):
page.goto(f"{self.live_server_url}")
return SearchPage(page)

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}")
return SingleCategorySearchPage(page)

def visit_cookies_page_from_footer(self):
page = self.browser.new_page()
page.goto(f"{self.live_server_url}")
Expand Down

0 comments on commit b5acc83

Please sign in to comment.