diff --git a/apps/meteor/tests/e2e/omnichannel/omnichannel-priorities-sidebar.spec.ts b/apps/meteor/tests/e2e/omnichannel/omnichannel-priorities-sidebar.spec.ts index 559d248896337b13b9dd23c2421944d36426e2dc..d1572f7b5ce7390adc9ce2ced32a45c32bbab7fb 100644 --- a/apps/meteor/tests/e2e/omnichannel/omnichannel-priorities-sidebar.spec.ts +++ b/apps/meteor/tests/e2e/omnichannel/omnichannel-priorities-sidebar.spec.ts @@ -1,10 +1,10 @@ import { faker } from '@faker-js/faker'; import { IS_EE } from '../config/constants'; -import { createAuxContext } from '../fixtures/createAuxContext'; import { Users } from '../fixtures/userStates'; -import { HomeChannel, OmnichannelLiveChat } from '../page-objects'; +import { HomeChannel } from '../page-objects'; import { OmnichannelRoomInfo } from '../page-objects/omnichannel-room-info'; +import { createConversation } from '../utils/omnichannel/rooms'; import { test, expect } from '../utils/test'; const NEW_USER = { @@ -19,7 +19,7 @@ test.skip(!IS_EE, 'Omnichannel Priorities > Enterprise Only'); test.use({ storageState: Users.user1.state }); -test.describe.serial('Omnichannel Priorities [Sidebar]', () => { +test.describe.serial('OC - Priorities [Sidebar]', () => { let poHomeChannel: HomeChannel; let poRoomInfo: OmnichannelRoomInfo; @@ -33,14 +33,18 @@ test.describe.serial('Omnichannel Priorities [Sidebar]', () => { ).every((res) => expect(res.status()).toBe(200)); }); + test.beforeEach(async ({ page }) => { + poHomeChannel = new HomeChannel(page); + poRoomInfo = new OmnichannelRoomInfo(page); + }); + test.beforeEach(async ({ page }) => { await page.goto('/'); await page.locator('.main-content').waitFor(); }); - test.beforeEach(async ({ page }) => { - poHomeChannel = new HomeChannel(page); - poRoomInfo = new OmnichannelRoomInfo(page); + test.beforeEach(async ({ api }) => { + await createConversation(api, { visitorName: NEW_USER.name }); }); test.afterAll(async ({ api }) => { @@ -53,22 +57,11 @@ test.describe.serial('Omnichannel Priorities [Sidebar]', () => { ).every((res) => expect(res.status()).toBe(200)); }); - test('Priority updates with sidebar', async ({ browser, api }) => { + test('OC - Priorities [Sidebar] - Update conversation priority', async ({ page }) => { const systemMessage = poHomeChannel.content.lastSystemMessageBody; + await page.emulateMedia({ reducedMotion: 'reduce' }); - await test.step('Initiate conversation', async () => { - const poLivechat = await createAuxContext(browser, Users.user1, '/livechat', false).then( - ({ page }) => new OmnichannelLiveChat(page, api), - ); - await poLivechat.openLiveChat(); - await poLivechat.sendMessage(NEW_USER, false); - await poLivechat.onlineAgentMessage.type('this_a_test_message_from_visitor'); - await poLivechat.btnSendMessageToOnlineAgent.click(); - await poHomeChannel.sidenav.getSidebarItemByName(NEW_USER.name).click(); - await poLivechat.page.close(); - }); - - await test.step('Queue: Sidebar priority change', async () => { + await test.step('expect to change inquiry priority using sidebar menu', async () => { await poHomeChannel.sidenav.getSidebarItemByName(NEW_USER.name).click(); await expect(poRoomInfo.getLabel('Priority')).not.toBeVisible(); @@ -88,9 +81,10 @@ test.describe.serial('Omnichannel Priorities [Sidebar]', () => { await expect(poRoomInfo.getInfo('Unprioritized')).not.toBeVisible(); }); - await test.step('Subscription: Sidebar priority change', async () => { + await test.step('expect to change subscription priority using sidebar menu', async () => { await poHomeChannel.content.takeOmnichannelChatButton.click(); await systemMessage.locator('text="joined the channel"').waitFor(); + await page.waitForTimeout(500); await expect(poRoomInfo.getLabel('Priority')).not.toBeVisible(); diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts index 4f3d7b4886ebd43eb091f374c86aea2ce5ff184e..af860162bbdf798442c6eb06d32e6013285b3327 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts @@ -41,8 +41,8 @@ export class HomeSidenav { async selectPriority(name: string, priority: string) { const sidebarItem = this.getSidebarItemByName(name); - await sidebarItem.hover(); - await sidebarItem.locator(`[data-testid="menu"]`).click(); + await sidebarItem.focus(); + await sidebarItem.locator('.rcx-sidebar-item__menu').click(); await this.page.locator(`li[value="${priority}"]`).click(); } diff --git a/apps/meteor/tests/e2e/utils/omnichannel/rooms.ts b/apps/meteor/tests/e2e/utils/omnichannel/rooms.ts new file mode 100644 index 0000000000000000000000000000000000000000..bce8c7a4478199f4253b308a1c48bc0790523b9a --- /dev/null +++ b/apps/meteor/tests/e2e/utils/omnichannel/rooms.ts @@ -0,0 +1,100 @@ +import { faker } from '@faker-js/faker'; + +import { BaseTest } from '../test'; + +type UpdateRoomParams = { roomId: string; visitorId: string; tags: string[] }; + +type CreateRoomParams = { tags?: string[]; visitorToken: string; agentId?: string }; + +type CreateVisitorParams = { token: string; department?: string; name: string; email: string }; + +type CreateConversationParams = { visitorName?: string; visitorToken?: string; agentId?: string; departmentId?: string }; + +export const updateRoom = async (api: BaseTest['api'], { roomId, visitorId, tags }: UpdateRoomParams) => { + if (!roomId) { + throw Error('Unable to update room info, missing room id'); + } + + if (!visitorId) { + throw Error('Unable to update room info, missing visitor id'); + } + + return api.post('/livechat/room.saveInfo', { + guestData: { _id: visitorId }, + roomData: { _id: roomId, tags }, + }); +}; + +export const createRoom = async (api: BaseTest['api'], { visitorToken, agentId }: CreateRoomParams) => { + const response = await api.get('/livechat/room', { + token: visitorToken, + agentId, + }); + + if (response.status() !== 200) { + throw Error(`Unable to create room [http status: ${response.status()}]`); + } + + const data = await response.json(); + + return { + response, + data: data.room, + delete: async () => { + await api.post('/livechat/room.close', { rid: data.room._id, token: visitorToken }); + await api.post('/method.call/livechat:removeRoom', { + message: JSON.stringify({ + msg: 'method', + id: '16', + method: 'livechat:removeRoom', + params: [data.room._id], + }), + }); + }, + }; +}; + +export const createVisitor = async (api: BaseTest['api'], params: CreateVisitorParams) => + api.post('/livechat/visitor', { visitor: params }); + +export const sendMessageToRoom = async ( + api: BaseTest['api'], + { visitorToken, roomId, message }: { visitorToken: string; roomId: string; message?: string }, +) => + api.post(`/livechat/message`, { + token: visitorToken, + rid: roomId, + msg: message || faker.lorem.sentence(), + }); + +export const createConversation = async ( + api: BaseTest['api'], + { visitorName, visitorToken, agentId, departmentId }: CreateConversationParams, +) => { + const token = visitorToken || faker.string.uuid(); + const visitorRes = await createVisitor(api, { + name: visitorName || faker.person.firstName(), + email: faker.internet.email(), + token, + ...(departmentId && { department: departmentId }), + }); + + if (visitorRes.status() !== 200) { + throw Error(`Unable to create visitor [http status: ${visitorRes.status()}]`); + } + + const { data: room } = await createRoom(api, { visitorToken: token, agentId }); + + const messageRes = await sendMessageToRoom(api, { visitorToken: token, roomId: room._id }); + + if (messageRes.status() !== 200) { + throw Error(`Unable to send message to room [http status: ${messageRes.status()}]`); + } + + const { visitor } = await visitorRes.json(); + + return { + room, + visitor, + }; +};