@@ -103,55 +103,69 @@ export function verifyConsultTransferredLogs(): void {
103103}
104104
105105/**
106- * Utility function to get all captured logs for debugging purposes.
107- * @returns Array of all captured log messages
108- */
109- export function getAllCapturedLogs ( ) : string [ ] {
110- return [ ...capturedAdvancedLogs ] ;
111- }
112-
113- /**
114- * Initiates a consult with another agent via the agents tab.
106+ * Unified function to handle consult and transfer actions for agent, queue, and dial number.
115107 * @param page - The agent's main page
116- * @param agentName - Name of the agent to consult with (e.g., 'User1 Agent1')
108+ * @param type - 'agent' | 'queue' | 'dialNumber'
109+ * @param action - 'consult' | 'transfer'
110+ * @param value - agentName, queueName, or phoneNumber
117111 * @returns Promise<void>
118112 */
119- export async function consultViaAgent ( page : Page , agentName : string ) : Promise < void > {
120- // Click consult with another agent button
121- await page . getByTestId ( 'call-control:consult' ) . nth ( 1 ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
122- // Navigate to Agents tab
123- await page . getByRole ( 'tab' , { name : 'Agents' } ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
124-
125- //hover over the agent name - use exact match to avoid confusion with similar names
126- await page . getByRole ( 'listitem' , { name : agentName , exact : true } ) . hover ( { timeout : FORM_FIELD_TIMEOUT } ) ;
127-
128- // Select the specific agent
129- await page . getByRole ( 'listitem' , { name : agentName , exact : true } ) . getByRole ( 'button' ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
130-
131- // Wait a moment for the consult to be initiated
132- await page . waitForTimeout ( 2000 ) ;
133- }
134-
135- /**
136- * Initiates a consult with a queue via the queues tab.
137- * @param page - The agent's main page
138- * @param queueName - Name of the queue to consult with (e.g., 'Customer Service Queue')
139- * @returns Promise<void>
140- */
141- export async function consultViaQueue ( page : Page , queueName : string ) : Promise < void > {
142- // Click consult with another agent button
143- await page . getByTestId ( 'call-control:consult' ) . nth ( 1 ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
144-
145- // Navigate to Queues tab
146- await page . getByRole ( 'tab' , { name : 'Queues' } ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
147-
148- // Hover over the queue name - use exact match to avoid confusion with similar names
149- await page . getByRole ( 'listitem' , { name : queueName , exact : true } ) . hover ( { timeout : AWAIT_TIMEOUT } ) ;
113+ export async function consultOrTransfer (
114+ page : Page ,
115+ type : 'agent' | 'queue' | 'dialNumber' ,
116+ action : 'consult' | 'transfer' ,
117+ value : string
118+ ) : Promise < void > {
119+ // Determine which button to click for consult or transfer
120+ if ( action === 'consult' ) {
121+ await page . getByTestId ( 'call-control:consult' ) . nth ( 1 ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
122+ } else {
123+ await page
124+ . getByRole ( 'group' , { name : 'Call Control with Call' } )
125+ . getByLabel ( 'Transfer Call' )
126+ . click ( { timeout : AWAIT_TIMEOUT } ) ;
127+ }
150128
151- // Select the specific queue
152- await page . getByRole ( 'listitem' , { name : queueName , exact : true } ) . getByRole ( 'button' ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
129+ // Navigate to the correct tab and perform the action
130+ if ( type === 'agent' || type === 'queue' ) {
131+ const tabName = type === 'agent' ? 'Agents' : 'Queues' ;
132+ await page . getByRole ( 'tab' , { name : tabName } ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
133+ const listItem = page . getByRole ( 'listitem' , { name : value , exact : true } ) ;
134+ await listItem . waitFor ( { state : 'visible' , timeout : AWAIT_TIMEOUT } ) ;
135+ await listItem . scrollIntoViewIfNeeded ( ) ;
136+ await page . waitForTimeout ( 300 ) ;
137+ const button = listItem . getByRole ( 'button' ) ;
138+ await button . waitFor ( { state : 'visible' , timeout : AWAIT_TIMEOUT } ) ;
139+ await button . scrollIntoViewIfNeeded ( ) ;
140+ await button . evaluate ( ( el ) => {
141+ if ( el . hasAttribute ( 'disabled' ) ) {
142+ throw new Error ( `${ tabName . slice ( 0 , - 1 ) } button is disabled` ) ;
143+ }
144+ } ) ;
145+ let lastError ;
146+ for ( let i = 0 ; i < 3 ; i ++ ) {
147+ try {
148+ await button . click ( { timeout : AWAIT_TIMEOUT , force : true } ) ;
149+ lastError = undefined ;
150+ break ;
151+ } catch ( e ) {
152+ lastError = e ;
153+ await page . waitForTimeout ( 400 ) ;
154+ }
155+ }
156+ if ( lastError ) {
157+ throw lastError ;
158+ }
159+ } else if ( type === 'dialNumber' ) {
160+ await page . getByRole ( 'tab' , { name : 'Dial Number' } ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
161+ const inputLocator = page . getByTestId ( 'consult-transfer-dial-number-input' ) . locator ( 'input' ) ;
162+ await inputLocator . waitFor ( { state : 'visible' , timeout : AWAIT_TIMEOUT } ) ;
163+ await inputLocator . click ( { timeout : AWAIT_TIMEOUT } ) ;
164+ await inputLocator . fill ( value , { timeout : AWAIT_TIMEOUT } ) ;
165+ await page . getByTestId ( 'dial-number-btn' ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
166+ }
153167
154- // Wait a moment for the consult to be initiated
168+ // Wait a moment for the action to be processed
155169 await page . waitForTimeout ( 2000 ) ;
156170}
157171
@@ -164,58 +178,3 @@ export async function cancelConsult(page: Page): Promise<void> {
164178 // Click cancel consult button
165179 await page . getByTestId ( 'cancel-consult-btn' ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
166180}
167-
168- /**
169- * Initiates a transfer via the agents tab (without prior consult).
170- * @param page - The agent's main page
171- * @param agentName - Name of the agent to transfer to (e.g., 'User1 Agent1')
172- * @returns Promise<void>
173- */
174- export async function transferViaAgent ( page : Page , agentName : string ) : Promise < void > {
175- // Click transfer call button
176- await page
177- . getByRole ( 'group' , { name : 'Call Control with Call' } )
178- . getByLabel ( 'Transfer Call' )
179- . click ( { timeout : AWAIT_TIMEOUT } ) ;
180-
181- // Navigate to Agents tab
182- await page . getByRole ( 'tab' , { name : 'Agents' } ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
183-
184- // Hover over the agent name - use exact match to avoid confusion with similar names
185- await page . getByRole ( 'listitem' , { name : agentName , exact : true } ) . hover ( { timeout : FORM_FIELD_TIMEOUT } ) ;
186-
187- // Select the specific agent
188- await page
189- . getByRole ( 'listitem' , { name : agentName , exact : true } )
190- . getByRole ( 'button' )
191- . click ( { timeout : FORM_FIELD_TIMEOUT } ) ;
192-
193- // Wait a moment for the transfer to be processed
194- await page . waitForTimeout ( 2000 ) ;
195- }
196-
197- /**
198- * Initiates a transfer via the queues tab (without prior consult).
199- * @param page - The agent's main page
200- * @param queueName - Name of the queue to transfer to (e.g., 'Customer Service Queue')
201- * @returns Promise<void>
202- */
203- export async function transferViaQueue ( page : Page , queueName : string ) : Promise < void > {
204- // Click transfer call button
205- await page
206- . getByRole ( 'group' , { name : 'Call Control with Call' } )
207- . getByLabel ( 'Transfer Call' )
208- . click ( { timeout : AWAIT_TIMEOUT } ) ;
209-
210- // Navigate to Queues tab
211- await page . getByRole ( 'tab' , { name : 'Queues' } ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
212-
213- // Hover over the queue name - use exact match to avoid confusion with similar names
214- await page . getByRole ( 'listitem' , { name : queueName , exact : true } ) . hover ( { timeout : AWAIT_TIMEOUT } ) ;
215-
216- // Select the specific queue
217- await page . getByRole ( 'listitem' , { name : queueName , exact : true } ) . getByRole ( 'button' ) . click ( { timeout : AWAIT_TIMEOUT } ) ;
218-
219- // Wait a moment for the transfer to be processed
220- await page . waitForTimeout ( 2000 ) ;
221- }
0 commit comments