Skip to content

Commit 280a16e

Browse files
committed
remove main assertions from sessions page
1 parent 1c749f9 commit 280a16e

File tree

3 files changed

+89
-64
lines changed

3 files changed

+89
-64
lines changed

mavis/test/pages/sessions.py

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def __init__(
132132
"#vaccinate-form-vaccine-method-nasal-field"
133133
)
134134
self.attending_button = self.page.get_by_role("button", name="Attending").first
135-
self.success_alert = self.page.get_by_role("alert", name="Success")
136135
self.notes_length_error = (
137136
page.locator("div").filter(has_text="There is a problemEnter").nth(3)
138137
)
@@ -531,7 +530,7 @@ def add_note(self, note: str):
531530
with self.page.expect_navigation():
532531
self.click_save_note()
533532

534-
expect(self.success_alert).to_contain_text("Note added")
533+
self.expect_alert_text("Note added")
535534
reload_until_element_is_visible(self.page, self.page.get_by_text(note))
536535

537536
self.check_notes_appear_in_order([note])
@@ -562,22 +561,43 @@ def download_offline_recording_excel(self) -> Path:
562561

563562
return _file_path
564563

565-
@step("Expect text {1}")
566-
def expect_main_to_contain_text(self, text: str):
567-
expect(self.page.locator("main")).to_contain_text(text)
564+
def expect_consent_refused_text(self, parent: Parent):
565+
expect(
566+
self.page.get_by_text(f"{parent.relationship} refused to give consent.")
567+
).to_be_visible()
568+
569+
def check_session_activity_entry(self, text: str):
570+
expect(self.page.get_by_role("heading", name=text).first).to_be_visible()
571+
572+
def expect_conflicting_consent_text(self):
573+
expect(
574+
self.page.get_by_text(
575+
"You can only vaccinate if all respondents give consent."
576+
)
577+
).to_be_visible()
578+
579+
def expect_consent_status(self, programme: Programme, status: str):
580+
expect(self.page.get_by_text(f"{programme}: {status}")).to_be_visible()
581+
582+
def expect_child_safe_to_vaccinate(self, child: Child):
583+
expect(
584+
self.page.get_by_text(
585+
f"NURSE, Nurse decided that {str(child)} is safe to vaccinate."
586+
)
587+
).to_be_visible()
568588

569589
def get_session_id_from_offline_excel(self):
570590
file_path = self.download_offline_recording_excel()
571591
return self.test_data.get_session_id(file_path)
572592

573593
@step("Add Gillick competence details")
574594
def add_gillick_competence(
575-
self, is_competent: bool, competence_details: str
595+
self,
596+
is_competent: bool,
576597
) -> None:
577598
self.__set_gillick_competence(
578599
is_add=True,
579600
is_competent=is_competent,
580-
competence_details=competence_details,
581601
)
582602

583603
@step("Click Sessions")
@@ -586,29 +606,35 @@ def click_sessions(self) -> None:
586606

587607
@step("Edit Gillick competence details")
588608
def edit_gillick_competence(
589-
self, is_competent: bool, competence_details: str
609+
self,
610+
is_competent: bool,
590611
) -> None:
591612
self.__set_gillick_competence(
592613
is_add=False,
593614
is_competent=is_competent,
594-
competence_details=competence_details,
595615
)
596616

597617
def __set_gillick_competence(
598-
self, is_add: bool, is_competent: bool, competence_details: str
618+
self,
619+
is_add: bool,
620+
is_competent: bool,
599621
) -> None:
600622
self.answer_gillick_competence_questions(is_competent)
623+
competence_assessment = (
624+
f"Child assessed as {'' if is_competent else 'not '}Gillick competent"
625+
)
601626

602-
self.assessment_notes_textbox.fill(competence_details)
627+
self.assessment_notes_textbox.fill(competence_assessment)
603628
if is_add:
604629
self.click_complete_assessment()
605630
else:
606631
self.click_update_assessment()
607-
if is_competent:
608-
self.expect_main_to_contain_text("Child assessed as Gillick competent")
609-
else:
610-
self.expect_main_to_contain_text("Child assessed as not Gillick competent")
611-
self.expect_main_to_contain_text(competence_details)
632+
633+
competence_result_locator = self.page.get_by_role(
634+
"heading", name="Gillick assessment"
635+
).locator("xpath=following-sibling::*[1]")
636+
637+
expect(competence_result_locator).to_contain_text(competence_assessment)
612638

613639
def answer_gillick_competence_questions(self, is_competent):
614640
questions = [
@@ -632,7 +658,7 @@ def __schedule_session(self, on_date: str, expect_error: bool = False):
632658
self.fill_date_fields(_day, _month, _year)
633659
self.click_continue_button()
634660
if expect_error:
635-
self.expect_main_to_contain_text("There is a problemEnter a date")
661+
self.expect_alert_text("There is a problemEnter a date")
636662

637663
def __edit_session(self, to_date: str):
638664
_day = to_date[-2:]
@@ -650,23 +676,28 @@ def __edit_session(self, to_date: str):
650676
).not_to_be_visible()
651677

