Skip to content

Commit 1354d47

Browse files
committed
modify system tests to check titles
Where we are otherwise checking that we have landed on a particular page, ensure that we check the title of the page. This will help catch cases where we've forgot to set it. Normally I would check this in the view unit tests, but when using the Jinja template processor, we are not able to access the context passed to the view for test client requests.
1 parent d5cf40c commit 1354d47

10 files changed

+40
-5
lines changed

manage_breast_screening/tests/system/administrative/test_participant_record.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def then_i_should_be_on_the_participant_record_page(self):
111111
kwargs={"pk": self.participant.pk},
112112
)
113113
expect(self.page).to_have_url(re.compile(path))
114+
self.assert_page_title_contains("Participant")
114115

115116
def and_i_should_see_the_participant_record(self):
116117
main = self.page.get_by_role("main")

manage_breast_screening/tests/system/clinical/test_adding_previous_mammograms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def then_i_should_be_on_the_add_previous_mammogram_form(self):
9595
kwargs={"pk": self.participant.pk},
9696
)
9797
expect(self.page).to_have_url(re.compile(path))
98+
self.assert_page_title_contains("Add details of a previous mammogram")
9899

99100
def then_i_should_be_back_on_the_appointment(self):
100101
path = reverse(

manage_breast_screening/tests/system/clinical/test_editing_special_appointments.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def test_setting_up_a_special_appointment(self):
3030
self.given_i_am_logged_in_as_a_clinical_user()
3131
self.and_i_am_on_the_appointment_show_page()
3232
self.when_i_click_on_make_special_appointment()
33-
self.and_i_add_a_reason()
33+
self.then_i_am_on_the_special_appointment_form()
34+
35+
self.when_i_add_a_reason()
3436
self.and_i_select_no_reasons_are_temporary()
3537
self.and_i_submit_the_form()
3638
self.then_i_am_back_on_the_appointment()
@@ -158,11 +160,16 @@ def when_i_click_on_the_change_link(self):
158160
banner = self.page.locator(".nhsuk-warning-callout")
159161
banner.get_by_text("Change").click()
160162

163+
def then_i_am_on_the_special_appointment_form(self):
164+
self.assert_page_title_contains("Provide special appointment details")
165+
161166
def and_i_add_a_reason(self):
162167
self.page.get_by_label("Hearing").click()
163168
self.page.keyboard.press("Tab")
164169
self.page.locator("*:focus").fill("Deaf in one ear")
165170

171+
when_i_add_a_reason = and_i_add_a_reason
172+
166173
def and_i_add_another_reason(self):
167174
self.page.get_by_label("Gender identity").click()
168175
self.page.keyboard.press("Tab")

manage_breast_screening/tests/system/clinical/test_ethnicity_details_form.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_entering_ethnicity_details_for_a_participant(self):
2424
self.given_i_am_logged_in_as_a_clinical_user()
2525
self.and_i_am_viewing_an_appointment()
2626
self.when_i_click_on_enter_ethnicity_details()
27-
self.then_i_should_be_on_the_ethnicity_details_form()
27+
self.then_i_am_on_the_ethnicity_details_form()
2828

2929
self.when_i_submit_the_form()
3030
self.then_i_see_an_error()
@@ -35,7 +35,7 @@ def test_entering_ethnicity_details_for_a_participant(self):
3535
self.and_the_ethnicity_is_updated_to("Asian or Asian British (Chinese)")
3636

3737
self.when_i_click_the_change_ethnicity_link()
38-
self.then_i_should_be_on_the_ethnicity_details_form()
38+
self.then_i_am_on_the_ethnicity_details_form()
3939
self.and_the_saved_ethnicity_is_selected("Chinese")
4040
self.when_i_select_an_ethnicity("Any other White background")
4141
self.and_i_submit_the_form()
@@ -52,7 +52,7 @@ def test_entering_ethnicity_description_provided_by_the_participant(self):
5252
self.given_i_am_logged_in_as_a_clinical_user()
5353
self.and_i_am_viewing_an_appointment()
5454
self.when_i_click_on_enter_ethnicity_details()
55-
self.then_i_should_be_on_the_ethnicity_details_form()
55+
self.then_i_am_on_the_ethnicity_details_form()
5656

5757
self.when_i_select_an_ethnicity("Any other White background")
5858
self.and_i_enter_an_ethnicity_description_provided_by_the_participant(
@@ -83,7 +83,7 @@ def and_i_am_viewing_an_appointment(self):
8383
def when_i_click_on_enter_ethnicity_details(self):
8484
self.page.get_by_role("link", name="Enter ethnicity details").click()
8585

86-
def then_i_should_be_on_the_ethnicity_details_form(self):
86+
def then_i_am_on_the_ethnicity_details_form(self):
8787
expect(self.page).to_have_url(
8888
re.compile(
8989
reverse(
@@ -92,6 +92,7 @@ def then_i_should_be_on_the_ethnicity_details_form(self):
9292
)
9393
)
9494
)
95+
self.assert_page_title_contains("Ethnicity")
9596

9697
def when_i_submit_the_form(self):
9798
self.page.get_by_role("button", name="Save and continue").click()

manage_breast_screening/tests/system/clinical/test_recording_a_mammogram.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ def then_i_should_be_on_the_medical_information_page(self):
121121
kwargs={"pk": self.appointment.pk},
122122
)
123123
expect(self.page).to_have_url(re.compile(path))
124+
self.assert_page_title_contains("Medical information")
124125

125126
def then_i_should_be_on_the_record_medical_information_page(self):
126127
path = reverse(
127128
"mammograms:record_medical_information",
128129
kwargs={"pk": self.appointment.pk},
129130
)
130131
expect(self.page).to_have_url(re.compile(path))
132+
self.assert_page_title_contains("Record medical information")
131133

132134
def and_i_should_be_prompted_to_ask_about_relevant_medical_information(self):
133135
expect(
@@ -156,6 +158,7 @@ def then_the_screen_should_show_that_it_is_awaiting_images_from_the_PACS(self):
156158
kwargs={"pk": self.appointment.pk},
157159
)
158160
expect(self.page).to_have_url(re.compile(path))
161+
self.assert_page_title_contains("Awaiting images")
159162

160163
def then_i_am_prompted_to_answer_can_the_screening_go_ahead(self):
161164
self.expect_validation_error(

manage_breast_screening/tests/system/clinical/test_recording_symptoms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def when_i_click_on_add_a_lump(self):
9292

9393
def then_i_see_the_add_a_lump_form(self):
9494
expect(self.page.get_by_text("Details of the lump")).to_be_visible()
95+
self.assert_page_title_contains("Details of the lump")
9596

9697
def when_i_select_right_breast(self):
9798
self.page.get_by_label("Right breast").click()

manage_breast_screening/tests/system/clinical/test_user_submits_cannot_go_ahead_form.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def and_i_am_on_the_cannot_go_ahead_form(self):
5151
kwargs={"pk": self.appointment.pk},
5252
)
5353
)
54+
self.assert_page_title_contains("Appointment cannot go ahead")
5455

