From 97532bd66459176f3c5597954d0a2789b89de934 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Mon, 1 Apr 2024 10:06:38 -0300 Subject: [PATCH 1/2] test(livechat): fix Department flaky test --- .../omnichannel-livechat-department.spec.ts | 45 ++++++++++++++++--- .../e2e/page-objects/omnichannel-livechat.ts | 18 +++----- .../src/components/Modal/component.js | 7 ++- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts b/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts index fe820a71f62c..51094587eba2 100644 --- a/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts +++ b/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts @@ -54,8 +54,8 @@ test.describe('OC - Livechat - Department Flow', () => { }); test.afterEach(async ({ page }) => { - await poHomeOmnichannelAgent1.page?.close(); - await poHomeOmnichannelAgent2.page?.close(); + await poHomeOmnichannelAgent1?.page?.close(); + await poHomeOmnichannelAgent2?.page?.close(); await page.close(); }); @@ -98,25 +98,58 @@ test.describe('OC - Livechat - Department Flow', () => { await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible(); }); + await test.step('expect message to be received by department 1', async () => { + await poHomeOmnichannelAgent1.sidenav.openChat(firstUser.name); + await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toBeVisible(); + await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toContainText('this_a_test_message_from_user'); + }); + + await test.step('expect message to be sent by department 1', async () => { + await poHomeOmnichannelAgent1.content.sendMessage('this_a_test_message_from_agent_department_1'); + await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_agent_department_1"')).toBeVisible(); + await poHomeOmnichannelAgent1.page.close(); + }); + await test.step('expect to change department', async () => { - await poLiveChat.changeDepartment(departmentB.name); + await poLiveChat.btnOptions.click(); + await poLiveChat.btnChangeDepartment.click(); + + await expect(poLiveChat.selectDepartment).toBeVisible(); + await poLiveChat.selectDepartment.selectOption({ label: departmentB.name }); + + await expect(poLiveChat.btnSendMessage('Start chat')).toBeEnabled(); + await poLiveChat.btnSendMessage('Start chat').click(); + + await expect(poLiveChat.livechatModal).toBeVisible(); + + await expect(poLiveChat.livechatModalText('Are you sure you want to switch the department?')).toBeVisible(); + await poLiveChat.btnYes.click(); + + await expect(poLiveChat.livechatModal).toBeVisible(); + + await expect(poLiveChat.livechatModalText('Department switched')).toBeVisible(); + await poLiveChat.btnOk.click(); // Expect keep chat history await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible(); // Expect user to have changed await expect(await poLiveChat.headerTitle.textContent()).toEqual(agent2.username); + + await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user_to_department_2'); + await poLiveChat.btnSendMessageToOnlineAgent.click(); + await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user_to_department_2"')).toBeVisible(); }); await test.step('expect message to be received by department', async () => { await poHomeOmnichannelAgent2.sidenav.openChat(firstUser.name); await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toBeVisible(); - await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toContainText('this_a_test_message_from_user'); + await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toContainText('this_a_test_message_from_user_to_department_2'); }); await test.step('expect message to be sent by department', async () => { - await poHomeOmnichannelAgent2.content.sendMessage('this_a_test_message_from_agent'); - await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_agent"')).toBeVisible(); + await poHomeOmnichannelAgent2.content.sendMessage('this_a_test_message_from_agent_department_2'); + await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_agent_department_2"')).toBeVisible(); }); }); }); diff --git a/apps/meteor/tests/e2e/page-objects/omnichannel-livechat.ts b/apps/meteor/tests/e2e/page-objects/omnichannel-livechat.ts index c372dd6d8572..f380fcf80d05 100644 --- a/apps/meteor/tests/e2e/page-objects/omnichannel-livechat.ts +++ b/apps/meteor/tests/e2e/page-objects/omnichannel-livechat.ts @@ -53,16 +53,6 @@ export class OmnichannelLiveChat { return this.page.locator(`text="${message}"`); } - async changeDepartment (department: string): Promise { - await this.btnOptions.click(); - await this.btnChangeDepartment.click(); - await this.selectDepartment.waitFor({ state: 'visible' }); - await this.selectDepartment.selectOption({ label: department }); - await this.btnSendMessage('Start chat').click(); - await this.btnYes.click(); - await this.btnOk.click(); - } - async closeChat(): Promise { await this.btnOptions.click(); await this.btnCloseChat.click(); @@ -126,8 +116,12 @@ export class OmnichannelLiveChat { return this.page.locator('footer div div div:nth-child(3) button'); } - get firstAutoMessage(): Locator { - return this.page.locator('div.message-text__WwYco p'); + get livechatModal(): Locator { + return this.page.locator('[data-qa-type="modal-overlay"]'); + } + + livechatModalText(text: string): Locator { + return this.page.locator(`[data-qa-type="modal-overlay"] >> text=${text}`); } public async sendMessage(liveChatUser: { name: string; email: string }, isOffline = true, department?: string): Promise { diff --git a/packages/livechat/src/components/Modal/component.js b/packages/livechat/src/components/Modal/component.js index 195d4598f217..16f0df40d8ea 100644 --- a/packages/livechat/src/components/Modal/component.js +++ b/packages/livechat/src/components/Modal/component.js @@ -48,7 +48,12 @@ export class Modal extends Component { render = ({ children, animated, open, ...props }) => open ? ( -
+
{children}
From d300dd4fedfcacf134c990669a7851fdbe026707 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Tue, 2 Apr 2024 17:33:49 -0300 Subject: [PATCH 2/2] Use different guests --- .../omnichannel-livechat-department.spec.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts b/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts index 51094587eba2..c0b2bf8ae852 100644 --- a/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts +++ b/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-department.spec.ts @@ -8,10 +8,7 @@ import { createAgent } from '../utils/omnichannel/agents'; import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments'; import { test, expect } from '../utils/test'; -const firstUser = { - name: `${faker.person.firstName()} ${faker.string.uuid()}}`, - email: faker.internet.email(), -}; + test.use({ storageState: Users.user1.state }); @@ -67,9 +64,15 @@ test.describe('OC - Livechat - Department Flow', () => { }); test('OC - Livechat - Chat with Department', async () => { + + const guest = { + name: `${faker.person.firstName()} ${faker.string.nanoid(10)}}`, + email: faker.internet.email(), + }; + await test.step('expect start Chat with department', async () => { await poLiveChat.openAnyLiveChat(); - await poLiveChat.sendMessage(firstUser, false, departmentA.name); + await poLiveChat.sendMessage(guest, false, departmentA.name); await expect(poLiveChat.onlineAgentMessage).toBeVisible(); await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user'); await poLiveChat.btnSendMessageToOnlineAgent.click(); @@ -77,7 +80,7 @@ test.describe('OC - Livechat - Department Flow', () => { }); await test.step('expect message to be received by department', async () => { - await poHomeOmnichannelAgent1.sidenav.openChat(firstUser.name); + await poHomeOmnichannelAgent1.sidenav.openChat(guest.name); await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toBeVisible(); await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toContainText('this_a_test_message_from_user'); }); @@ -89,9 +92,15 @@ test.describe('OC - Livechat - Department Flow', () => { }); test('OC - Livechat - Change Department', async () => { + + const guest = { + name: `${faker.person.firstName()} ${faker.string.nanoid(10)}}`, + email: faker.internet.email(), + + }; await test.step('expect start Chat with department', async () => { await poLiveChat.openAnyLiveChat(); - await poLiveChat.sendMessage(firstUser, false, departmentA.name); + await poLiveChat.sendMessage(guest, false, departmentA.name); await expect(poLiveChat.onlineAgentMessage).toBeVisible(); await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user'); await poLiveChat.btnSendMessageToOnlineAgent.click(); @@ -99,7 +108,7 @@ test.describe('OC - Livechat - Department Flow', () => { }); await test.step('expect message to be received by department 1', async () => { - await poHomeOmnichannelAgent1.sidenav.openChat(firstUser.name); + await poHomeOmnichannelAgent1.sidenav.openChat(guest.name); await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toBeVisible(); await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toContainText('this_a_test_message_from_user'); }); @@ -142,7 +151,7 @@ test.describe('OC - Livechat - Department Flow', () => { }); await test.step('expect message to be received by department', async () => { - await poHomeOmnichannelAgent2.sidenav.openChat(firstUser.name); + await poHomeOmnichannelAgent2.sidenav.openChat(guest.name); await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toBeVisible(); await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toContainText('this_a_test_message_from_user_to_department_2'); });