Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(livechat): fix Department flaky test #32102

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { createAgent } from '../utils/omnichannel/agents';
import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments';
import { test, expect } from '../utils/test';

const firstUser = {
name: `${faker.person.firstName()} ${faker.string.uuid()}}`,
email: faker.internet.email(),
};


test.use({ storageState: Users.user1.state });

Expand Down Expand Up @@ -54,8 +51,8 @@ test.describe('OC - Livechat - Department Flow', () => {
});

test.afterEach(async ({ page }) => {
await poHomeOmnichannelAgent1.page?.close();
await poHomeOmnichannelAgent2.page?.close();
await poHomeOmnichannelAgent1?.page?.close();
await poHomeOmnichannelAgent2?.page?.close();
await page.close();
});

Expand All @@ -67,17 +64,23 @@ test.describe('OC - Livechat - Department Flow', () => {
});

test('OC - Livechat - Chat with Department', async () => {

const guest = {
name: `${faker.person.firstName()} ${faker.string.nanoid(10)}}`,
email: faker.internet.email(),
};

await test.step('expect start Chat with department', async () => {
await poLiveChat.openAnyLiveChat();
await poLiveChat.sendMessage(firstUser, false, departmentA.name);
await poLiveChat.sendMessage(guest, false, departmentA.name);
await expect(poLiveChat.onlineAgentMessage).toBeVisible();
await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user');
await poLiveChat.btnSendMessageToOnlineAgent.click();
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible();
});

await test.step('expect message to be received by department', async () => {
await poHomeOmnichannelAgent1.sidenav.openChat(firstUser.name);
await poHomeOmnichannelAgent1.sidenav.openChat(guest.name);
await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toBeVisible();
await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toContainText('this_a_test_message_from_user');
});
Expand All @@ -89,34 +92,73 @@ test.describe('OC - Livechat - Department Flow', () => {
});

test('OC - Livechat - Change Department', async () => {

const guest = {
name: `${faker.person.firstName()} ${faker.string.nanoid(10)}}`,
email: faker.internet.email(),

};
await test.step('expect start Chat with department', async () => {
await poLiveChat.openAnyLiveChat();
await poLiveChat.sendMessage(firstUser, false, departmentA.name);
await poLiveChat.sendMessage(guest, false, departmentA.name);
await expect(poLiveChat.onlineAgentMessage).toBeVisible();
await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user');
await poLiveChat.btnSendMessageToOnlineAgent.click();
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible();
});

await test.step('expect message to be received by department 1', async () => {
await poHomeOmnichannelAgent1.sidenav.openChat(guest.name);
await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toBeVisible();
await expect(poHomeOmnichannelAgent1.content.lastUserMessage).toContainText('this_a_test_message_from_user');
});

await test.step('expect message to be sent by department 1', async () => {
await poHomeOmnichannelAgent1.content.sendMessage('this_a_test_message_from_agent_department_1');
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_agent_department_1"')).toBeVisible();
await poHomeOmnichannelAgent1.page.close();
});

await test.step('expect to change department', async () => {
await poLiveChat.changeDepartment(departmentB.name);
await poLiveChat.btnOptions.click();
await poLiveChat.btnChangeDepartment.click();

await expect(poLiveChat.selectDepartment).toBeVisible();
await poLiveChat.selectDepartment.selectOption({ label: departmentB.name });

await expect(poLiveChat.btnSendMessage('Start chat')).toBeEnabled();
await poLiveChat.btnSendMessage('Start chat').click();

await expect(poLiveChat.livechatModal).toBeVisible();

await expect(poLiveChat.livechatModalText('Are you sure you want to switch the department?')).toBeVisible();
await poLiveChat.btnYes.click();

await expect(poLiveChat.livechatModal).toBeVisible();

await expect(poLiveChat.livechatModalText('Department switched')).toBeVisible();
await poLiveChat.btnOk.click();

// Expect keep chat history
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user"')).toBeVisible();

// Expect user to have changed
await expect(await poLiveChat.headerTitle.textContent()).toEqual(agent2.username);

await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user_to_department_2');
await poLiveChat.btnSendMessageToOnlineAgent.click();
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_user_to_department_2"')).toBeVisible();
});

await test.step('expect message to be received by department', async () => {
await poHomeOmnichannelAgent2.sidenav.openChat(firstUser.name);
await poHomeOmnichannelAgent2.sidenav.openChat(guest.name);
await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toBeVisible();
await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toContainText('this_a_test_message_from_user');
await expect(poHomeOmnichannelAgent2.content.lastUserMessage).toContainText('this_a_test_message_from_user_to_department_2');
});

await test.step('expect message to be sent by department', async () => {
await poHomeOmnichannelAgent2.content.sendMessage('this_a_test_message_from_agent');
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_agent"')).toBeVisible();
await poHomeOmnichannelAgent2.content.sendMessage('this_a_test_message_from_agent_department_2');
await expect(poLiveChat.page.locator('div >> text="this_a_test_message_from_agent_department_2"')).toBeVisible();
});
});
});
18 changes: 6 additions & 12 deletions apps/meteor/tests/e2e/page-objects/omnichannel-livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ export class OmnichannelLiveChat {
return this.page.locator(`text="${message}"`);
}

async changeDepartment (department: string): Promise<void> {
await this.btnOptions.click();
await this.btnChangeDepartment.click();
await this.selectDepartment.waitFor({ state: 'visible' });
await this.selectDepartment.selectOption({ label: department });
await this.btnSendMessage('Start chat').click();
await this.btnYes.click();
await this.btnOk.click();
}

async closeChat(): Promise<void> {
await this.btnOptions.click();
await this.btnCloseChat.click();
Expand Down Expand Up @@ -132,8 +122,12 @@ export class OmnichannelLiveChat {
return this.page.locator('footer div div div:nth-child(3) button');
}

get firstAutoMessage(): Locator {
return this.page.locator('div.message-text__WwYco p');
get livechatModal(): Locator {
return this.page.locator('[data-qa-type="modal-overlay"]');
}

livechatModalText(text: string): Locator {
return this.page.locator(`[data-qa-type="modal-overlay"] >> text=${text}`);
}

get fileUploadTarget(): Locator {
Expand Down
7 changes: 6 additions & 1 deletion packages/livechat/src/components/Modal/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export class Modal extends Component {

render = ({ children, animated, open, ...props }) =>
open ? (
<div onTouchStart={this.handleTouchStart} onMouseDown={this.handleMouseDown} className={createClassName(styles, 'modal__overlay')}>
<div
data-qa-type='modal-overlay'
onTouchStart={this.handleTouchStart}
onMouseDown={this.handleMouseDown}
className={createClassName(styles, 'modal__overlay')}
>
<div className={createClassName(styles, 'modal', { animated })} {...props}>
{children}
</div>
Expand Down
Loading