Skip to content

Commit 5e821ad

Browse files
test: add tags to the room (RocketChat#36869)
Co-authored-by: Aleksander Nicacio da Silva <6494543+aleksandernsilva@users.noreply.github.com>
1 parent 48d1442 commit 5e821ad

3 files changed

Lines changed: 162 additions & 8 deletions

File tree

apps/meteor/client/views/omnichannel/directory/chats/ChatInfo/ChatInfo.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function ChatInfo({ id, route }: ChatInfoProps) {
5353
const { data: room } = useOmnichannelRoomInfo(id); // FIXME: `room` is serialized, but we need to deserialize it
5454

5555
const {
56+
_id: roomId,
5657
ts,
5758
tags,
5859
closedAt,
@@ -121,15 +122,17 @@ function ChatInfo({ id, route }: ChatInfoProps) {
121122
{departmentId && <DepartmentField departmentId={departmentId} />}
122123
{tags && tags.length > 0 && (
123124
<InfoPanelField>
124-
<InfoPanelLabel>{t('Tags')}</InfoPanelLabel>
125+
<InfoPanelLabel id={`${roomId}-tags`}>{t('Tags')}</InfoPanelLabel>
125126
<InfoPanelText>
126-
{tags.map((tag) => (
127-
<Box key={tag} mie={4} display='inline'>
128-
<Tag style={{ display: 'inline' }} disabled>
129-
{tag}
130-
</Tag>
131-
</Box>
132-
))}
127+
<ul aria-labelledby={`${roomId}-tags`}>
128+
{tags.map((tag) => (
129+
<Box is='li' key={tag} mie={4} display='inline'>
130+
<Tag style={{ display: 'inline' }} disabled>
131+
{tag}
132+
</Tag>
133+
</Box>
134+
))}
135+
</ul>
133136
</InfoPanelText>
134137
</InfoPanelField>
135138
)}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
});

apps/meteor/tests/e2e/page-objects/omnichannel-room-info.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ export class OmnichannelRoomInfo {
5353
return this.page.getByRole('option', { name, exact: true }).click();
5454
}
5555

56+
get inputTags(): Locator {
57+
return this.page.getByRole('textbox', { name: 'Select an option' });
58+
}
59+
60+
optionTags(name: string): Locator {
61+
return this.page.getByRole('option', { name, exact: true });
62+
}
63+
64+
async selectTag(name: string): Promise<void> {
65+
await this.optionTags(name).click();
66+
}
67+
68+
getTagInfoByLabel(label: string): Locator {
69+
return this.dialogRoomInfo.getByRole('list', { name: 'Tags' }).getByText(label, { exact: true });
70+
}
71+
5672
getBadgeIndicator(name: string, title: string): Locator {
5773
return this.homeSidenav.getSidebarItemByName(name).getByTitle(title);
5874
}

0 commit comments

Comments
 (0)