11from playwright .sync_api import Page , expect
22from pages .base_page import BasePage
3+ from utils .table_util import TableUtils
34
45
56class LetterLibraryIndexPage (BasePage ):
@@ -8,8 +9,14 @@ class LetterLibraryIndexPage(BasePage):
89 def __init__ (self , page : Page ):
910 super ().__init__ (page )
1011 self .page = page
12+ self .table_utils = TableUtils (page , "#displayRS" )
1113 # Letter Library Index - page locators, methods
1214
15+ self .letter_library_index_table = page .locator ("#displayRS" )
16+ self .define_supplementary_letter_button = page .locator (
17+ "input.HeaderButtons[value='Define Supplementary Letter']"
18+ )
19+
1320 def verify_letter_library_index_title (self ) -> None :
1421 """Verify the Letter Library Index page title is displayed as expected"""
1522 self .bowel_cancer_screening_page_title_contains_text ("Letter Library Index" )
@@ -20,7 +27,22 @@ def filter_by_letters_group(self, group_name: str) -> None:
2027 Triggers the postback and waits for the page to update.
2128
2229 Args:
23- group_name (str): Visible label of the desired letter group (e.g., 'Supplementary Letters')
30+ group_name (str): Visible label of the desired letter group. Must be one of:
31+ - 'Discharge Letters (Patient)'
32+ - 'Discharge Letters (GP)'
33+ - 'Discharge Notification Cards To GP Practice'
34+ - '30 Day Questionnaire'
35+ - 'Surveillance Selection'
36+ - 'Invitation Letters'
37+ - 'MDT Referral Letter to GP'
38+ - 'Practitioner Clinic Letters'
39+ - 'Reminder Letters'
40+ - 'Result Letters (Patient)'
41+ - 'Result Communications (GP)'
42+ - 'Retest Letters'
43+ - 'Supplementary Letters'
44+ - 'Bowel Scope Hub Letters'
45+ - 'Genetic Service Letters'
2446 """
2547 dropdown = self .page .locator ("#selLetterType" )
2648 expect (dropdown ).to_be_visible ()
@@ -31,5 +53,68 @@ def filter_by_letters_group(self, group_name: str) -> None:
3153 # Wait for the page to reload—this form triggers a postback
3254 self .page .wait_for_load_state ("load" )
3355
34- # Optional: wait for something specific to confirm the filter applied
35- expect (self .page .locator ("text=" + group_name )).to_be_visible ()
56+ def filter_by_event_code (self , event_code : str ) -> None :
57+ """
58+ Filters the letter library index by event code using the textbox input.
59+
60+ Args:
61+ event_code (str): The event code to filter the list (e.g., 'S1')
62+ """
63+ event_code_input = self .page .get_by_role (
64+ "textbox" , name = "Enter text to filter the list"
65+ )
66+ expect (event_code_input ).to_be_visible ()
67+ event_code_input .click ()
68+ event_code_input .fill (event_code )
69+ event_code_input .press ("Enter" )
70+
71+ # Optional: wait for the filtered list to update
72+ self .page .wait_for_timeout (500 ) # tweak or replace with smart wait
73+
74+ def click_first_letter_code_link_in_table (self ) -> None :
75+ """Clicks the first link from the Letter Library Index table."""
76+ self .table_utils .click_first_link_in_column ("Code" )
77+
78+ def click_define_supplementary_letter_button (self ) -> None :
79+ """
80+ Clicks the 'Define Supplementary Letter' button
81+
82+ Raises:
83+ AssertionError: If the button is not visible or interactive
84+ """
85+ button = self .define_supplementary_letter_button
86+ expect (button ).to_be_visible ()
87+ button .click ()
88+
89+ def define_supplementary_letter (
90+ self ,
91+ description : str = "Define Letter" ,
92+ destination_id : str = "12057" ,
93+ priority_id : str = "12016" ,
94+ signatory : str = "signatory" ,
95+ job_title : str = "job title" ,
96+ paragraph_text : str = "body text"
97+ ) -> None :
98+ """
99+ Fills out the form to define a supplementary letter and confirms save via modal.
100+
101+ Args:
102+ description (str): Letter description
103+ destination_id (str): Dropdown option for destination
104+ priority_id (str): Dropdown option for priority
105+ signatory (str): Signatory name
106+ job_title (str): Signatory's job title
107+ paragraph_text (str): Main body text of the letter
108+ """
109+ self .page .locator ('input[name="A_C_LETT_DESC"]' ).fill (description )
110+ self .page .locator ("#A_C_DESTINATION_ID" ).select_option (destination_id )
111+ self .page .locator ("#A_C_PRIORITY_ID" ).select_option (priority_id )
112+ self .page .locator ("#A_C_SIGNATORY" ).fill (signatory )
113+ self .page .locator ("#A_C_JOB_TITLE" ).fill (job_title )
114+ self .page .locator ("#A_C_PARAGRAPH_1" ).fill (paragraph_text )
115+
116+ # Handle the modal popup when saving
117+ self .page .once ("dialog" , lambda dialog : dialog .accept ())
118+ self .page .get_by_role ("button" , name = "Save" ).click ()
119+
120+
0 commit comments