Files
upstream-rocketchat/apps/meteor/tests/e2e/omnichannel/omnichannel-canned-responses-usage.spec.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

213 lines
8.4 KiB
TypeScript

import { faker } from '@faker-js/faker';
import type { Page } from '@playwright/test';
import { createFakeVisitor } from '../../mocks/data';
import { IS_EE } from '../config/constants';
import { createAuxContext } from '../fixtures/createAuxContext';
import { Users } from '../fixtures/userStates';
import { HomeOmnichannel } from '../page-objects';
import { OmnichannelLiveChat } from '../page-objects/omnichannel';
import { test, expect } from '../utils/test';
test.describe('OC - Canned Responses Usage', () => {
test.skip(!IS_EE, 'Enterprise Only');
let poLiveChat: OmnichannelLiveChat;
let newVisitor: { email: string; name: string };
let agent: { page: Page; poHomeChannel: HomeOmnichannel };
let cannedResponseId: string;
let placeholderResponseId: string;
let secondResponseId: string;
const cannedResponseName = `test-${faker.string.uuid()}`;
const cannedResponseText = 'Hello! Welcome to our support chat. How can I assist you today?';
const cannedResponseWithPlaceholder = `Hello {{contact.name}}, thank you for contacting us!`;
const placeholderResponseName = `placeholder-${faker.string.uuid()}`;
const secondResponseName = `followup-${faker.string.uuid()}`;
const secondResponseText = 'Is there anything else I can help you with today?';
test.beforeAll(async ({ api, browser }) => {
await Promise.all([
api.post('/livechat/users/agent', { username: 'user1' }),
api.post('/livechat/users/manager', { username: 'user1' }),
api.post('/canned-responses', {
shortcut: cannedResponseName,
text: cannedResponseText,
scope: 'global',
tags: ['tag'],
}),
api.post('/canned-responses', {
shortcut: placeholderResponseName,
text: cannedResponseWithPlaceholder,
scope: 'global',
tags: ['tag'],
}),
api.post('/canned-responses', {
shortcut: secondResponseName,
text: secondResponseText,
scope: 'global',
tags: ['tag'],
}),
]);
const { page } = await createAuxContext(browser, Users.user1);
agent = { page, poHomeChannel: new HomeOmnichannel(page) };
const [mainResponse, placeholderResponse, secondResponse] = await Promise.all([
api.get('/canned-responses', { shortcut: cannedResponseName }),
api.get('/canned-responses', { shortcut: placeholderResponseName }),
api.get('/canned-responses', { shortcut: secondResponseName }),
]);
const [mainData, placeholderData, secondData] = await Promise.all([
mainResponse.json(),
placeholderResponse.json(),
secondResponse.json(),
]);
cannedResponseId = mainData.cannedResponses[0]._id;
placeholderResponseId = placeholderData.cannedResponses[0]._id;
secondResponseId = secondData.cannedResponses[0]._id;
});
test.beforeEach(async ({ page, api }) => {
newVisitor = createFakeVisitor();
poLiveChat = new OmnichannelLiveChat(page, api);
});
test.afterEach('close livechat conversation', async () => {
await poLiveChat.closeChat();
});
test.afterAll(async ({ api }) => {
await Promise.all([
api.delete('/livechat/users/agent/user1'),
api.delete('/livechat/users/manager/user1'),
api.delete('/canned-responses', { _id: cannedResponseId }),
api.delete('/canned-responses', { _id: placeholderResponseId }),
api.delete('/canned-responses', { _id: secondResponseId }),
agent.poHomeChannel.page.close(),
]);
});
test('OC - Canned Responses Usage - Create response and use in chat', async () => {
await test.step('expect to start a visitor conversation', async () => {
await poLiveChat.goto();
await poLiveChat.openLiveChat();
await poLiveChat.sendMessage(newVisitor, false);
await poLiveChat.onlineAgentMessage.fill('this_a_test_message_from_visitor');
await poLiveChat.btnSendMessageToOnlineAgent.click();
});
await test.step('expect agent to receive and open the chat', async () => {
await agent.poHomeChannel.navbar.openChat(newVisitor.name);
});
await test.step('expect to use the canned response in the chat', async () => {
await agent.poHomeChannel.content.selectCannedResponse(cannedResponseName);
});
await test.step('expect canned response text to appear in message composer', async () => {
await expect(agent.poHomeChannel.composer.inputMessage).toHaveValue(`${cannedResponseText} `);
});
await test.step('expect agent to be able to send the canned response message', async () => {
await agent.poHomeChannel.content.sendMessage(cannedResponseText);
});
await test.step('expect visitor to receive the canned response message', async () => {
await expect(poLiveChat.txtChatMessage(cannedResponseText)).toBeVisible();
});
});
test('OC - Canned Responses Usage - Use response with placeholder replacement', async () => {
await test.step('expect to start a new visitor conversation', async () => {
await poLiveChat.goto();
await poLiveChat.openLiveChat();
await poLiveChat.sendMessage(newVisitor, false);
await poLiveChat.onlineAgentMessage.fill('test_message_for_placeholder');
await poLiveChat.btnSendMessageToOnlineAgent.click();
});
await test.step('expect agent to receive and open the chat', async () => {
await agent.poHomeChannel.navbar.openChat(newVisitor.name);
});
await test.step('expect to use the canned response with placeholder', async () => {
await agent.poHomeChannel.content.selectCannedResponse(placeholderResponseName);
});
await test.step('expect placeholder to be replaced with actual visitor name', async () => {
await agent.poHomeChannel.content.sendMessage(cannedResponseWithPlaceholder);
await expect(poLiveChat.txtChatMessage('{{contact.name}}')).not.toBeVisible();
});
});
test('OC - Canned Responses Usage - Modify response before sending', async () => {
const modifiedText = `Additionally, I'll be happy to help you with any specific questions.`;
await test.step('expect to start a visitor conversation', async () => {
await poLiveChat.goto();
await poLiveChat.openLiveChat();
await poLiveChat.sendMessage(newVisitor, false);
await poLiveChat.onlineAgentMessage.fill('test_message_for_modification');
await poLiveChat.btnSendMessageToOnlineAgent.click();
});
await test.step('expect agent to open the chat', async () => {
await agent.poHomeChannel.navbar.openChat(newVisitor.name);
});
await test.step('expect to use existing canned response and modify it', async () => {
await agent.poHomeChannel.content.selectCannedResponse(cannedResponseName);
});
await test.step('expect to modify the canned response text before sending', async () => {
await agent.poHomeChannel.composer.inputMessage.click();
await agent.page.keyboard.press('End');
await agent.poHomeChannel.composer.inputMessage.pressSequentially(modifiedText);
await expect(agent.poHomeChannel.composer.inputMessage).toHaveValue(`${cannedResponseText} ${modifiedText}`);
});
await test.step('expect to send the modified message', async () => {
await agent.page.keyboard.press('Enter');
});
await test.step('expect visitor to receive the modified message', async () => {
await expect(poLiveChat.txtChatMessage(`${cannedResponseText} ${modifiedText}`)).toBeVisible();
});
});
test('OC - Canned Responses Usage - Use multiple responses in sequence', async () => {
await test.step('expect to start a visitor conversation', async () => {
await poLiveChat.goto();
await poLiveChat.openLiveChat();
await poLiveChat.sendMessage(newVisitor, false);
await poLiveChat.onlineAgentMessage.fill('test_message_for_sequence');
await poLiveChat.btnSendMessageToOnlineAgent.click();
});
await test.step('expect agent to open the chat', async () => {
await agent.poHomeChannel.navbar.openChat(newVisitor.name);
});
await test.step('expect to use first canned response', async () => {
await agent.poHomeChannel.content.selectCannedResponse(cannedResponseName);
await expect(agent.poHomeChannel.composer.inputMessage).toHaveValue(`${cannedResponseText} `);
await agent.page.keyboard.press('Enter');
});
await test.step('expect to use second canned response', async () => {
await agent.poHomeChannel.content.selectCannedResponse(secondResponseName);
await expect(agent.poHomeChannel.composer.inputMessage).toHaveValue(`${secondResponseText} `);
await agent.page.keyboard.press('Enter');
});
await test.step('expect visitor to receive both messages in correct order', async () => {
await expect(poLiveChat.txtChatMessage(cannedResponseText)).toBeVisible();
await expect(poLiveChat.txtChatMessage(secondResponseText)).toBeVisible();
});
});
});