Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 25, 2024
1 parent 72d747b commit aa52f0d
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ callbacks.add(
}

await saveQueueInquiry(inquiry);

return LivechatInquiry.findOneById(inquiry._id);
},
callbacks.priority.HIGH,
'livechat-before-routing-chat',
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
globalSetup: require.resolve('./tests/e2e/config/global-setup.ts'),
use: {
channel: 'chromium',
headless: true,
headless: false,
ignoreHTTPSErrors: true,
trace: 'retain-on-failure',
baseURL: constants.BASE_URL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { createFakeVisitor } from '../../mocks/data';
import { IS_EE } from '../config/constants';
import { createAuxContext } from '../fixtures/createAuxContext';
import { Users } from '../fixtures/userStates';
import { HomeOmnichannel, OmnichannelLiveChat } from '../page-objects';
import { test, expect } from '../utils/test';

const firstVisitor = createFakeVisitor();

const secondVisitor = createFakeVisitor();

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

test.describe('OC - Livechat - Queue Management', () => {
test.skip(!IS_EE, 'Enterprise Only');

let poHomeOmnichannel: HomeOmnichannel;
let poLiveChat: OmnichannelLiveChat;

const waitingQueueMessage = 'This is a message from Waiting Queue';
const queuePosition1 = 'Your spot is #1';
const queuePosition2 = 'Your spot is #2';

test.beforeAll(async ({ api, browser }) => {
await Promise.all([
api.post('/settings/Livechat_Routing_Method', { value: 'Auto_Selection' }),
api.post('/settings/Livechat_accept_chats_with_no_agents', { value: true }),
api.post('/settings/Livechat_waiting_queue', { value: true }),
api.post('/settings/Livechat_waiting_queue_message', { value: waitingQueueMessage }),
api.post('/livechat/users/agent', { username: 'user1' }),
]);

const { page: omniPage } = await createAuxContext(browser, Users.user1, '/', true);
poHomeOmnichannel = new HomeOmnichannel(omniPage);

// Agent will be offline for these tests
await poHomeOmnichannel.sidenav.switchOmnichannelStatus('offline');
});

test.beforeEach(async ({ browser, api }) => {
const context = await browser.newContext();
const page2 = await context.newPage();

poLiveChat = new OmnichannelLiveChat(page2, api);
await poLiveChat.page.goto('/livechat');
});

test.afterAll(async ({ api }) => {
await Promise.all([
api.post('/settings/Livechat_waiting_queue', { value: false }),
api.post('/settings/Livechat_waiting_queue_message', { value: '' }),
api.delete('/livechat/users/agent/user1'),
]);
await poHomeOmnichannel.page.close();
});

test.describe('OC - Queue Management - Auto Selection', () => {
let poLiveChat2: OmnichannelLiveChat;

test.beforeEach(async ({ browser, api }) => {
const context = await browser.newContext();
const page = await context.newPage();
poLiveChat2 = new OmnichannelLiveChat(page, api);
await poLiveChat2.page.goto('/livechat');
});

test.afterEach(async () => {
await poLiveChat2.closeChat();
await poLiveChat2.page.close();
await poLiveChat.closeChat();
await poLiveChat.page.close();
});

test('Update user position on Queue', async () => {
await test.step('should start livechat session', async () => {
await poLiveChat.openAnyLiveChatAndSendMessage({
liveChatUser: firstVisitor,
message: 'Test message',
isOffline: false,
});
});

await test.step('expect to receive Waiting Queue message on chat', async () => {
await expect(poLiveChat.page.locator(`div >> text=${waitingQueueMessage}`)).toBeVisible();
});

await test.step('expect to be on spot #1', async () => {
await expect(poLiveChat.page.locator(`div[role='alert'] >> text=${queuePosition1}`)).toBeVisible();
});

await test.step('should start secondary livechat session', async () => {
await poLiveChat2.openAnyLiveChatAndSendMessage({
liveChatUser: secondVisitor,
message: 'Test message',
isOffline: false,
});
});

await test.step('should start secondary livechat on spot #2', async () => {
await expect(poLiveChat2.page.locator(`div[role='alert'] >> text=${queuePosition2}`)).toBeVisible();
});

await test.step('should start the queue by making the agent available again', async () => {
await poHomeOmnichannel.sidenav.switchOmnichannelStatus('online');
});

await test.step('user1 should get assigned to the first chat', async () => {
await expect(poLiveChat.page.locator(`div[role='alert'] >> text=${queuePosition1}`)).not.toBeVisible();
});

await test.step('secondary session should be on position #1', async () => {
await expect(poLiveChat2.page.locator(`div[role='alert'] >> text=${queuePosition1}`)).toBeVisible();
});

await test.step('secondary session should be taken by user1', async () => {
await expect(poLiveChat2.page.locator(`div[role='alert'] >> text=${queuePosition1}`)).not.toBeVisible();
});
});
});
});
30 changes: 30 additions & 0 deletions docker-compose-local-monolith.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3.8'

services:
rocketchat:
platform: linux/amd64
image: rocketchat/rocket.chat:6.9.2
environment:
- TEST_MODE=true
- EXIT_UNHANDLEDPROMISEREJECTION=true
- 'MONGO_URL=${MONGO_URL}'
- OVERWRITE_SETTING_Log_Level=2
extra_hosts:
- 'host.docker.internal:host-gateway'
depends_on:
- mongo
ports:
- '3000:3000'

mongo:
image: docker.io/bitnami/mongodb:7.0
restart: on-failure
environment:
MONGODB_REPLICA_SET_MODE: primary
MONGODB_REPLICA_SET_NAME: ${MONGODB_REPLICA_SET_NAME:-rs0}
MONGODB_PORT_NUMBER: ${MONGODB_PORT_NUMBER:-27017}
MONGODB_INITIAL_PRIMARY_HOST: ${MONGODB_INITIAL_PRIMARY_HOST:-mongo}
MONGODB_INITIAL_PRIMARY_PORT_NUMBER: ${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}
MONGODB_ADVERTISED_HOSTNAME: ${MONGODB_ADVERTISED_HOSTNAME:-mongo}
MONGODB_ENABLE_JOURNAL: ${MONGODB_ENABLE_JOURNAL:-true}
ALLOW_EMPTY_PASSWORD: ${ALLOW_EMPTY_PASSWORD:-yes}

0 comments on commit aa52f0d

Please sign in to comment.