diff --git a/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx b/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx index d321784fa268..192446a8c6ee 100644 --- a/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx +++ b/apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useQuickActions.tsx @@ -10,12 +10,11 @@ import { useEndpoint, useMethod, useTranslation, + useRoute, } from '@rocket.chat/ui-contexts'; -import { FlowRouter } from 'meteor/kadira:flow-router'; import { Session } from 'meteor/session'; import React, { useCallback, useState, useEffect } from 'react'; -import { RoomManager } from '../../../../../../../app/ui-utils/client'; import PlaceChatOnHoldModal from '../../../../../../../ee/app/livechat-enterprise/client/components/modals/PlaceChatOnHoldModal'; import CloseChatModal from '../../../../../../components/Omnichannel/modals/CloseChatModal'; import CloseChatModalData from '../../../../../../components/Omnichannel/modals/CloseChatModalData'; @@ -34,6 +33,7 @@ export const useQuickActions = ( getAction: (id: string) => void; } => { const setModal = useSetModal(); + const route = useRoute('home'); const t = useTranslation(); const dispatchToastMessage = useToastMessageDispatch(); @@ -83,11 +83,11 @@ export const useQuickActions = ( await methodReturn(rid); closeModal(); Session.set('openedRoom', null); - FlowRouter.go('/home'); + route.push(); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); } - }, [closeModal, dispatchToastMessage, methodReturn, rid]); + }, [closeModal, dispatchToastMessage, methodReturn, rid, route]); const requestTranscript = useMethod('livechat:requestTranscript'); @@ -96,7 +96,6 @@ export const useQuickActions = ( try { await requestTranscript(rid, email, subject); closeModal(); - RoomManager.close(`l${rid}`); dispatchToastMessage({ type: 'success', message: t('Livechat_transcript_has_been_requested'), @@ -169,13 +168,13 @@ export const useQuickActions = ( throw new Error(departmentId ? t('error-no-agents-online-in-department') : t('error-forwarding-chat')); } dispatchToastMessage({ type: 'success', message: t('Transferred') }); - FlowRouter.go('/'); + route.push(); closeModal(); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); } }, - [closeModal, dispatchToastMessage, forwardChat, rid, t], + [closeModal, dispatchToastMessage, forwardChat, rid, route, t], ); const closeChat = useMethod('livechat:closeRoom'); diff --git a/apps/meteor/tests/e2e/omnichannel-send-transcript.spec.ts b/apps/meteor/tests/e2e/omnichannel-send-transcript.spec.ts new file mode 100644 index 000000000000..b6d06784b224 --- /dev/null +++ b/apps/meteor/tests/e2e/omnichannel-send-transcript.spec.ts @@ -0,0 +1,61 @@ +import { faker } from '@faker-js/faker'; +import type { Browser, Page } from '@playwright/test'; + +import { test, expect } from './utils/test'; +import { OmnichannelLiveChat, HomeChannel } from './page-objects'; + +const createAuxContext = async (browser: Browser, storageState: string): Promise<{ page: Page; poHomeChannel: HomeChannel }> => { + const page = await browser.newPage({ storageState }); + const poHomeChannel = new HomeChannel(page); + await page.goto('/'); + await page.locator('.main-content').waitFor(); + + return { page, poHomeChannel }; +}; + +test.describe('omnichannel-transcript', () => { + let poLiveChat: OmnichannelLiveChat; + let newUser: { email: string; name: string }; + + let agent: { page: Page; poHomeChannel: HomeChannel }; + test.beforeAll(async ({ api, browser }) => { + newUser = { + name: faker.name.firstName(), + email: faker.internet.email(), + }; + + // Set user user 1 as manager and agent + await api.post('/livechat/users/agent', { username: 'user1' }); + await api.post('/livechat/users/manager', { username: 'user1' }); + + agent = await createAuxContext(browser, 'user1-session.json'); + }); + test.beforeEach(async ({ page }) => { + poLiveChat = new OmnichannelLiveChat(page); + }); + + test.afterAll(async ({ api }) => { + await api.delete('/livechat/users/agent/user1'); + await api.delete('/livechat/users/manager/user1'); + }); + + test('Receiving a message from visitor', async ({ page }) => { + await test.step('Expect send a message as a visitor', async () => { + await page.goto('/livechat'); + await poLiveChat.btnOpenLiveChat('R').click(); + await poLiveChat.sendMessage(newUser, false); + await poLiveChat.onlineAgentMessage.type('this_a_test_message_from_visitor'); + await poLiveChat.btnSendMessageToOnlineAgent.click(); + }); + + await test.step('Expect to have 1 omnichannel assigned to agent 1', async () => { + await agent.poHomeChannel.sidenav.openChat(newUser.name); + }); + + await test.step('Expect to be able to create transcript', async () => { + await agent.poHomeChannel.content.btnSendTranscript.click(); + await agent.poHomeChannel.content.btnModalConfirm.click(); + await expect(agent.poHomeChannel.toastSuccess).toBeVisible(); + }); + }); +}); diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts index a6949a9a32f7..c4ecce4cc8b7 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -110,6 +110,10 @@ export class HomeContent { return this.page.locator('[data-qa-id="ToolBoxAction-balloon-arrow-top-right"]'); } + get btnSendTranscript(): Locator { + return this.page.locator('[data-qa-id="ToolBoxAction-mail-arrow-top-right"]'); + } + get inputModalAgentUserName(): Locator { return this.page.locator('#modal-root input:nth-child(1)'); }