652678
def verify_triage_updated_for_child(self):
653-
expect(self.success_alert).to_contain_text("Triage outcome updated")
679+
self.expect_alert_text("Triage outcome updated")
654680

655681
def invalidate_parent_refusal(self, parent: Parent):
682+
invalidation_notes = "Invalidation notes."
656683
self.page.get_by_role("link", name=parent.full_name).click()
657684
self.click_mark_as_invalid_link()
658-
self.fill_notes("Invalidation notes.")
685+
self.fill_notes(invalidation_notes)
659686
self.click_mark_as_invalid_button()
660-
self.expect_main_to_contain_text("Consent refusedInvalid")
661-
self.expect_main_to_contain_text("Invalidation notes.")
687+
self.expect_details("Decision", "Consent refusedInvalid")
688+
self.expect_details("Notes", invalidation_notes)
662689

663690
self.click_back_to_child()
664-
self.expect_main_to_contain_text("Consent refusedInvalid")
665-
self.expect_main_to_contain_text("No requests have been sent.")
691+
self.expect_details("Decision", "Consent refusedInvalid")
692+
expect(self.page.get_by_text("No requests have been sent.")).to_be_visible()
666693

667-
def verify_scheduled_date(self, message: str):
668-
self.expect_main_to_contain_text(message)
669-
self.click_continue_link()
694+
def expect_details(self, key: str, value: str) -> None:
695+
detail_key = self.page.locator(
696+
".nhsuk-summary-list__key", has_text=re.compile(f"^{key}$")
697+
).first
698+
detail_value = detail_key.locator("xpath=following-sibling::*[1]")
699+
700+
expect(detail_value).to_contain_text(value)
670701

