Skip to content

Commit

Permalink
test(Livechat): Cross tab communication (#32138)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Apr 16, 2024
1 parent 3b58d23 commit 249fb78
Showing 1 changed file with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ReturnType<typeof createAgent>>;

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();
});
});
});

0 comments on commit 249fb78

Please sign in to comment.