From 249fb785feef491c3e0b8c73146aaebf2e1126a9 Mon Sep 17 00:00:00 2001 From: Martin Schoeler Date: Tue, 16 Apr 2024 14:13:03 -0300 Subject: [PATCH] test(Livechat): Cross tab communication (#32138) --- ...channel-livechat-tab-communication.spec.ts | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-tab-communication.spec.ts diff --git a/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-tab-communication.spec.ts b/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-tab-communication.spec.ts new file mode 100644 index 000000000000..17e32fd51d70 --- /dev/null +++ b/apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-tab-communication.spec.ts @@ -0,0 +1,85 @@ +import { faker } from '@faker-js/faker'; + +import { createAuxContext } from '../fixtures/createAuxContext'; +import { Users } from '../fixtures/userStates'; +import { HomeOmnichannel, OmnichannelLiveChat } from '../page-objects'; +import { createAgent } from '../utils/omnichannel/agents'; +import { test, expect } from '../utils/test'; + +test.describe('OC - Livechat - Cross Tab Communication', () => { + let pageLivechat1: OmnichannelLiveChat; + let pageLivechat2: OmnichannelLiveChat; + + let poHomeOmnichannel: HomeOmnichannel; + let agent: Awaited>; + + test.beforeAll(async ({ browser, api }) => { + agent = await createAgent(api, 'user1'); + + const { page } = await createAuxContext(browser, Users.user1, '/'); + poHomeOmnichannel = new HomeOmnichannel(page); + }); + + test.beforeEach(async ({ browser, api }) => { + const context = await browser.newContext(); + const p1 = await context.newPage(); + const p2 = await context.newPage(); + + pageLivechat1 = new OmnichannelLiveChat(p1, api); + pageLivechat2 = new OmnichannelLiveChat(p2, api); + + await pageLivechat1.page.goto('/livechat'); + await pageLivechat2.page.goto('/livechat'); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page?.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const firstUser = { + name: `${faker.person.firstName()} ${faker.string.uuid()}}`, + email: faker.internet.email(), + }; + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(firstUser, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible(); + + await expect(pageLivechat2.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + + await expect(pageLivechat1.btnNewChat).toBeVisible(); + await pageLivechat1.startNewChat(); + + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user_after_close'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + + await pageLivechat1.page.locator('div >> text="this_a_test_message_from_user"').waitFor({ state: 'hidden' }); + await pageLivechat2.page.locator('div >> text="this_a_test_message_from_user"').waitFor({ state: 'hidden' }); + + + await expect(pageLivechat1.page.locator('div >> text="this_a_test_message_from_user"')).not.toBeVisible(); + await expect(pageLivechat2.page.locator('div >> text="this_a_test_message_from_user"')).not.toBeVisible(); + + await expect(pageLivechat1.page.locator('div >> text="this_a_test_message_from_user_after_close"')).toBeVisible(); + await expect(pageLivechat2.page.locator('div >> text="this_a_test_message_from_user_after_close"')).toBeVisible(); + }); + }); +});