|
| 1 | +import { Page, test, expect, BrowserContext } from "@playwright/test"; |
| 2 | +import { |
| 3 | + consultViaAgent, |
| 4 | + transferViaAgent, |
| 5 | + cancelConsult, |
| 6 | +} from './Utils/advancedTaskControlUtils'; |
| 7 | +import { changeUserState, getCurrentState, verifyCurrentState } from './Utils/userStateUtils'; |
| 8 | +import { |
| 9 | + createCallTask, |
| 10 | + acceptIncomingTask, |
| 11 | + loginExtension |
| 12 | +} from './Utils/incomingTaskUtils'; |
| 13 | +import { submitWrapup } from './Utils/wrapupUtils'; |
| 14 | +import { USER_STATES, LOGIN_MODE, TASK_TYPES, WRAPUP_REASONS } from './constants'; |
| 15 | +import { pageSetup, waitForState } from "./Utils/helperUtils"; |
| 16 | +import { endTask, holdCallToggle } from "./Utils/taskControlUtils"; |
| 17 | + |
| 18 | +let agent1Page: Page; |
| 19 | +let agent2Page: Page; |
| 20 | +let callerPage: Page; |
| 21 | +let agent1Context: BrowserContext; |
| 22 | +let agent2Context: BrowserContext; |
| 23 | +let callerContext: BrowserContext; |
| 24 | +const maxRetries = 3; |
| 25 | + |
| 26 | + |
| 27 | +test.describe("Advanced Combinations Tests ", () => { |
| 28 | + |
| 29 | + test.beforeAll(async ({ browser }) => { |
| 30 | + agent1Context = await browser.newContext(); |
| 31 | + agent2Context = await browser.newContext(); |
| 32 | + callerContext = await browser.newContext(); |
| 33 | + |
| 34 | + agent1Page = await agent1Context.newPage(); |
| 35 | + agent2Page = await agent2Context.newPage(); |
| 36 | + callerPage = await callerContext.newPage(); |
| 37 | + |
| 38 | + await Promise.all([ |
| 39 | + (async () => { |
| 40 | + for (let i = 0; i < maxRetries; i++) { |
| 41 | + try { |
| 42 | + await loginExtension(callerPage, process.env.PW_AGENT2_USERNAME ?? '', process.env.PW_PASSWORD ?? ''); |
| 43 | + break; |
| 44 | + } catch (error) { |
| 45 | + if (i == maxRetries - 1) { |
| 46 | + throw new Error(`Failed to login extension after ${maxRetries} attempts: ${error}`); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + })(), |
| 51 | + (async () => { |
| 52 | + await pageSetup(agent1Page, LOGIN_MODE.DESKTOP, 'AGENT1'); |
| 53 | + })(), |
| 54 | + (async () => { |
| 55 | + await pageSetup(agent2Page, LOGIN_MODE.DESKTOP, 'AGENT2'); |
| 56 | + })(), |
| 57 | + ]); |
| 58 | + }); |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + test('Transfer from one agent to another, then transfer back to the first agent', async () => { |
| 63 | + await changeUserState(agent2Page, USER_STATES.MEETING); |
| 64 | + await changeUserState(agent1Page, USER_STATES.AVAILABLE); |
| 65 | + await createCallTask(callerPage, process.env.PW_DIAL_NUMBER); |
| 66 | + let incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 67 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 40000 }); |
| 68 | + await agent1Page.waitForTimeout(2000); |
| 69 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 70 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 71 | + await changeUserState(agent2Page, USER_STATES.AVAILABLE); |
| 72 | + await agent1Page.waitForTimeout(2000); |
| 73 | + await waitForState(agent2Page, USER_STATES.AVAILABLE); |
| 74 | + await transferViaAgent(agent1Page, 'User2 Agent2'); |
| 75 | + incomingTaskDiv = agent2Page.getByTestId('samples:incoming-task-telephony').first(); |
| 76 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 20000 }); |
| 77 | + await agent2Page.waitForTimeout(2000); |
| 78 | + await acceptIncomingTask(agent2Page, TASK_TYPES.CALL); |
| 79 | + await waitForState(agent2Page, USER_STATES.ENGAGED); |
| 80 | + await agent1Page.waitForTimeout(2000); |
| 81 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 82 | + await agent1Page.waitForTimeout(2000); |
| 83 | + await transferViaAgent(agent2Page, 'User1 Agent1'); |
| 84 | + incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 85 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 20000 }); |
| 86 | + await agent1Page.waitForTimeout(2000); |
| 87 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 88 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 89 | + await verifyCurrentState(agent1Page, USER_STATES.ENGAGED); |
| 90 | + await agent1Page.waitForTimeout(2000); |
| 91 | + await submitWrapup(agent2Page, WRAPUP_REASONS.SALE); |
| 92 | + await agent1Page.getByTestId('call-control:end-call').first().click(); |
| 93 | + await agent1Page.waitForTimeout(3000); |
| 94 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 95 | + }); |
| 96 | + |
| 97 | + test('Consult with another agent and transfer the call, do it again from the other agent', async () => { |
| 98 | + await changeUserState(agent1Page, USER_STATES.AVAILABLE); |
| 99 | + await changeUserState(agent2Page, USER_STATES.MEETING); |
| 100 | + await createCallTask(callerPage); |
| 101 | + let incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 102 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 40000 }); |
| 103 | + await agent1Page.waitForTimeout(2000); |
| 104 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 105 | + await changeUserState(agent2Page, USER_STATES.AVAILABLE); |
| 106 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 107 | + await waitForState(agent2Page, USER_STATES.AVAILABLE); |
| 108 | + await consultViaAgent(agent1Page, 'User2 Agent2'); |
| 109 | + incomingTaskDiv = agent2Page.getByTestId('samples:incoming-task-telephony').first(); |
| 110 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 20000 }); |
| 111 | + await agent2Page.waitForTimeout(2000); |
| 112 | + await acceptIncomingTask(agent2Page, TASK_TYPES.CALL); |
| 113 | + await waitForState(agent2Page, USER_STATES.ENGAGED); |
| 114 | + await agent1Page.getByTestId('transfer-consult-btn').click(); |
| 115 | + await agent1Page.waitForTimeout(3000); |
| 116 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 117 | + await waitForState(agent1Page, USER_STATES.AVAILABLE); |
| 118 | + await consultViaAgent(agent2Page, 'User1 Agent1'); |
| 119 | + await agent1Page.getByTestId('samples:incoming-task-telephony').first().waitFor({ state: 'visible', timeout: 20000 }); |
| 120 | + await agent1Page.waitForTimeout(2000); |
| 121 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 122 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 123 | + await agent2Page.getByTestId('transfer-consult-btn').click(); |
| 124 | + await agent2Page.waitForTimeout(3000); |
| 125 | + await submitWrapup(agent2Page, WRAPUP_REASONS.SALE); |
| 126 | + await waitForState(agent2Page, USER_STATES.AVAILABLE); |
| 127 | + await agent1Page.getByTestId('call-control:end-call').first().click(); |
| 128 | + await agent1Page.waitForTimeout(2000); |
| 129 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 130 | + await agent1Page.waitForTimeout(2000); |
| 131 | + }) |
| 132 | + |
| 133 | + test('Consult with another agent, transfer the call and transfer the call back to the agent', async () => { |
| 134 | + await changeUserState(agent1Page, USER_STATES.AVAILABLE); |
| 135 | + await changeUserState(agent2Page, USER_STATES.MEETING); |
| 136 | + await createCallTask(callerPage); |
| 137 | + let incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 138 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 40000 }); |
| 139 | + await agent1Page.waitForTimeout(2000); |
| 140 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 141 | + await changeUserState(agent2Page, USER_STATES.AVAILABLE); |
| 142 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 143 | + await waitForState(agent2Page, USER_STATES.AVAILABLE); |
| 144 | + await consultViaAgent(agent1Page, 'User2 Agent2'); |
| 145 | + incomingTaskDiv = agent2Page.getByTestId('samples:incoming-task-telephony').first(); |
| 146 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 20000 }); |
| 147 | + await agent2Page.waitForTimeout(2000); |
| 148 | + await acceptIncomingTask(agent2Page, TASK_TYPES.CALL); |
| 149 | + await waitForState(agent2Page, USER_STATES.ENGAGED); |
| 150 | + await agent1Page.getByTestId('transfer-consult-btn').click(); |
| 151 | + await agent1Page.waitForTimeout(2000); |
| 152 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 153 | + await waitForState(agent1Page, USER_STATES.AVAILABLE); |
| 154 | + |
| 155 | + await transferViaAgent(agent2Page, 'User1 Agent1'); |
| 156 | + incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 157 | + await incomingTaskDiv.waitFor({ |
| 158 | + state: 'visible', timeout: 20000 |
| 159 | + }); |
| 160 | + await agent1Page.waitForTimeout(2000); |
| 161 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 162 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 163 | + await agent2Page.waitForTimeout(2000); |
| 164 | + await submitWrapup(agent2Page, WRAPUP_REASONS.SALE); |
| 165 | + await waitForState(agent2Page, USER_STATES.AVAILABLE); |
| 166 | + await agent1Page.getByTestId('call-control:end-call').first().click(); |
| 167 | + await agent1Page.waitForTimeout(2000); |
| 168 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 169 | + await agent1Page.waitForTimeout(2000); |
| 170 | + }) |
| 171 | + |
| 172 | + |
| 173 | + test('Transfer the call to another agent & then consult from the other agent', async () => { |
| 174 | + await changeUserState(agent2Page, USER_STATES.MEETING); |
| 175 | + await changeUserState(agent1Page, USER_STATES.AVAILABLE); |
| 176 | + await createCallTask(callerPage, process.env.PW_DIAL_NUMBER); |
| 177 | + let incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 178 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 40000 }); |
| 179 | + await agent1Page.waitForTimeout(2000); |
| 180 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 181 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 182 | + await changeUserState(agent2Page, USER_STATES.AVAILABLE); |
| 183 | + await agent1Page.waitForTimeout(2000); |
| 184 | + await transferViaAgent(agent1Page, 'User2 Agent2'); |
| 185 | + await agent2Page.getByTestId('samples:incoming-task-telephony').first().waitFor({ state: 'visible', timeout: 20000 }); |
| 186 | + await agent2Page.waitForTimeout(2000); |
| 187 | + await acceptIncomingTask(agent2Page, TASK_TYPES.CALL); |
| 188 | + await waitForState(agent2Page, USER_STATES.ENGAGED); |
| 189 | + await agent1Page.waitForTimeout(2000); |
| 190 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 191 | + await waitForState(agent1Page, USER_STATES.AVAILABLE); |
| 192 | + await consultViaAgent(agent2Page, 'User1 Agent1'); |
| 193 | + incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 194 | + await incomingTaskDiv.waitFor({ |
| 195 | + state: 'visible', timeout: 20000 |
| 196 | + }); |
| 197 | + await agent1Page.waitForTimeout(2000); |
| 198 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 199 | + await waitForState(agent1Page, USER_STATES.ENGAGED); |
| 200 | + await agent2Page.getByTestId('transfer-consult-btn').click(); |
| 201 | + await agent2Page.waitForTimeout(2000); |
| 202 | + await submitWrapup(agent2Page, WRAPUP_REASONS.SALE); |
| 203 | + await waitForState(agent2Page, USER_STATES.AVAILABLE); |
| 204 | + await agent1Page.getByTestId('call-control:end-call').first().click(); |
| 205 | + await agent1Page.waitForTimeout(2000); |
| 206 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 207 | + await agent1Page.waitForTimeout(2000); |
| 208 | + }); |
| 209 | + |
| 210 | + test('Multi-Stage Consult and Transfer Between A1 and A2', async () => { |
| 211 | + await changeUserState(agent2Page, USER_STATES.MEETING); |
| 212 | + await createCallTask(callerPage); |
| 213 | + const incomingTaskDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 214 | + await incomingTaskDiv.waitFor({ state: 'visible', timeout: 120000 }); |
| 215 | + await agent1Page.waitForTimeout(3000); |
| 216 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 217 | + await changeUserState(agent2Page, USER_STATES.AVAILABLE); |
| 218 | + await agent1Page.waitForTimeout(5000); |
| 219 | + await verifyCurrentState(agent1Page, USER_STATES.ENGAGED); |
| 220 | + await consultViaAgent(agent1Page, 'User2 Agent2'); |
| 221 | + const consultRequestDiv = agent2Page.getByTestId('samples:incoming-task-telephony').first(); |
| 222 | + await consultRequestDiv.waitFor({ state: 'visible', timeout: 60000 }); |
| 223 | + await agent2Page.waitForTimeout(3000); |
| 224 | + await acceptIncomingTask(agent2Page, TASK_TYPES.CALL); |
| 225 | + await agent2Page.waitForTimeout(3000); |
| 226 | + await verifyCurrentState(agent2Page, USER_STATES.ENGAGED); |
| 227 | + await agent1Page.getByTestId('transfer-consult-btn').click(); |
| 228 | + await agent1Page.waitForTimeout(2000); |
| 229 | + await submitWrapup(agent1Page, WRAPUP_REASONS.SALE); |
| 230 | + await agent2Page.waitForTimeout(3000); |
| 231 | + await verifyCurrentState(agent2Page, USER_STATES.ENGAGED); |
| 232 | + await consultViaAgent(agent2Page, 'User1 Agent1'); |
| 233 | + const returnConsultDiv = agent1Page.getByTestId('samples:incoming-task-telephony').first(); |
| 234 | + await returnConsultDiv.waitFor({ state: 'visible', timeout: 60000 }); |
| 235 | + await agent1Page.waitForTimeout(3000); |
| 236 | + await acceptIncomingTask(agent1Page, TASK_TYPES.CALL); |
| 237 | + await agent1Page.waitForTimeout(3000); |
| 238 | + await agent2Page.getByTestId('transfer-consult-btn').click(); |
| 239 | + await agent2Page.waitForTimeout(2000); |
| 240 | + await submitWrapup(agent2Page, WRAPUP_REASONS.RESOLVED); |
| 241 | + await verifyCurrentState(agent1Page, USER_STATES.ENGAGED); |
| 242 | + await consultViaAgent(agent1Page, 'User2 Agent2'); |
| 243 | + await expect(agent1Page.getByTestId('cancel-consult-btn')).toBeVisible(); |
| 244 | + await expect(agent1Page.getByTestId('transfer-consult-btn')).toBeVisible(); |
| 245 | + await cancelConsult(agent1Page); |
| 246 | + await expect(agent1Page.getByRole('group', { name: 'Call Control with Call' })).toBeVisible(); |
| 247 | + await verifyCurrentState(agent1Page, USER_STATES.ENGAGED); |
| 248 | + await holdCallToggle(agent1Page); |
| 249 | + await endTask(agent1Page); |
| 250 | + await agent1Page.waitForTimeout(3000); |
| 251 | + await submitWrapup(agent1Page, WRAPUP_REASONS.RESOLVED); |
| 252 | + await agent1Page.waitForTimeout(2000); |
| 253 | + }); |
| 254 | + |
| 255 | +}); |
0 commit comments