Skip to content

Commit

Permalink
test(Livechat): Clean up after registerGuest() test (#32092)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Mar 28, 2024
1 parent 3158edf commit 68f541c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions apps/meteor/tests/e2e/omnichannel/omnichannel-livechat-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ test.describe('OC - Livechat API', () => {
let agent: Awaited<ReturnType<typeof createAgent>>;
let agent2: Awaited<ReturnType<typeof createAgent>>;
let departments: Awaited<ReturnType<typeof createDepartment>>[];
let pageContext: Page;

test.beforeAll(async ({ api }) => {
agent = await createAgent(api, 'user1');
Expand Down Expand Up @@ -262,6 +263,7 @@ test.describe('OC - Livechat API', () => {
await poAuxContext.page.close();
await page.close();
await poAuxContext2?.page.close();
await pageContext?.close();
});

test.afterAll(async ({ api }) => {
Expand Down Expand Up @@ -388,20 +390,20 @@ test.describe('OC - Livechat API', () => {
});

await test.step('Expect registerGuest to log in an existing guest and load chat history', async () => {
const { page: pageCtx } = await createAuxContext(browser, Users.user1);
({ page: pageContext } = await createAuxContext(browser, Users.user1));

await pageCtx.goto('/packages/rocketchat_livechat/assets/demo.html');
await pageContext.goto('/packages/rocketchat_livechat/assets/demo.html');

await pageCtx.evaluate(() => window.RocketChat.livechat.maximizeWidget());
await expect(pageCtx.frameLocator('#rocketchat-iframe').getByText('Start Chat')).toBeVisible();
await pageContext.evaluate(() => window.RocketChat.livechat.maximizeWidget());
await expect(pageContext.frameLocator('#rocketchat-iframe').getByText('Start Chat')).toBeVisible();

await pageCtx.evaluate(
await pageContext.evaluate(
(registerGuestVisitor) => window.RocketChat.livechat.registerGuest(registerGuestVisitor),
registerGuestVisitor,
);

await expect(pageCtx.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();
await expect(pageCtx.frameLocator('#rocketchat-iframe').getByText('this_a_test_message_from_visitor')).toBeVisible();
await expect(pageContext.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();
await expect(pageContext.frameLocator('#rocketchat-iframe').getByText('this_a_test_message_from_visitor')).toBeVisible();
});
});

Expand Down Expand Up @@ -593,20 +595,20 @@ test.describe('OC - Livechat API', () => {
await poLiveChat.btnSendMessageToOnlineAgent.click();

await test.step('Expect setGuestToken to log in an existing guest and load chat history', async () => {
const { page: pageCtx } = await createAuxContext(browser, Users.user1);
({ page: pageContext } = await createAuxContext(browser, Users.user1));

await pageCtx.goto('/packages/rocketchat_livechat/assets/demo.html');
await pageContext.goto('/packages/rocketchat_livechat/assets/demo.html');

await pageCtx.evaluate(() => window.RocketChat.livechat.maximizeWidget());
await expect(pageCtx.frameLocator('#rocketchat-iframe').getByText('Start Chat')).toBeVisible();
await pageContext.evaluate(() => window.RocketChat.livechat.maximizeWidget());
await expect(pageContext.frameLocator('#rocketchat-iframe').getByText('Start Chat')).toBeVisible();

await pageCtx.evaluate(
await pageContext.evaluate(
(registerGuestVisitor) => window.RocketChat.livechat.setGuestToken(registerGuestVisitor.token),
registerGuestVisitor,
);

await expect(pageCtx.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();
await expect(pageCtx.frameLocator('#rocketchat-iframe').getByText('this_a_test_message_from_visitor')).toBeVisible();
await expect(pageContext.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();
await expect(pageContext.frameLocator('#rocketchat-iframe').getByText('this_a_test_message_from_visitor')).toBeVisible();
});
});
});
Expand Down

0 comments on commit 68f541c

Please sign in to comment.