diff --git a/apps/meteor/tests/e2e/omnichannel-transfer-to-another-agents.spec.ts b/apps/meteor/tests/e2e/omnichannel-transfer-to-another-agents.spec.ts index 72848a1914f14..04dae33db71be 100644 --- a/apps/meteor/tests/e2e/omnichannel-transfer-to-another-agents.spec.ts +++ b/apps/meteor/tests/e2e/omnichannel-transfer-to-another-agents.spec.ts @@ -8,58 +8,69 @@ const createAuxContext = async (browser: Browser, storageState: string): Promise const page = await browser.newPage({ storageState }); const poHomeChannel = new HomeChannel(page); await page.goto('/'); + await page.locator('.main-content').waitFor(); + return { page, poHomeChannel }; }; -test.describe('omnichannel-departaments', () => { +test.describe('omnichannel-departments', () => { let poLiveChat: OmnichannelLiveChat; let newUser: { email: string; name: string }; - test.beforeAll(async ({ api }) => { + + let agent1: { page: Page; poHomeChannel: HomeChannel }; + let agent2: { page: Page; poHomeChannel: HomeChannel }; + test.beforeAll(async ({ api, browser }) => { newUser = { name: faker.name.firstName(), email: faker.internet.email(), }; + + // Set user user 1 as manager and agent await api.post('/livechat/users/agent', { username: 'user1' }); await api.post('/livechat/users/manager', { username: 'user1' }); + agent1 = await createAuxContext(browser, 'user1-session.json'); + }); + test.beforeEach(async ({ page }) => { + poLiveChat = new OmnichannelLiveChat(page); }); - test.describe('Receiving message from user', () => { - let auxContext1: { page: Page; poHomeChannel: HomeChannel }; - test.beforeEach(async ({ browser, api, page }) => { - await api.post('/livechat/users/agent', { username: 'user2' }); - auxContext1 = await createAuxContext(browser, 'user1-session.json'); + test.afterAll(async ({ api }) => { + await api.delete('/livechat/users/agent/user1'); + await api.delete('/livechat/users/manager/user1'); + + await api.delete('/livechat/users/agent/user2'); + }); + + test('Receiving a message from visitor', async ({ browser, api, page }) => { + await test.step('Expect send a message as a visitor', async () => { await page.goto('/livechat'); - poLiveChat = new OmnichannelLiveChat(page); await poLiveChat.btnOpenLiveChat('R').click(); await poLiveChat.sendMessage(newUser, false); - - await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_user'); + await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor'); await poLiveChat.btnSendMessageToOnlineAgent.click(); + // Set user user 2 as agent }); - test('transfer chat to another agent', async ({ browser }) => { - const auxContext2 = await createAuxContext(browser, 'user2-session.json'); - - await auxContext1.poHomeChannel.sidenav.openChat(newUser.name); - await auxContext1.poHomeChannel.content.btnForwardChat.click(); - await auxContext1.poHomeChannel.content.inputModalAgentUserName.type('user2'); - await auxContext1.page.locator('.rcx-option .rcx-option__wrapper >> text="user2"').click(); - await auxContext1.poHomeChannel.content.inputModalAgentForwardComment.type('any_comment'); - await auxContext1.poHomeChannel.content.btnModalConfirm.click(); + await test.step('Expect to have 1 omnichannel assigned to agent 1', async () => { + await agent1.poHomeChannel.sidenav.openChat(newUser.name); + }); - await expect(auxContext1.poHomeChannel.toastSuccess).toBeVisible(); - await auxContext1.page.close(); - await auxContext2.page.close(); + await test.step('Expect to connect as agent 2', async () => { + agent2 = await createAuxContext(browser, 'user2-session.json'); + // TODO: We cannot assign a user as agent before, because now the agent can be assigned even offline, since we dont have endpoint to turn agent offline I'm doing this :x + await api.post('/livechat/users/agent', { username: 'user2' }); + }); + await test.step('Expect to be able to transfer an omnichannel to conversation to agent 2 as agent 1', async () => { + await agent1.poHomeChannel.content.btnForwardChat.click(); + await agent1.poHomeChannel.content.inputModalAgentUserName.type('user2'); + await agent1.page.locator('.rcx-option .rcx-option__wrapper >> text="user2"').click(); + await agent1.poHomeChannel.content.inputModalAgentForwardComment.type('any_comment'); + await agent1.poHomeChannel.content.btnModalConfirm.click(); + await expect(agent1.poHomeChannel.toastSuccess).toBeVisible(); }); - }); - test.describe('verify if chat is transfer', async () => { - test.use({ storageState: 'user2-session.json' }); - test('verify is chat is transfered', async ({ page }) => { - await page.goto('/'); - const poHomeChannel = new HomeChannel(page); - await poHomeChannel.sidenav.openChat(newUser.name); - await expect(page.locator(`[data-qa="sidebar-item-title"] >> text="${newUser.name}"`)).toBeVisible(); + await test.step('Expect to have 1 omnichannel assigned to agent 2', async () => { + await agent2.poHomeChannel.sidenav.openChat(newUser.name); }); }); });