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

fix(Omnichannel): Omnichannel agent take it button #32175

Merged
merged 38 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ebc643c
fix test
tiagoevanp Apr 10, 2024
b57be3e
rewrite test's name
tiagoevanp Apr 10, 2024
b975a01
add a test as a proof of concept
tiagoevanp Apr 10, 2024
3cd61c0
:(
tiagoevanp Apr 11, 2024
8377f2e
Merge branch 'develop' into test/omnichannel-take-chat
MarcosSpessatto Apr 11, 2024
382fc8a
Update apps/meteor/tests/e2e/omnichannel/omnichannel-take-chat.spec.ts
tiagoevanp Apr 11, 2024
bdbde04
Update apps/meteor/tests/e2e/omnichannel/omnichannel-take-chat.spec.ts
tiagoevanp Apr 11, 2024
656285e
Update apps/meteor/tests/e2e/omnichannel/omnichannel-take-chat.spec.ts
tiagoevanp Apr 11, 2024
23cec6a
Merge branch 'develop' into test/omnichannel-take-chat
tiagoevanp Apr 13, 2024
cccc66b
fix review
ggazzo Apr 17, 2024
5689ea5
wip
tiagoevanp Apr 17, 2024
4e9aebb
this
tiagoevanp Apr 17, 2024
e0e3835
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into test…
tiagoevanp Apr 17, 2024
657d07f
trash
tiagoevanp Apr 17, 2024
689d708
clean
tiagoevanp Apr 17, 2024
564781b
clean 2
tiagoevanp Apr 17, 2024
97fc7a8
double test
tiagoevanp Apr 17, 2024
f1b886c
fix
tiagoevanp Apr 18, 2024
d561ebe
Merge branch 'develop' into test/omnichannel-take-chat
KevLehman Apr 19, 2024
6e56d00
button take chat disabled when offline
tiagoevanp Apr 19, 2024
66de1be
Merge branch 'develop' into test/omnichannel-take-chat
KevLehman Apr 19, 2024
81b5778
Create forty-ghosts-flow.md
tiagoevanp Apr 21, 2024
8fbcd88
Merge branch 'develop' into test/omnichannel-take-chat
tiagoevanp Apr 21, 2024
e93cf98
Update apps/meteor/tests/e2e/omnichannel/omnichannel-takeChat.spec.ts
tiagoevanp Apr 23, 2024
93a62a9
Merge branch 'develop' into test/omnichannel-take-chat
KevLehman Apr 29, 2024
fd90cce
add offline message title
tiagoevanp Apr 30, 2024
de3674b
Merge branch 'develop' into test/omnichannel-take-chat
tiagoevanp Apr 30, 2024
340bc50
Merge branch 'develop' into test/omnichannel-take-chat
tiagoevanp May 13, 2024
86c94dd
updates
tiagoevanp May 20, 2024
27987c2
title fix
tiagoevanp May 20, 2024
45fcf22
different title
tiagoevanp May 20, 2024
57e6611
Apply suggestions from code review
tiagoevanp May 23, 2024
73c095a
Update packages/i18n/src/locales/en.i18n.json
tiagoevanp May 23, 2024
ecec205
Apply suggestions from code review
KevLehman May 24, 2024
fd0d000
Merge branch 'develop' into test/omnichannel-take-chat
tiagoevanp May 25, 2024
4791384
Merge branch 'develop' into test/omnichannel-take-chat
tiagoevanp May 27, 2024
148124a
conflict resolution error :whip:
tiagoevanp May 27, 2024
7aa2509
Merge branch 'develop' into test/omnichannel-take-chat
kodiakhq[bot] Jun 10, 2024
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
5 changes: 5 additions & 0 deletions .changeset/forty-ghosts-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed "Take it" button behavior disabling it when agent status is set to offline
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { MessageFooterCallout, MessageFooterCalloutAction, MessageFooterCalloutContent } from '@rocket.chat/ui-composer';
import { useEndpoint, useMethod, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import { useEndpoint, useMethod, useToastMessageDispatch, useTranslation, useUser } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React from 'react';
import React, { useMemo } from 'react';

import { useOmnichannelAgentAvailable } from '../../../../hooks/omnichannel/useOmnichannelAgentAvailable';
import { useOmnichannelRoom } from '../../contexts/RoomContext';

export const ComposerOmnichannelInquiry = (): ReactElement => {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

const user = useUser();
const agentAvailable = useOmnichannelAgentAvailable();
const room = useOmnichannelRoom();
const getInquire = useEndpoint('GET', `/v1/livechat/inquiries.getOne`);
const result = useQuery(['inquire', room._id], () =>
getInquire({
roomId: room._id,
}),
);

const takeInquiry = useMethod('livechat:takeInquiry');

const handleTakeInquiry = async (): Promise<void> => {
Expand All @@ -32,11 +36,24 @@ export const ComposerOmnichannelInquiry = (): ReactElement => {
}
};

const t = useTranslation();
const title = useMemo(() => {
if (user?.status === 'offline') {
return t('meteor_status_offline');
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
}

if (!agentAvailable) {
return t('Youre_unavailable');
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
}
}, [agentAvailable, t, user?.status]);

return (
<MessageFooterCallout aria-busy={result.isLoading}>
<MessageFooterCalloutContent>{t('you_are_in_preview_mode_of_incoming_livechat')}</MessageFooterCalloutContent>
<MessageFooterCalloutAction disabled={result.isLoading} onClick={handleTakeInquiry}>
<MessageFooterCalloutAction
{...(title && { title })}
disabled={result.isLoading || user?.status === 'offline' || !agentAvailable}
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
onClick={handleTakeInquiry}
>
{t('Take_it')}
</MessageFooterCalloutAction>
</MessageFooterCallout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getRoomId = (page: Page): string => {
return rid;
};

test.describe('omnichannel-changing-room-priority-and-sla', () => {
test.describe.serial('omnichannel-changing-room-priority-and-sla', () => {
test.skip(!IS_EE, 'Enterprise Only');

let poLiveChat: OmnichannelLiveChat;
Expand Down Expand Up @@ -69,7 +69,7 @@ test.describe('omnichannel-changing-room-priority-and-sla', () => {
await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_user');
await poLiveChat.btnSendMessageToOnlineAgent.click();

await agent.poHomeChannel.sidenav.openQueuedOmnichannelChat(newVisitor.name);
await agent.poHomeChannel.sidenav.getQueuedChat(newVisitor.name).click();
});

test('expect to change priority of room and corresponding system message should be displayed', async ({ api }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test.describe('Omnichannel close inquiry', () => {
});

await test.step('Expect to have 1 omnichannel assigned to agent 1', async () => {
await agent.poHomeOmnichannel.sidenav.openQueuedOmnichannelChat(newUser.name);
await agent.poHomeOmnichannel.sidenav.getQueuedChat(newUser.name).click();
await expect(agent.poHomeOmnichannel.content.btnTakeChat).toBeVisible();
});

Expand Down
60 changes: 41 additions & 19 deletions apps/meteor/tests/e2e/omnichannel/omnichannel-takeChat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ test.describe('omnichannel-takeChat', () => {

let agent: { page: Page; poHomeChannel: HomeOmnichannel };

const sendLivechatMessage = async () => {
await poLiveChat.openLiveChat();
await poLiveChat.sendMessage(newVisitor, false);
await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_user');
await poLiveChat.btnSendMessageToOnlineAgent.click();
};

test.beforeAll(async ({ api, browser }) => {
await Promise.all([
await api.post('/livechat/users/agent', { username: 'user1' }).then((res) => expect(res.status()).toBe(200)),
Expand All @@ -24,51 +31,66 @@ test.describe('omnichannel-takeChat', () => {
});

test.afterAll(async ({ api }) => {
await agent.poHomeChannel.sidenav.switchOmnichannelStatus('online');
await agent.poHomeChannel.sidenav.switchStatus('online');

await Promise.all([
await api.post('/settings/Livechat_Routing_Method', { value: 'Auto_Selection' }).then((res) => expect(res.status()).toBe(200)),
await api.post('/settings/Livechat_enabled_when_agent_idle', { value: false }).then((res) => expect(res.status()).toBe(200)),
await api.delete('/livechat/users/agent/user1').then((res) => expect(res.status()).toBe(200)),
await api.post('/settings/Livechat_Routing_Method', { value: 'Auto_Selection' }).then((res) => expect(res.status()).toBe(200)),
await api.post('/settings/Livechat_enabled_when_agent_idle', { value: true }).then((res) => expect(res.status()).toBe(200)),
]);

await agent.page.close();
});

test.beforeEach(async ({ page, api }) => {
// make "user-1" online
test.beforeEach('start a new livechat chat', async ({ page, api }) => {
await agent.poHomeChannel.sidenav.switchStatus('online');

// start a new chat for each test
newVisitor = {
name: `${faker.person.firstName()} ${faker.string.uuid()}`,
email: faker.internet.email(),
};

poLiveChat = new OmnichannelLiveChat(page, api);

await page.goto('/livechat');
await poLiveChat.openLiveChat();
await poLiveChat.sendMessage(newVisitor, false);
await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_user');
await poLiveChat.btnSendMessageToOnlineAgent.click();
});

test('expect "user1" to be able to take the chat from the queue', async () => {
await agent.poHomeChannel.sidenav.openQueuedOmnichannelChat(newVisitor.name);
test('When agent is online should take the chat', async () => {
await sendLivechatMessage();

await agent.poHomeChannel.sidenav.getQueuedChat(newVisitor.name).click();

await expect(agent.poHomeChannel.content.btnTakeChat).toBeVisible();
await agent.poHomeChannel.content.btnTakeChat.click();

await agent.poHomeChannel.content.btnTakeChat.click();
await agent.poHomeChannel.sidenav.openChat(newVisitor.name);

await expect(agent.poHomeChannel.content.btnTakeChat).not.toBeVisible();
await expect(agent.poHomeChannel.content.inputMessage).toBeVisible();

await poLiveChat.closeChat();
});

test('expect "user1" to not able able to take chat from queue in-case its user status is offline', async () => {
// make "user-1" offline
test('When agent is offline should not take the chat', async () => {
await agent.poHomeChannel.sidenav.switchStatus('offline');

await agent.poHomeChannel.sidenav.openQueuedOmnichannelChat(newVisitor.name);
await expect(agent.poHomeChannel.content.btnTakeChat).toBeVisible();
await agent.poHomeChannel.content.btnTakeChat.click();
await sendLivechatMessage();

await expect(poLiveChat.alertMessage('Error starting a new conversation: Sorry, no online agents [no-agent-online]')).toBeVisible();
});

test('When a new livechat conversation starts but agent is offline, it should not be able to take the chat', async () => {
await sendLivechatMessage();

await agent.poHomeChannel.sidenav.switchStatus('offline');
await agent.poHomeChannel.sidenav.getQueuedChat(newVisitor.name).click();

await expect(agent.poHomeChannel.content.btnTakeChat).toBeDisabled();

await agent.poHomeChannel.sidenav.switchStatus('online');
await agent.poHomeChannel.sidenav.switchOmnichannelStatus('offline');

// expect to see error message
await expect(agent.page.locator('text=Agent status is offline or Omnichannel service is not active')).toBeVisible();
await expect(agent.poHomeChannel.content.btnTakeChat).toBeDisabled();
});
});
10 changes: 5 additions & 5 deletions apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class HomeSidenav {
return this.page.getByRole('toolbar', { name: 'Sidebar actions' });
}

// Note: this is different from openChat because queued chats are not searchable
getQueuedChat(name: string): Locator {
return this.page.locator('[data-qa="sidebar-item-title"]', { hasText: name }).first();
ggazzo marked this conversation as resolved.
Show resolved Hide resolved
}

getSidebarItemByName(name: string): Locator {
return this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`);
}
Expand Down Expand Up @@ -129,11 +134,6 @@ export class HomeSidenav {
expect(newStatus).toBe(status === 'offline' ? StatusTitleMap.offline : StatusTitleMap.online);
}

// Note: this is a workaround for now since queued omnichannel chats are not searchable yet so we can't use openChat() :(
async openQueuedOmnichannelChat(name: string): Promise<void> {
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
await this.page.locator('[data-qa="sidebar-item-title"]', { hasText: name }).first().click();
}

async createPublicChannel(name: string) {
await this.openNewByLabel('Channel');
await this.checkboxPrivateChannel.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class OmnichannelLiveChat {
): Promise<void> {
await this.openAnyLiveChat();
await this.sendMessage(liveChatUser, false);
await this.onlineAgentMessage.type(message);
await this.onlineAgentMessage.fill(message);
await this.btnSendMessageToOnlineAgent.click();
await expect(this.txtChatMessage(message)).toBeVisible();
await this.closeChat();
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -6419,5 +6419,6 @@
"Close_gallery": "Close gallery",
"Next_image": "Next Image",
"Previous_image": "Previous image",
"Image_gallery": "Image gallery"
"Image_gallery": "Image gallery",
"Youre_unavailable": "You’re unavailable"
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
}
Loading