import { faker } from '@faker-js/faker'; import type { Page } from '@playwright/test'; import { IS_EE } from '../config/constants'; import { Users } from '../fixtures/userStates'; import { OmnichannelUnits } from '../page-objects/omnichannel'; import { setSettingValueById } from '../utils'; import { createAgent } from '../utils/omnichannel/agents'; import { createDepartment } from '../utils/omnichannel/departments'; import { createMonitor } from '../utils/omnichannel/monitors'; import { createOrUpdateUnit } from '../utils/omnichannel/units'; import { test, expect } from '../utils/test'; test.use({ storageState: Users.admin.state }); test.describe('OC - Manage Units', () => { test.skip(!IS_EE, 'OC - Manage Units > Enterprise Edition Only'); let poOmnichannelUnits: OmnichannelUnits; let department: Awaited>; let department2: Awaited>; let agent: Awaited>; let monitor: Awaited>; let monitor2: Awaited>; test.beforeAll(async ({ api }) => { department = await createDepartment(api); department2 = await createDepartment(api); }); test.beforeAll(async ({ api }) => { agent = await createAgent(api, 'user2'); }); test.beforeAll(async ({ api }) => { monitor = await createMonitor(api, 'user2'); monitor2 = await createMonitor(api, 'user3'); }); test.beforeAll(async ({ api }) => { await setSettingValueById(api, 'Omnichannel_enable_department_removal', true); }); test.afterAll(async ({ api }) => { await department.delete(); await department2.delete(); await monitor.delete(); await monitor2.delete(); await agent.delete(); await setSettingValueById(api, 'Omnichannel_enable_department_removal', false); }); test.beforeEach(async ({ page }: { page: Page }) => { poOmnichannelUnits = new OmnichannelUnits(page); await poOmnichannelUnits.goto(); }); test('OC - Manage Units - Create Unit', async () => { const unitName = faker.string.uuid(); await test.step('expect correct form default state', async () => { await poOmnichannelUnits.createNew(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await expect(poOmnichannelUnits.manageUnit.btnSave).toBeEnabled(); await expect(poOmnichannelUnits.manageUnit.btnCancel).toBeEnabled(); await poOmnichannelUnits.manageUnit.btnCancel.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); }); await test.step('expect to create new unit', async () => { await poOmnichannelUnits.createNew(); await poOmnichannelUnits.manageUnit.inputName.fill(unitName); await poOmnichannelUnits.manageUnit.selectVisibility('public'); await poOmnichannelUnits.manageUnit.selectDepartment(department.data.name); await poOmnichannelUnits.manageUnit.selectMonitor('user2'); await expect(poOmnichannelUnits.manageUnit.findMonitorChipOption('user2')).toBeVisible(); await poOmnichannelUnits.manageUnit.btnSave.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); await poOmnichannelUnits.search(unitName); await expect(poOmnichannelUnits.table.findRowByName(unitName)).toBeVisible(); }); await test.step('expect to delete unit', async () => { await poOmnichannelUnits.deleteUnit(unitName); await expect(poOmnichannelUnits.table.findRowByName(unitName)).toHaveCount(0); }); }); test('OC - Manage Units - Edit unit name', async ({ api }) => { const unitName = faker.string.uuid(); const editedUnitName = faker.string.uuid(); const unit = await test.step('expect to create new unit', async () => { const { data: newUnit } = await createOrUpdateUnit(api, { name: unitName, visibility: 'public', monitors: [{ monitorId: monitor.data._id, username: 'user2' }], departments: [{ departmentId: department.data._id }], }); return newUnit; }); await poOmnichannelUnits.goto(); await test.step('expect to edit unit', async () => { await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.table.findRowByName(unit.name).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await poOmnichannelUnits.manageUnit.inputName.fill(editedUnitName); await poOmnichannelUnits.manageUnit.btnSave.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); await expect(poOmnichannelUnits.inputSearch).toBeVisible(); await poOmnichannelUnits.search(editedUnitName); await expect(poOmnichannelUnits.table.findRowByName(editedUnitName)).toBeVisible(); }); await test.step('expect to add another monitor to list', async () => { await poOmnichannelUnits.table.findRowByName(editedUnitName).click(); await poOmnichannelUnits.manageUnit.selectMonitor('user3'); await poOmnichannelUnits.manageUnit.btnSave.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); await poOmnichannelUnits.search(editedUnitName); await poOmnichannelUnits.table.findRowByName(editedUnitName).click(); await expect(poOmnichannelUnits.manageUnit.findMonitorChipOption('user2')).toBeVisible(); await expect(poOmnichannelUnits.manageUnit.findMonitorChipOption('user3')).toBeVisible(); }); await test.step('expect unit to remove one of the two monitors', async () => { await poOmnichannelUnits.search(editedUnitName); await poOmnichannelUnits.table.findRowByName(editedUnitName).click(); await poOmnichannelUnits.manageUnit.removeMonitor('user2'); await poOmnichannelUnits.manageUnit.btnSave.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); await poOmnichannelUnits.search(editedUnitName); await poOmnichannelUnits.table.findRowByName(editedUnitName).click(); await expect(poOmnichannelUnits.manageUnit.findMonitorChipOption('user3')).toBeVisible(); await expect(poOmnichannelUnits.manageUnit.findMonitorChipOption('user2')).toBeHidden(); }); await test.step('expect to delete unit', async () => { await poOmnichannelUnits.table.findRowByName(editedUnitName).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await poOmnichannelUnits.deleteUnit(editedUnitName); await expect(poOmnichannelUnits.table.findRowByName(editedUnitName)).not.toBeVisible(); }); }); test('OC - Manage Units - Edit unit departments', async ({ api, page }) => { const unit = await test.step('expect to create new unit', async () => { const { data: unit } = await createOrUpdateUnit(api, { name: faker.string.uuid(), visibility: 'public', monitors: [{ monitorId: monitor.data._id, username: 'user2' }], departments: [{ departmentId: department.data._id }], }); return unit; }); await page.reload(); await test.step('expect to add unit departments', async () => { await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.table.findRowByName(unit.name).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await poOmnichannelUnits.manageUnit.selectDepartment(department2.data.name); await poOmnichannelUnits.manageUnit.btnSave.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.table.findRowByName(unit.name).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await expect(poOmnichannelUnits.manageUnit.findDepartmentsChipOption(department2.data.name)).toBeVisible(); await poOmnichannelUnits.manageUnit.findDepartmentsChipOption(department2.data.name).hover(); await expect(page.getByRole('tooltip', { name: department2.data.name })).toBeVisible(); await poOmnichannelUnits.manageUnit.close(); }); await test.step('expect to remove unit departments', async () => { await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.table.findRowByName(unit.name).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await poOmnichannelUnits.manageUnit.selectDepartment(department2.data.name); await poOmnichannelUnits.manageUnit.btnSave.click(); await expect(poOmnichannelUnits.manageUnit.root).not.toBeVisible(); await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.table.findRowByName(unit.name).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await expect(poOmnichannelUnits.manageUnit.findDepartmentsChipOption(department2.data.name)).toBeHidden(); await poOmnichannelUnits.manageUnit.close(); }); await test.step('expect to delete unit', async () => { await poOmnichannelUnits.search(unit.name); await poOmnichannelUnits.table.findRowByName(unit.name).click(); await expect(poOmnichannelUnits.manageUnit.root).toBeVisible(); await poOmnichannelUnits.deleteUnit(unit.name); await expect(poOmnichannelUnits.table.findRowByName(unit.name)).not.toBeVisible(); }); }); });