diff --git a/.github/workflows/ci-test-e2e.yml b/.github/workflows/ci-test-e2e.yml index 6a4aa84c8da45..a499f5271b9bd 100644 --- a/.github/workflows/ci-test-e2e.yml +++ b/.github/workflows/ci-test-e2e.yml @@ -291,7 +291,7 @@ jobs: working-directory: ./apps/meteor run: | yarn prepare - yarn test:e2e --shard=${{ matrix.shard }}/${{ inputs.total-shard }} + yarn playwright test tests/e2e/flaky/ - name: Store playwright test trace if: inputs.type == 'ui' && always() diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-0.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-0.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-0.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-10.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-10.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-10.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-2.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-2.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-2.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-3.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-3.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-3.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-4.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-4.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-4.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-5.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-5.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-5.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-6.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-6.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-6.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-7.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-7.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-7.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-8.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-8.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-8.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-9.spec.ts b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-9.spec.ts new file mode 100644 index 0000000000000..5f3a35004a8da --- /dev/null +++ b/apps/meteor/tests/e2e/flaky/omnichannel-livechat-tab-communication-9.spec.ts @@ -0,0 +1,95 @@ +import { createFakeVisitor } from '../../mocks/data'; +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.afterEach(async () => { + await pageLivechat1.page.close(); + await pageLivechat2.page.close(); + }); + + test.afterAll(async () => { + await poHomeOmnichannel.page.close(); + await agent.delete(); + }); + + test('OC - Livechat - Send messages, close chat and start again 2 tabs', async () => { + const visitor = createFakeVisitor(); + + await test.step('expect livechat conversations to be synced', async () => { + await pageLivechat1.openAnyLiveChat(); + + await pageLivechat1.sendMessage(visitor, false); + await pageLivechat1.onlineAgentMessage.fill('this_a_test_message_from_user'); + await pageLivechat1.btnSendMessageToOnlineAgent.click(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + + await test.step('expect to restart a livechat conversation and tabs to be synced', async () => { + 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.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + await pageLivechat2.txtChatMessage('this_a_test_message_from_user').waitFor({ state: 'hidden' }); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user')).not.toBeVisible(); + + await expect(pageLivechat1.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + await expect(pageLivechat2.txtChatMessage('this_a_test_message_from_user_after_close')).toBeVisible(); + }); + + await test.step('expect to close livechat conversation', async () => { + await expect(pageLivechat1.btnOptions).toBeVisible(); + await pageLivechat1.btnOptions.click(); + + await expect(pageLivechat1.btnCloseChat).toBeVisible(); + await pageLivechat1.btnCloseChat.click(); + + await pageLivechat1.btnCloseChatConfirm.click(); + }); + }); +}); diff --git a/packages/livechat/src/lib/room.js b/packages/livechat/src/lib/room.js index f7e7e97df5f4e..40e362a146ed6 100644 --- a/packages/livechat/src/lib/room.js +++ b/packages/livechat/src/lib/room.js @@ -18,17 +18,13 @@ import { handleTranscript } from './transcript'; import Triggers from './triggers'; const commands = new Commands(); - export const closeChat = async ({ transcriptRequested } = {}) => { - if (!transcriptRequested) { - await handleTranscript(); - } + console.log('Post finish chat action', Date.now()); - const { room, department, config: { settings: { clearLocalStorageWhenChatEnded } = {} } = {} } = store.state; + const { department, config: { settings: { clearLocalStorageWhenChatEnded } = {} } = {} } = store.state; - if (!room) { - console.warn('closeChat called without a room'); - return; + if (!transcriptRequested) { + await handleTranscript(); } await store.setState({ room: null, renderedTriggers: [] }); @@ -46,6 +42,7 @@ export const closeChat = async ({ transcriptRequested } = {}) => { await loadConfig(); parentCall('callback', 'chat-ended'); route('/chat-finished'); + console.log('Close room procedure completed successfuly'); }; const getVideoConfMessageData = (message) => @@ -355,10 +352,11 @@ export const defaultRoomParams = () => { return params; }; -store.on('change', ([state, prevState]) => { +store.on('change', async ([state, prevState]) => { // Cross-tab communication // Detects when a room is created and then route to the correct container if (prevState.room?._id !== state.room?._id) { + console.log('Room was added to the store. Redirecting to /'); route('/'); } }); diff --git a/packages/livechat/src/routes/Chat/container.js b/packages/livechat/src/routes/Chat/container.js index e38a53a7db6a6..f9756850d401e 100644 --- a/packages/livechat/src/routes/Chat/container.js +++ b/packages/livechat/src/routes/Chat/container.js @@ -2,6 +2,7 @@ import { Component } from 'preact'; import { route } from 'preact-router'; import { withTranslation } from 'react-i18next'; +import Chat from './component'; import { Livechat } from '../../api'; import { ModalManager } from '../../components/Modal'; import { getAvatarUrl } from '../../helpers/baseUrl'; @@ -22,9 +23,8 @@ import constants from '../../lib/constants'; import { getLastReadMessage, loadConfig, processUnread, shouldMarkAsUnread } from '../../lib/main'; import { parentCall, runCallbackEventEmitter } from '../../lib/parentCall'; import { createToken } from '../../lib/random'; -import { initRoom, closeChat, loadMessages, loadMoreMessages, defaultRoomParams, getGreetingMessages } from '../../lib/room'; +import { initRoom, loadMessages, loadMoreMessages, defaultRoomParams, getGreetingMessages } from '../../lib/room'; import store from '../../store'; -import Chat from './component'; const ChatWrapper = ({ children, rid }) => { useRoomMessagesSubscription(rid); @@ -230,31 +230,40 @@ class ChatContainer extends Component { onFinishChat = async () => { const { i18n } = this.props; + console.log('Opening confirmation modal'); const { success } = await ModalManager.confirm({ text: i18n.t('are_you_sure_you_want_to_finish_this_chat'), }); if (!success) { + console.log('Finish chat action cancelled'); return; } + console.log('Finish chat action confirmed'); + const { alerts, dispatch, room } = this.props; const { _id: rid } = room || {}; + console.log('Finish chat room', rid); + await dispatch({ loading: true }); try { if (!rid) { + console.log('Room not found'); throw new Error('error-room-not-found'); } await Livechat.closeChat({ rid }); } catch (error) { + console.log('Failed to close chat'); console.error(error); const alert = { id: createToken(), children: i18n.t('error_closing_chat'), error: true, timeout: 0 }; await dispatch({ alerts: (alerts.push(alert), alerts) }); } finally { + console.log('Finish chat action finally'); + await dispatch({ loading: false }); - await closeChat(); } }; diff --git a/packages/livechat/src/store/index.tsx b/packages/livechat/src/store/index.tsx index 8f5294e42cbae..672c1d7ead952 100644 --- a/packages/livechat/src/store/index.tsx +++ b/packages/livechat/src/store/index.tsx @@ -3,13 +3,13 @@ import type { ComponentChildren } from 'preact'; import { Component, createContext } from 'preact'; import { useContext } from 'preact/hooks'; +import Store from './Store'; import type { CustomField } from '../components/Form/CustomFields'; import type { Agent } from '../definitions/agents'; import type { Department } from '../definitions/departments'; import type { TriggerMessage } from '../definitions/triggerMessage'; import { parentCall } from '../lib/parentCall'; import { createToken } from '../lib/random'; -import Store from './Store'; export type LivechatHiddenSytemMessageType = | 'uj' // User joined