Skip to content

Commit a021c54

Browse files
authored
Merge pull request #557 from NHSDigital/remove-main-text-expectations
Remove main text expectations
2 parents 0b31deb + 280a16e commit a021c54

File tree

11 files changed

+121
-89
lines changed

11 files changed

+121
-89
lines changed

mavis/test/pages/children.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ def fill_nhs_no_for_child(self, child: Child, nhs_no: str) -> None:
167167
def click_invite_to_community_clinic(self) -> None:
168168
self.invite_to_community_clinic_button.click()
169169

170-
def expect_text_in_main(self, text: str) -> None:
171-
expect(self.page.get_by_role("main")).to_contain_text(text)
170+
def expect_vaccination_details(self, key: str, value: str) -> None:
171+
detail_key = self.page.locator(".nhsuk-summary-list__key", has_text=key)
172+
detail_value = detail_key.locator("xpath=following-sibling::*[1]")
172173

173-
def expect_text_in_heading(self, text: str) -> None:
174-
expect(self.page.get_by_role("heading")).to_contain_text(text)
174+
expect(detail_value).to_contain_text(value)
175175

176176
def expect_text_in_alert(self, text: str) -> None:
177177
expect(self.page.get_by_role("alert")).to_contain_text(text)
@@ -214,12 +214,18 @@ def verify_activity_log_for_created_or_matched_child(
214214

215215
self.click_record_for_child(child)
216216
self.click_activity_log()
217-
self.expect_text_in_main("Consent given")
218-
self.expect_text_in_main(f"Added to the session at {location}")
217+
self.expect_activity_log_header("Consent given")
218+
self.expect_activity_log_header(f"Added to the session at {location}", any=True)
219219

220220
# FIXME: Update this text when MAVIS-1896/MAV-253 is closed
221221
self.check_log_updates_with_match()
222222

223+
def expect_activity_log_header(self, header: str, any: bool = False):
224+
if any:
225+
expect(self.page.get_by_role("heading", name=header).first).to_be_visible()
226+
else:
227+
expect(self.page.get_by_role("heading", name=header)).to_be_visible()
228+
223229
def archive_child_record(self):
224230
self.click_archive_child_record()
225231
self.click_imported_in_error()

mavis/test/pages/consent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,12 @@ def select_consent_not_given_reason(
362362

363363
self.click_continue()
364364

365-
def expect_text_in_main(self, text: str) -> None:
366-
expect(self.page.get_by_role("main")).to_contain_text(text)
365+
def expect_text_in_alert(self, text: str) -> None:
366+
expect(self.page.get_by_role("alert")).to_contain_text(text)
367+
368+
def expect_confirmation_text(self, text: str) -> None:
369+
confirmation = self.page.locator(".nhsuk-panel.nhsuk-panel--confirmation")
370+
expect(confirmation).to_contain_text(text)
367371

368372
def change_parent_phone(self):
369373
self.fill_phone_number_and_receive_text_alerts("7700900000")
@@ -421,7 +425,7 @@ def parent_written_positive(
421425
def update_triage_outcome_positive(self):
422426
self.click_safe_to_vaccinate()
423427
self.click_save_triage()
424-
expect(self.page.get_by_role("main")).to_contain_text("Triage outcome updated")
428+
self.expect_text_in_alert("Triage outcome updated")
425429

426430
def parent_phone_positive(
427431
self, parent: Parent, consent_option: ConsentOption = ConsentOption.INJECTION
@@ -555,4 +559,4 @@ def programme_display(programme, consent_option) -> str:
555559
body = f"{child.first_name} {child.last_name} is due to get the {programmes_str} vaccination{'s' if len(programmes) > 1 else ''} at school"
556560

557561
final_message = "".join([title, body])
558-
self.expect_text_in_main(final_message)
562+
self.expect_confirmation_text(final_message)

mavis/test/pages/programmes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def click_use_duplicate(self):
122122
def click_resolve_duplicate(self):
123123
self.resolve_duplicate_button.click()
124124

125+
def expect_alert_text(self, text: str):
126+
expect(self.page.get_by_role("alert")).to_contain_text(text)
127+
125128
@step("Click on Download vaccination report")
126129
def click_download_report(self):
127130
self.download_report_button.click()
@@ -170,9 +173,3 @@ def _download_and_verify_report_headers(self, expected_headers: str):
170173
assert False, (
171174
f"The following expected field(s) were not found in the report: {_e_not_a}. Report contains extra field(s), which were not expected: {_a_not_e}."
172175
)
173-
174-
def expect_text(self, text: str):
175-
expect(self.page.get_by_role("main")).to_contain_text(text)
176-
177-
def expect_to_not_see_text(self, text: str):
178-
expect(self.page.get_by_role("main")).not_to_contain_text(text)

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_children.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def test_details_mav_853(setup_mav_853, children_page, schools, children):
131131
children_page.click_record_for_child(child)
132132
# Verify activity log
133133
children_page.click_activity_log()
134-
children_page.expect_text_in_main("Vaccinated with Gardasil 9")
134+
children_page.expect_activity_log_header("Vaccinated with Gardasil 9")
135135
# Verify vaccination record
136136
children_page.click_child_record()
137137
children_page.click_vaccination_details(school)
138-
children_page.expect_text_in_main("OutcomeVaccinated")
138+
children_page.expect_vaccination_details("Outcome", "Vaccinated")
139139

140140

141141
@pytest.mark.bug
@@ -148,7 +148,7 @@ def test_change_nhsno(setup_change_nhsno, children_page, children):
148148
children_page.click_change_nhs_no()
149149
children_page.fill_nhs_no_for_child(child, "9123456789")
150150
children_page.click_continue()
151-
children_page.expect_text_in_main("Enter a valid NHS number")
151+
children_page.expect_text_in_alert("Enter a valid NHS number")
152152

153153

154154
@pytest.mark.children

tests/test_import_records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_vaccs_historic_no_urn_mav_855(
349349
children_page.search_with_all_filters_for_child_name(str(child))
350350
children_page.click_record_for_child(child)
351351
children_page.click_vaccination_details(school)
352-
children_page.expect_text_in_main(str(school))
352+
children_page.expect_vaccination_details("Location", str(school))
353353

354354

355355
@pytest.mark.vaccinations

tests/test_online_consent_doubles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_refused(consent_page, schools, children):
2929
details="Vaccine already received in previous school",
3030
)
3131
consent_page.click_confirm()
32-
consent_page.expect_text_in_main(
32+
consent_page.expect_confirmation_text(
3333
f"Consent refusedYou’ve told us that you do not want {child.first_name} {child.last_name} to get the MenACWY and Td/IPV vaccinations at school"
3434
)
3535

tests/test_online_consent_flu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_refused(start_consent, consent_page, schools, children):
5252
details="Vaccine already received in previous school",
5353
)
5454
consent_page.click_confirm()
55-
consent_page.expect_text_in_main(
55+
consent_page.expect_confirmation_text(
5656
f"Consent refusedYou’ve told us that you do not want {child.first_name} {child.last_name} to get the flu vaccination at school"
5757
)
5858

tests/test_online_consent_hpv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_refused(consent_page, schools, children):
2727
details="Vaccine already received in previous school",
2828
)
2929
consent_page.click_confirm()
30-
consent_page.expect_text_in_main(
30+
consent_page.expect_confirmation_text(
3131
f"Consent refusedYou’ve told us that you do not want {child.first_name} {child.last_name} to get the HPV vaccination at school"
3232
)
3333

tests/test_programmes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ def test_rav_triage_consent_refused(
251251
sessions_page.navigate_to_consent_response(child, Programme.HPV)
252252

253253
consent_page.parent_paper_refuse_consent(child.parents[0])
254-
consent_page.expect_text_in_main(str(child))
254+
consent_page.expect_text_in_alert(str(child))
255255

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

@@ -278,7 +278,7 @@ def test_rav_edit_dose_to_not_given(
278278
programmes_page.click_they_refused_it()
279279
programmes_page.click_continue()
280280
programmes_page.click_save_changes()
281-
programmes_page.expect_to_not_see_text("Sorry, there’s a problem with the service")
281+
programmes_page.expect_alert_text("Vaccination outcome recorded for HPV")
282282

283283

284284
@pytest.mark.rav
@@ -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)

0 commit comments

Comments
 (0)