1919)
2020from mavis .test .utils import (
2121 MAVIS_NOTE_LENGTH_LIMIT ,
22+ expect_alert_text ,
23+ expect_details ,
2224 get_current_datetime_compact ,
2325 get_day_month_year_from_compact_date ,
2426 get_offset_date ,
@@ -431,24 +433,26 @@ def create_invalid_session(self) -> None:
431433 self .add_or_change_session_dates ()
432434 self .fill_date_fields (_invalid_date )
433435 self .click_continue_button ()
434- self . expect_alert_text ("Enter a date" )
436+ expect_alert_text (self . page , "Enter a date" )
435437 self .click_back ()
436438
437439 def create_session_in_previous_academic_year (self ) -> None :
438440 _previous_year_date = get_offset_date_compact_format (offset_days = - 365 )
439441 self .add_or_change_session_dates ()
440442 self .fill_date_fields (_previous_year_date )
441443 self .click_continue_button ()
442- self .expect_alert_text ("Enter a date on or after the start of the school year" )
444+ expect_alert_text (
445+ self .page , "Enter a date on or after the start of the school year"
446+ )
443447 self .click_back ()
444448
445449 def create_session_in_next_academic_year (self ) -> None :
446450 _next_year_date = get_offset_date_compact_format (offset_days = 365 )
447451 self .add_or_change_session_dates ()
448452 self .fill_date_fields (_next_year_date )
449453 self .click_continue_button ()
450- self . expect_alert_text (
451- "Enter a date on or before the end of the current school year"
454+ expect_alert_text (
455+ self . page , "Enter a date on or before the end of the current school year"
452456 )
453457 self .click_back ()
454458
@@ -536,7 +540,8 @@ def schedule_a_valid_session(
536540 if self .keep_session_dates_button .is_visible ():
537541 self .click_keep_session_dates () # MAV-2066
538542
539- self .expect_details (
543+ expect_details (
544+ self .page ,
540545 "Session dates" ,
541546 self ._get_day_month_year_with_day_of_week (date_to_format = _future_date ),
542547 )
@@ -562,7 +567,8 @@ def schedule_a_valid_mmr_session(
562567 if self .keep_session_dates_button .is_visible ():
563568 self .click_keep_session_dates () # MAV-2066
564569
565- self .expect_details (
570+ expect_details (
571+ self .page ,
566572 "Session dates" ,
567573 self ._get_day_month_year_with_day_of_week (date_to_format = _future_date ),
568574 )
@@ -582,18 +588,6 @@ def answer_whether_psd_should_be_enabled(self, answer: str) -> None:
582588 ),
583589 ).get_by_label (answer ).check ()
584590
585- def expect_alert_text (self , text : str ) -> None :
586- expect (self .page .get_by_role ("alert" )).to_contain_text (text )
587-
588- def expect_details (self , key : str , value : str ) -> None :
589- detail_key = self .page .locator (
590- ".nhsuk-summary-list__key" ,
591- has_text = re .compile (f"^{ key } $" ),
592- ).first
593- detail_value = detail_key .locator ("xpath=following-sibling::*[1]" )
594-
595- expect (detail_value ).to_contain_text (value )
596-
597591
598592class SessionsChildrenPage (SearchBarMixin , SessionsTabsMixin ):
599593 def __init__ (self , page : Page ) -> None :
@@ -860,11 +854,11 @@ def invalidate_parent_refusal(self, parent: Parent) -> None:
860854 self .click_mark_as_invalid_link ()
861855 self .fill_notes (invalidation_notes )
862856 self .click_mark_as_invalid_button ()
863- self . expect_details ("Response" , "Invalid" )
864- self . expect_details ("Notes" , invalidation_notes )
857+ expect_details (self . page , "Response" , "Invalid" )
858+ expect_details (self . page , "Notes" , invalidation_notes )
865859
866860 self .click_back ()
867- self . expect_details ("Response" , "Invalid" )
861+ expect_details (self . page , "Response" , "Invalid" )
868862 expect (self .page .get_by_text ("No requests have been sent." )).to_be_visible ()
869863
870864 @step ("Click Back" )
@@ -879,15 +873,6 @@ def click_continue_button(self) -> None:
879873 def fill_notes (self , notes : str ) -> None :
880874 self .notes_textbox .fill (notes )
881875
882- def expect_details (self , key : str , value : str ) -> None :
883- detail_key = self .page .locator (
884- ".nhsuk-summary-list__key" ,
885- has_text = re .compile (f"^{ key } $" ),
886- ).first
887- detail_value = detail_key .locator ("xpath=following-sibling::*[1]" )
888-
889- expect (detail_value ).to_contain_text (value )
890-
891876 @step ("Click on Yes" )
892877 def select_identity_confirmed_by_child (self , child : Child ) -> None :
893878 self .page .get_by_role (
@@ -967,10 +952,7 @@ def go_back_to_session_for_school(self, school: School) -> None:
967952 expect (self .page .get_by_role ("heading" , name = school .name ).first ).to_be_visible ()
968953
969954 def verify_triage_updated_for_child (self ) -> None :
970- self .expect_alert_text ("Triage outcome updated" )
971-
972- def expect_alert_text (self , text : str ) -> None :
973- expect (self .page .get_by_role ("alert" )).to_contain_text (text )
955+ expect_alert_text (self .page , "Triage outcome updated" )
974956
975957 @step ("Triage MMR patient" )
976958 def triage_mmr_patient (self , consent_option : ConsentOption ) -> None :
@@ -1037,15 +1019,12 @@ def add_note(self, note: str) -> None:
10371019 with self .page .expect_navigation ():
10381020 self .click_save_note ()
10391021
1040- self . expect_alert_text ("Note added" )
1022+ expect_alert_text (self . page , "Note added" )
10411023 reload_until_element_is_visible (self .page , self .page .get_by_text (note ))
10421024
10431025 def check_session_activity_entry (self , text : str ) -> None :
10441026 expect (self .page .get_by_role ("heading" , name = text ).first ).to_be_visible ()
10451027
1046- def expect_alert_text (self , text : str ) -> None :
1047- expect (self .page .get_by_role ("alert" )).to_contain_text (text )
1048-
10491028
10501029class SessionsVaccinationWizardPage :
10511030 def __init__ (self , page : Page ) -> None :
@@ -1082,18 +1061,6 @@ def choose_batch(self, batch_name: str) -> None:
10821061 self .page .get_by_role ("radio" , name = batch_name ).check ()
10831062 self .click_continue_button ()
10841063
1085- def expect_details (self , key : str , value : str ) -> None :
1086- detail_key = self .page .locator (
1087- ".nhsuk-summary-list__key" ,
1088- has_text = re .compile (f"^{ key } $" ),
1089- ).first
1090- detail_value = detail_key .locator ("xpath=following-sibling::*[1]" )
1091-
1092- expect (detail_value ).to_contain_text (value )
1093-
1094- def expect_alert_text (self , text : str ) -> None :
1095- expect (self .page .get_by_role ("alert" )).to_contain_text (text )
1096-
10971064 def record_vaccination (
10981065 self ,
10991066 vaccination_record : VaccinationRecord ,
@@ -1106,9 +1073,9 @@ def record_vaccination(
11061073
11071074 if at_school : # only skips MAV-854
11081075 if psd_option :
1109- self . expect_details ("Protocol" , "Patient Specific Direction" )
1076+ expect_details (self . page , "Protocol" , "Patient Specific Direction" )
11101077 else :
1111- self . expect_details ("Protocol" , "Patient Group Direction (PGD)" )
1078+ expect_details (self . page , "Protocol" , "Patient Group Direction (PGD)" )
11121079
11131080 self .vaccination_notes .fill (notes )
11141081 self .click_confirm_button ()
@@ -1118,6 +1085,7 @@ def record_vaccination(
11181085 self .vaccination_notes .fill ("Confirmation notes" )
11191086 self .click_confirm_button ()
11201087
1121- self .expect_alert_text (
1122- f"Vaccination outcome recorded for { vaccination_record .programme } "
1088+ expect_alert_text (
1089+ self .page ,
1090+ f"Vaccination outcome recorded for { vaccination_record .programme } " ,
11231091 )
0 commit comments