Skip to content

Commit

Permalink
test(Livechat): registerguest() with different guests (#32072)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored and ggazzo committed Apr 23, 2024
1 parent 3bc7d9f commit 40b6fac
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 15 deletions.
115 changes: 101 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 @@ -67,7 +67,7 @@ test.describe('OC - Livechat API', () => {
let agent: Awaited<ReturnType<typeof createAgent>>;

test.beforeAll(async ({ browser, api }) => {
agent = await createAgent(api, 'user1')
agent = await createAgent(api, 'user1');

page = await browser.newPage();
await expect((await api.post('/settings/Enable_CSP', { value: false })).status()).toBe(200);
Expand Down Expand Up @@ -221,16 +221,15 @@ test.describe('OC - Livechat API', () => {
let agent2: Awaited<ReturnType<typeof createAgent>>;
let departments: Awaited<ReturnType<typeof createDepartment>>[];


test.beforeAll(async ({ api }) => {
agent = await createAgent(api, 'user1')
agent2 = await createAgent(api, 'user2')
agent = await createAgent(api, 'user1');
agent2 = await createAgent(api, 'user2');

departments = await Promise.all([createDepartment(api), createDepartment(api)]);
const [departmentA, departmentB] = departments.map(({ data }) => data);

await addAgentToDepartment(api, { department: departmentA, agentId: agent.data._id })
await addAgentToDepartment(api, { department: departmentB, agentId: agent2.data._id })
await addAgentToDepartment(api, { department: departmentA, agentId: agent.data._id });
await addAgentToDepartment(api, { department: departmentB, agentId: agent2.data._id });

await expect((await api.post('/settings/Enable_CSP', { value: false })).status()).toBe(200);
await expect((await api.post('/settings/Livechat_offline_email', { value: 'test@testing.com' })).status()).toBe(200);
Expand All @@ -253,7 +252,7 @@ test.describe('OC - Livechat API', () => {

if (testInfo.title === 'OC - Livechat API - setDepartment') {
const { page: pageCtx2 } = await createAuxContext(browser, Users.user2);
poAuxContext2 = { page: pageCtx2, poHomeOmnichannel: new HomeOmnichannel(pageCtx) };
poAuxContext2 = { page: pageCtx2, poHomeOmnichannel: new HomeOmnichannel(pageCtx) };
}

await page.goto('/packages/rocketchat_livechat/assets/demo.html');
Expand Down Expand Up @@ -349,10 +348,7 @@ test.describe('OC - Livechat API', () => {
const depId = departmentB._id;

await test.step('Expect setDepartment to change a guest department', async () => {
await poLiveChat.page.evaluate(
(depId) => window.RocketChat.livechat.setDepartment(depId),
depId,
);
await poLiveChat.page.evaluate((depId) => window.RocketChat.livechat.setDepartment(depId), depId);
});

await test.step('Expect registered guest to be in dep2', async () => {
Expand Down Expand Up @@ -408,6 +404,99 @@ test.describe('OC - Livechat API', () => {
});
});

test('OC - Livechat API - registerGuest different guests', async () => {
const registerGuestVisitor1 = {
name: faker.person.firstName(),
email: faker.internet.email(),
token: faker.string.uuid(),
};

const registerGuestVisitor2 = {
name: faker.person.firstName(),
email: faker.internet.email(),
token: faker.string.uuid(),
};

await test.step('Expect registerGuest to create guest 1', async () => {
await poLiveChat.page.evaluate(() => window.RocketChat.livechat.maximizeWidget());
await expect(poLiveChat.page.frameLocator('#rocketchat-iframe').getByText('Start Chat')).toBeVisible();

await poLiveChat.page.evaluate(
(registerGuestVisitor1) => window.RocketChat.livechat.registerGuest(registerGuestVisitor1),
registerGuestVisitor1,
);

await expect(poLiveChat.page.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();

await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor_1');
await poLiveChat.btnSendMessageToOnlineAgent.click();

await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor_1')).toBeVisible();
});

await test.step('Expect registerGuest to create guest 2', async () => {
await poLiveChat.page.evaluate(
(registerGuestVisitor2) => window.RocketChat.livechat.registerGuest(registerGuestVisitor2),
registerGuestVisitor2,
);

await poLiveChat.page.frameLocator('#rocketchat-iframe').getByText('this_a_test_message_from_visitor').waitFor({ state: 'hidden' });

await expect(poLiveChat.page.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();

await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor_2');
await poLiveChat.btnSendMessageToOnlineAgent.click();

await poLiveChat.txtChatMessage('this_a_test_message_from_visitor_2').waitFor({ state: 'visible' });
await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor_2')).toBeVisible();
});
});

test('OC - Livechat API - registerGuest multiple times', async () => {
const registerGuestVisitor = {
name: faker.person.firstName(),
email: faker.internet.email(),
token: faker.string.uuid(),
};

await test.step('Expect registerGuest work with the same token, multiple times', async () => {
test.fail();

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

await poLiveChat.page.evaluate(
(registerGuestVisitor) => window.RocketChat.livechat.registerGuest(registerGuestVisitor),
registerGuestVisitor,
);

await expect(page.frameLocator('#rocketchat-iframe').getByText('Start Chat')).not.toBeVisible();

await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor');
await poLiveChat.btnSendMessageToOnlineAgent.click();

await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor')).toBeVisible();

await poLiveChat.page.evaluate(
(registerGuestVisitor) => window.RocketChat.livechat.registerGuest(registerGuestVisitor),
registerGuestVisitor,
);

await page.waitForTimeout(500);

await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor')).toBeVisible();

await poLiveChat.page.evaluate(
(registerGuestVisitor) => window.RocketChat.livechat.registerGuest(registerGuestVisitor),
registerGuestVisitor,
);

await page.waitForTimeout(500);

await expect(poLiveChat.txtChatMessage('this_a_test_message_from_visitor')).toBeVisible();
});
});

test('OC - Livechat API - setGuestEmail', async () => {
const registerGuestVisitor = {
name: faker.person.firstName(),
Expand Down Expand Up @@ -528,7 +617,7 @@ test.describe('OC - Livechat API', () => {
let agent: Awaited<ReturnType<typeof createAgent>>;

test.beforeAll(async ({ api }) => {
agent = await createAgent(api, 'user1')
agent = await createAgent(api, 'user1');
await expect((await api.post('/settings/Enable_CSP', { value: false })).status()).toBe(200);
await expect((await api.post('/settings/Livechat_offline_email', { value: 'test@testing.com' })).status()).toBe(200);
});
Expand Down Expand Up @@ -681,7 +770,6 @@ test.describe('OC - Livechat API', () => {
await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor');
await poLiveChat.btnSendMessageToOnlineAgent.click();


const watchForTrigger = page.waitForFunction(() => window.onAgentStatusChange === true);

await poLiveChat.page.evaluate(() =>
Expand Down Expand Up @@ -762,5 +850,4 @@ test.describe('OC - Livechat API', () => {
});
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class OmnichannelLiveChatEmbedded {
}

txtChatMessage(message: string): Locator {
return this.page.frameLocator('#rocketchat-iframe').locator(`text="${message}"`);
return this.page.frameLocator('#rocketchat-iframe').locator(`li >> text="${message}"`);
}

async closeChat(): Promise<void> {
Expand Down

0 comments on commit 40b6fac

Please sign in to comment.