|
| 1 | +import { createFakeVisitor } from '../../mocks/data'; |
| 2 | +import { IS_EE } from '../config/constants'; |
| 3 | +import { Users } from '../fixtures/userStates'; |
| 4 | +import { HomeOmnichannel } from '../page-objects'; |
| 5 | +import { createAgent } from '../utils/omnichannel/agents'; |
| 6 | +import { addAgentToDepartment, createDepartment } from '../utils/omnichannel/departments'; |
| 7 | +import { createConversation } from '../utils/omnichannel/rooms'; |
| 8 | +import { createTag } from '../utils/omnichannel/tags'; |
| 9 | +import { test, expect } from '../utils/test'; |
| 10 | + |
| 11 | +const visitorA = createFakeVisitor(); |
| 12 | +const visitorB = createFakeVisitor(); |
| 13 | + |
| 14 | +test.use({ storageState: Users.user1.state }); |
| 15 | + |
| 16 | +test.describe('OC - Tags Visibility', () => { |
| 17 | + test.skip(!IS_EE, 'OC - Tags Visibility > Enterprise Edition Only'); |
| 18 | + |
| 19 | + let poOmnichannel: HomeOmnichannel; |
| 20 | + let conversations: Awaited<ReturnType<typeof createConversation>>[] = []; |
| 21 | + let departmentA: Awaited<ReturnType<typeof createDepartment>>; |
| 22 | + let departmentB: Awaited<ReturnType<typeof createDepartment>>; |
| 23 | + let agent: Awaited<ReturnType<typeof createAgent>>; |
| 24 | + let tags: Awaited<ReturnType<typeof createTag>>[] = []; |
| 25 | + |
| 26 | + test.beforeAll('Create departments', async ({ api }) => { |
| 27 | + departmentA = await createDepartment(api, { name: 'Department A' }); |
| 28 | + departmentB = await createDepartment(api, { name: 'Department B' }); |
| 29 | + }); |
| 30 | + |
| 31 | + test.beforeAll('Create agent', async ({ api }) => { |
| 32 | + agent = await createAgent(api, 'user1'); |
| 33 | + }); |
| 34 | + |
| 35 | + test.beforeAll('Add agents to departments', async ({ api }) => { |
| 36 | + await Promise.all([ |
| 37 | + addAgentToDepartment(api, { department: departmentA.data, agentId: 'user1' }), |
| 38 | + addAgentToDepartment(api, { department: departmentB.data, agentId: 'user1' }), |
| 39 | + ]); |
| 40 | + }); |
| 41 | + |
| 42 | + test.beforeAll('Create tags', async ({ api }) => { |
| 43 | + tags = await Promise.all([ |
| 44 | + createTag(api, { name: 'TagA', description: 'tag A', departments: [departmentA.data._id] }), |
| 45 | + createTag(api, { name: 'TagB', description: 'tag B', departments: [departmentB.data._id] }), |
| 46 | + createTag(api, { name: 'GlobalTag', description: 'public tag', departments: [] }), |
| 47 | + createTag(api, { |
| 48 | + name: 'SharedTag', |
| 49 | + description: 'tag for both departments', |
| 50 | + departments: [departmentA.data._id, departmentB.data._id], |
| 51 | + }), |
| 52 | + ]); |
| 53 | + }); |
| 54 | + |
| 55 | + test.beforeAll('Create conversations', async ({ api }) => { |
| 56 | + conversations = await Promise.all([ |
| 57 | + createConversation(api, { visitorName: visitorA.name, agentId: 'user1', departmentId: departmentA.data._id }), |
| 58 | + createConversation(api, { visitorName: visitorB.name, agentId: 'user1', departmentId: departmentB.data._id }), |
| 59 | + ]); |
| 60 | + }); |
| 61 | + |
| 62 | + test.beforeEach(async ({ page }) => { |
| 63 | + poOmnichannel = new HomeOmnichannel(page); |
| 64 | + await page.goto('/'); |
| 65 | + }); |
| 66 | + |
| 67 | + test.afterAll(async () => { |
| 68 | + await Promise.all(conversations.map((conversation) => conversation.delete())); |
| 69 | + await Promise.all(tags.map((tag) => tag.delete())); |
| 70 | + await agent.delete(); |
| 71 | + await departmentA.delete(); |
| 72 | + await departmentB.delete(); |
| 73 | + }); |
| 74 | + |
| 75 | + test('Verify agent should see correct tags based on department association', async () => { |
| 76 | + await test.step('Agent opens room', async () => { |
| 77 | + await poOmnichannel.sidenav.getSidebarItemByName(visitorA.name).click(); |
| 78 | + }); |
| 79 | + |
| 80 | + await test.step('should not be able to see tags field', async () => { |
| 81 | + await expect(poOmnichannel.roomInfo.getLabel('Tags')).not.toBeVisible(); |
| 82 | + }); |
| 83 | + |
| 84 | + await test.step('check available tags', async () => { |
| 85 | + await poOmnichannel.roomInfo.btnEditRoomInfo.click(); |
| 86 | + await expect(poOmnichannel.roomInfo.dialogEditRoom).toBeVisible(); |
| 87 | + await poOmnichannel.roomInfo.inputTags.click(); |
| 88 | + }); |
| 89 | + |
| 90 | + await test.step('Should see TagA (department A specific)', async () => { |
| 91 | + await expect(poOmnichannel.roomInfo.optionTags('TagA')).toBeVisible(); |
| 92 | + }); |
| 93 | + |
| 94 | + await test.step('Should see SharedTag (both departments)', async () => { |
| 95 | + await expect(poOmnichannel.roomInfo.optionTags('SharedTag')).toBeVisible(); |
| 96 | + }); |
| 97 | + |
| 98 | + await test.step('Should see Public Tags for all chats (no department restriction)', async () => { |
| 99 | + await expect(poOmnichannel.roomInfo.optionTags('GlobalTag')).toBeVisible(); |
| 100 | + }); |
| 101 | + |
| 102 | + await test.step('Should not see TagB (department B specific)', async () => { |
| 103 | + await expect(poOmnichannel.roomInfo.optionTags('TagB')).not.toBeVisible(); |
| 104 | + }); |
| 105 | + |
| 106 | + await test.step('add tags and save', async () => { |
| 107 | + await poOmnichannel.roomInfo.selectTag('TagA'); |
| 108 | + await poOmnichannel.roomInfo.selectTag('GlobalTag'); |
| 109 | + await poOmnichannel.roomInfo.btnSaveEditRoom.click(); |
| 110 | + }); |
| 111 | + |
| 112 | + await test.step('verify selected tags are displayed under room information', async () => { |
| 113 | + await expect(poOmnichannel.roomInfo.getLabel('Tags')).toBeVisible(); |
| 114 | + await expect(poOmnichannel.roomInfo.getTagInfoByLabel('TagA')).toBeVisible(); |
| 115 | + await expect(poOmnichannel.roomInfo.getTagInfoByLabel('GlobalTag')).toBeVisible(); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + test('Verify tags visibility for agent associated with multiple departments', async () => { |
| 120 | + await test.step('Open room info', async () => { |
| 121 | + await poOmnichannel.sidenav.getSidebarItemByName(visitorB.name).click(); |
| 122 | + await poOmnichannel.roomInfo.btnEditRoomInfo.click(); |
| 123 | + await expect(poOmnichannel.roomInfo.dialogEditRoom).toBeVisible(); |
| 124 | + await poOmnichannel.roomInfo.inputTags.click(); |
| 125 | + }); |
| 126 | + |
| 127 | + await test.step('Agent associated with DepartmentB should be able to see tags for Department B', async () => { |
| 128 | + await expect(poOmnichannel.roomInfo.optionTags('TagB')).toBeVisible(); |
| 129 | + }); |
| 130 | + |
| 131 | + await test.step('Agent associated with DepartmentB should not be able to see tags for DepartmentA', async () => { |
| 132 | + await expect(poOmnichannel.roomInfo.optionTags('TagA')).not.toBeVisible(); |
| 133 | + }); |
| 134 | + }); |
| 135 | +}); |
0 commit comments