671702
def schedule_a_valid_session(
672703
self,
@@ -684,10 +715,13 @@ def schedule_a_valid_session(
684715
else:
685716
offset_days = 10
686717
_future_date = get_offset_date(offset_days=offset_days)
687-
_expected_message = f"Session dates{self.__get_display_formatted_date(date_to_format=_future_date)}"
688718
self.click_session_for_programme_group(location, programme_group)
689719
self.__schedule_session(on_date=_future_date)
690-
self.verify_scheduled_date(message=_expected_message)
720+
self.expect_details(
721+
"Session dates",
722+
self.__get_display_formatted_date(date_to_format=_future_date),
723+
)
724+
self.click_continue_link()
691725

692726
def edit_a_session_to_today(self, location: str, programme_group: str):
693727
_future_date = get_offset_date(offset_days=0)
@@ -741,7 +775,9 @@ def verify_search(self):
741775
"""
742776
self.click_consent_tab()
743777
self.search_for("a very long string that won't match any names")
744-
self.expect_main_to_contain_text("No children matching search criteria found")
778+
expect(
779+
self.page.get_by_text("No children matching search criteria found")
780+
).to_be_visible()
745781

746782
def search_child(self, child: Child) -> None:
747783
self.search_for(str(child))
@@ -790,11 +826,12 @@ def record_vaccs_for_child(
790826
self.vaccination_notes.fill("Confirmation notes")
791827
self.click_confirm_button()
792828

793-
expect(self.success_alert).to_contain_text(
794-
f"Vaccination outcome recorded for {programme}"
795-
)
829+
self.expect_alert_text(f"Vaccination outcome recorded for {programme}")
796830
return datetime.now().astimezone()
797831

832+
def expect_alert_text(self, text: str):
833+
expect(self.page.get_by_role("alert")).to_contain_text(text)
834+
798835
def verify_child_shows_correct_flu_consent_method(self, child: Child, method: str):
799836
patient_card = self.page.locator(
800837
f'div.nhsuk-card.app-card.app-card--compact:has(h4:has-text("{str(child)}"))'

tests/test_programmes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_rav_triage_consent_refused(
256256
sessions_page.select_consent_refused()
257257
sessions_page.click_child(child)
258258
sessions_page.click_session_activity_and_notes()
259-
sessions_page.expect_main_to_contain_text(
259+
sessions_page.check_session_activity_entry(
260260
f"Consent refused by {child.parents[0].name_and_relationship}"
261261
)
262262

@@ -325,7 +325,7 @@ def test_rav_verify_excel_mav_854(
325325
sessions_page.check_location_radio(clinics[0])
326326
sessions_page.click_continue_button()
327327
sessions_page.click_confirm_button()
328-
sessions_page.expect_main_to_contain_text("Vaccination outcome recorded for HPV")
328+
sessions_page.expect_alert_text("Vaccination outcome recorded for HPV")
329329
dashboard_page.click_mavis()
330330
dashboard_page.click_sessions()
331331
sessions_page.click_session_for_programme_group(school, Programme.HPV)

tests/test_verbal_consent.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,9 @@ def test_gillick_competence(setup_fixed_child, schools, sessions_page, children)
5656
sessions_page.click_session_for_programme_group(school, Programme.HPV)
5757
sessions_page.navigate_to_gillick_competence(child, Programme.HPV)
5858

59-
sessions_page.add_gillick_competence(
60-
is_competent=True, competence_details="Gillick competent"
61-
)
59+
sessions_page.add_gillick_competence(is_competent=True)
6260
sessions_page.click_edit_gillick_competence()
63-
sessions_page.edit_gillick_competence(
64-
is_competent=False, competence_details="Not Gillick competent"
65-
)
61+
sessions_page.edit_gillick_competence(is_competent=False)
6662

6763

6864
@issue("MAV-955")
@@ -111,13 +107,13 @@ def test_invalid_consent(
111107
sessions_page.invalidate_parent_refusal(child.parents[1])
112108
sessions_page.click_session_activity_and_notes()
113109

114-
sessions_page.expect_main_to_contain_text(
110+
sessions_page.check_session_activity_entry(
115111
f"Consent from {child.parents[1].full_name} invalidated"
116112
)
117-
sessions_page.expect_main_to_contain_text(
113+
sessions_page.check_session_activity_entry(
118114
f"Consent refused by {child.parents[1].name_and_relationship}"
119115
)
120-
sessions_page.expect_main_to_contain_text(
116+
sessions_page.check_session_activity_entry(
121117
f"Consent not_provided by {child.parents[0].name_and_relationship}"
122118
)
123119

@@ -146,15 +142,13 @@ def test_parent_provides_consent_twice(
146142

147143
sessions_page.click_child(child)
148144
sessions_page.click_programme_tab(Programme.HPV)
149-
sessions_page.expect_main_to_contain_text(
150-
f"{child.parents[0].relationship} refused to give consent."
151-
)
145+
sessions_page.expect_consent_refused_text(child.parents[0])
152146
sessions_page.click_session_activity_and_notes()
153-
sessions_page.expect_main_to_contain_text(
147+
sessions_page.check_session_activity_entry(
154148
f"Consent refused by {child.parents[0].name_and_relationship}"
155149
)
156-
sessions_page.expect_main_to_contain_text("Triaged decision: Safe to vaccinate")
157-
sessions_page.expect_main_to_contain_text(
150+
sessions_page.check_session_activity_entry("Triaged decision: Safe to vaccinate")
151+
sessions_page.check_session_activity_entry(
158152
f"Consent given by {child.parents[0].name_and_relationship}"
159153
)
160154

@@ -179,27 +173,21 @@ def test_conflicting_consent_with_gillick_consent(
179173

180174
sessions_page.click_child(child)
181175
sessions_page.click_programme_tab(Programme.HPV)
182-
sessions_page.expect_main_to_contain_text("Conflicting consent")
183-
sessions_page.expect_main_to_contain_text(
184-
"You can only vaccinate if all respondents give consent."
185-
)
176+
sessions_page.expect_consent_status(Programme.HPV, "Conflicting consent")
177+
sessions_page.expect_conflicting_consent_text()
186178
sessions_page.click_assess_gillick_competence()
187-
sessions_page.add_gillick_competence(
188-
is_competent=True, competence_details="Gillick competent"
189-
)
190-
sessions_page.expect_main_to_contain_text("HPV: Safe to vaccinate")
179+
sessions_page.add_gillick_competence(is_competent=True)
180+
sessions_page.expect_consent_status(Programme.HPV, "Safe to vaccinate")
191181
sessions_page.click_record_a_new_consent_response()
192182
consent_page.child_consent_verbal_positive()
193-
sessions_page.expect_main_to_contain_text(f"Consent recorded for {str(child)}")
183+
sessions_page.expect_alert_text(f"Consent recorded for {str(child)}")
194184
sessions_page.select_consent_given()
195185
sessions_page.click_child(child)
196186
sessions_page.click_programme_tab(Programme.HPV)
197-
sessions_page.expect_main_to_contain_text("HPV: Safe to vaccinate")
198-
sessions_page.expect_main_to_contain_text(
199-
f"NURSE, Nurse decided that {str(child)} is safe to vaccinate."
200-
)
201-
sessions_page.expect_main_to_contain_text("Consent given")
187+
sessions_page.expect_consent_status(Programme.HPV, "Safe to vaccinate")
188+
sessions_page.expect_child_safe_to_vaccinate(child)
189+
sessions_page.expect_consent_status(Programme.HPV, "Consent given")
202190
sessions_page.click_session_activity_and_notes()
203-
sessions_page.expect_main_to_contain_text(
191+
sessions_page.check_session_activity_entry(
204192
f"Consent given by {str(child)} (Child (Gillick competent))"
205193
)

0 commit comments

Comments
 (0)