Skip to content

Commit e4e0a15

Browse files
committed
Benign lumps: add system test for creating
1 parent a839980 commit e4e0a15

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from django.urls import reverse
2+
from playwright.sync_api import expect
3+
4+
from manage_breast_screening.participants.tests.factories import (
5+
AppointmentFactory,
6+
ParticipantFactory,
7+
ScreeningEpisodeFactory,
8+
)
9+
10+
from ..system_test_setup import SystemTestCase
11+
12+
13+
class TestBenignLumpHistory(SystemTestCase):
14+
def test_adding_a_benign_lump_history_item(self):
15+
self.given_i_am_logged_in_as_a_clinical_user()
16+
self.and_there_is_an_appointment()
17+
self.and_i_am_on_the_record_medical_information_page()
18+
self.when_i_click_on_add_benign_lump_history()
19+
self.then_i_see_the_add_benign_lump_history_form()
20+
self.when_i_try_to_save_without_entering_benign_lump_details()
21+
self.then_i_see_validation_errors_for_missing_benign_lump_details()
22+
23+
self.when_i_select_procedures_for_each_breast()
24+
self.and_i_enter_the_year_and_select_a_location()
25+
self.and_i_enter_additional_details()
26+
self.and_i_click_save_benign_lump_history()
27+
self.then_i_see_a_validation_error_for_missing_location_details()
28+
29+
self.when_i_enter_the_location_details()
30+
self.and_i_click_save_benign_lump_history()
31+
self.then_i_am_back_on_the_medical_information_page()
32+
self.and_the_benign_lump_history_item_is_listed()
33+
self.and_the_message_says_benign_lump_history_added()
34+
35+
def test_accessibility(self):
36+
self.given_i_am_logged_in_as_a_clinical_user()
37+
self.and_there_is_an_appointment()
38+
self.and_i_am_on_the_record_medical_information_page()
39+
self.when_i_click_on_add_benign_lump_history()
40+
self.then_the_accessibility_baseline_is_met()
41+
42+
def and_there_is_an_appointment(self):
43+
self.participant = ParticipantFactory(first_name="Sonia", last_name="Dhillon")
44+
self.screening_episode = ScreeningEpisodeFactory(participant=self.participant)
45+
self.appointment = AppointmentFactory(
46+
screening_episode=self.screening_episode,
47+
clinic_slot__clinic__setting__provider=self.current_provider,
48+
)
49+
50+
def and_i_am_on_the_record_medical_information_page(self):
51+
self.page.goto(
52+
self.live_server_url
53+
+ reverse(
54+
"mammograms:record_medical_information",
55+
kwargs={"pk": self.appointment.pk},
56+
)
57+
)
58+
59+
def when_i_click_on_add_benign_lump_history(self):
60+
self.page.get_by_text("Add benign lump history", exact=True).click()
61+
62+
def then_i_see_the_add_benign_lump_history_form(self):
63+
expect(self.page.get_by_text("Add details of benign lumps")).to_be_visible()
64+
self.assert_page_title_contains("Add details of benign lumps")
65+
66+
def when_i_try_to_save_without_entering_benign_lump_details(self):
67+
self.page.get_by_role("button", name="Save").click()
68+
69+
def then_i_see_validation_errors_for_missing_benign_lump_details(self):
70+
self.expect_validation_error(
71+
error_text="Select which procedures they have had in the left breast",
72+
fieldset_legend="Left breast",
73+
field_label="Needle biopsy",
74+
)
75+
self.expect_validation_error(
76+
error_text="Select which procedures they have had in the right breast",
77+
fieldset_legend="Right breast",
78+
field_label="Needle biopsy",
79+
)
80+
self.expect_validation_error(
81+
error_text="Select where the tests and treatment were done",
82+
fieldset_legend="Where were the tests and treatment done?",
83+
field_label="At an NHS hospital",
84+
)
85+
86+
def when_i_select_procedures_for_each_breast(self):
87+
right_fieldset = self.page.get_by_role("group", name="Right breast", exact=True)
88+
right_fieldset.get_by_label("Needle biopsy", exact=True).check()
89+
right_fieldset.get_by_label("Lump removed", exact=True).check()
90+
91+
left_fieldset = self.page.get_by_role("group", name="Left breast", exact=True)
92+
left_fieldset.get_by_label("Lump removed", exact=True).check()
93+
94+
def and_i_enter_the_year_and_select_a_location(self):
95+
self.page.get_by_label("Year of procedure (optional)", exact=True).fill("2022")
96+
self.page.get_by_label("At an NHS hospital", exact=True).click()
97+
98+
def when_i_enter_the_location_details(self):
99+
self.page.locator("#id_nhs_hospital_details").fill(
100+
"St Thomas' Hospital, London"
101+
)
102+
103+
def and_i_enter_additional_details(self):
104+
self.page.get_by_label("Additional details (optional)", exact=True).fill(
105+
"Participant described no complications following any of the procedures."
106+
)
107+
108+
def and_i_click_save_benign_lump_history(self):
109+
self.page.get_by_role("button", name="Save").click()
110+
111+
def then_i_see_a_validation_error_for_missing_location_details(self):
112+
self.expect_validation_error(
113+
error_text="This field is required.",
114+
fieldset_legend="Where were the tests and treatment done?",
115+
field_label="Provide details",
116+
field_name="nhs_hospital_details",
117+
)
118+
119+
def then_i_am_back_on_the_medical_information_page(self):
120+
self.expect_url("mammograms:record_medical_information", pk=self.appointment.pk)
121+
122+
def and_the_benign_lump_history_item_is_listed(self):
123+
key = self.page.locator(
124+
".nhsuk-summary-list__key",
125+
has=self.page.get_by_text("Benign lump history", exact=True),
126+
)
127+
row = self.page.locator(".nhsuk-summary-list__row").filter(has=key)
128+
129+
expect(row).to_contain_text("Right breast: Needle biopsy, Lump removed")
130+
expect(row).to_contain_text("Left breast: Lump removed")
131+
expect(row).to_contain_text("2022")
132+
expect(row).to_contain_text("At an NHS hospital: St Thomas' Hospital, London")
133+
expect(row).to_contain_text(
134+
"Participant described no complications following any of the procedures."
135+
)
136+
137+
def and_the_message_says_benign_lump_history_added(self):
138+
alert = self.page.get_by_role("alert")
139+
140+
expect(alert).to_contain_text("Success")
141+
expect(alert).to_contain_text("Added benign lump history")

0 commit comments

Comments
 (0)