5556
def when_i_submit_the_form(self):
5657
self.page.get_by_role("button", name="Continue").click()

manage_breast_screening/tests/system/general/test_user_views_clinic_show_page.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.urls import reverse
66
from playwright.sync_api import expect
77

8+
from manage_breast_screening.clinics.models import Clinic
89
from manage_breast_screening.clinics.tests.factories import ClinicFactory
910
from manage_breast_screening.core.utils.date_formatting import format_date, format_time
1011
from manage_breast_screening.core.utils.string_formatting import (
@@ -66,6 +67,7 @@ def and_a_clinic_exists_that_is_run_by_my_provider(self):
6667
starts_at=self.clinic_start_time,
6768
setting__name="West London BSS",
6869
setting__provider=user_assignment.provider,
70+
risk_type=Clinic.RiskType.ROUTINE_RISK,
6971
)
7072

7173
def and_there_are_appointments(self):
@@ -100,12 +102,14 @@ def and_there_are_appointments(self):
100102

101103
def and_i_am_on_the_clinic_list(self):
102104
self.page.goto(self.live_server_url + reverse("clinics:index"))
105+
self.assert_page_title_contains("Today’s clinics")
103106

104107
def and_i_am_on_the_clinic_show_page(self):
105108
self.page.goto(
106109
self.live_server_url
107110
+ reverse("clinics:show", kwargs={"pk": self.clinic.pk})
108111
)
112+
self.assert_page_title_contains("Routine risk screening clinic")
109113

110114
def when_i_click_on_the_clinic(self):
111115
self.page.get_by_role("link", name="West London BSS").click()

manage_breast_screening/tests/system/general/test_viewing_a_completed_appointment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.urls import reverse
33
from playwright.sync_api import expect
44

5+
from manage_breast_screening.clinics.models import Clinic
56
from manage_breast_screening.participants.models import AppointmentStatus
67
from manage_breast_screening.participants.tests.factories import (
78
AppointmentFactory,
@@ -18,6 +19,7 @@ def before(self):
1819
self.participant = ParticipantFactory(first_name="Janet", last_name="Williams")
1920
self.screening_episode = ScreeningEpisodeFactory(participant=self.participant)
2021
self.appointment = AppointmentFactory(
22+
clinic_slot__clinic__type=Clinic.Type.SCREENING,
2123
screening_episode=self.screening_episode,
2224
current_status=AppointmentStatus.SCREENED,
2325
)
@@ -46,6 +48,7 @@ def and_i_am_on_the_appointment_show_page(self):
4648
kwargs={"pk": self.appointment.pk},
4749
)
4850
)
51+
self.assert_page_title_contains("Screening appointment")
4952

5053
def then_i_should_see_the_demographic_banner(self):
5154
expect(self.page.get_by_text("NHS Number")).to_be_visible()

manage_breast_screening/tests/system/system_test_setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def expect_validation_error(
107107

108108
expect(field).to_be_focused()
109109

110+
title_components = self.page_title_components()
111+
assert title_components[0].startswith("Error: "), title_components
112+
110113
def expect_url(self, url, **kwargs):
111114
path = reverse(url, kwargs=kwargs)
112115
url = re.compile(f"^{self.live_server_url}{re.escape(path)}$")
@@ -148,3 +151,13 @@ def then_the_accessibility_baseline_is_met(self, require_unique_link_text=True):
148151
duplicates = {k: v for k, v in counter.items() if v > 1}
149152

150153
self.assertEqual(len(duplicates), 0, duplicates)
154+
155+
def page_title_components(self):
156+
return self.page.title().split(" – ")
157+
158+
def assert_page_title_contains(self, component):
159+
components = self.page_title_components()
160+
161+
assert components[-1] == "NHS", components
162+
assert components[-2] == "Manage breast screening", components
163+
assert components[-3] == component, components

0 commit comments

Comments
 (0)