Skip to content

Commit 44351f5

Browse files
dougfabrisgaolin1
authored andcommitted
test: Replace magic tag names in e2e tests (RocketChat#37932)
1 parent ae319ae commit 44351f5

File tree

4 files changed

+47
-43
lines changed

4 files changed

+47
-43
lines changed

apps/meteor/tests/e2e/omnichannel/omnichannel-assign-room-tags.spec.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ test.describe('OC - Tags Visibility', () => {
2121
let departmentA: Awaited<ReturnType<typeof createDepartment>>;
2222
let departmentB: Awaited<ReturnType<typeof createDepartment>>;
2323
let agent: Awaited<ReturnType<typeof createAgent>>;
24-
let tags: Awaited<ReturnType<typeof createTag>>[] = [];
24+
let tagA: Awaited<ReturnType<typeof createTag>>;
25+
let tagB: Awaited<ReturnType<typeof createTag>>;
26+
let globalTag: Awaited<ReturnType<typeof createTag>>;
27+
let sharedTag: Awaited<ReturnType<typeof createTag>>;
2528

2629
test.beforeAll('Create departments', async ({ api }) => {
2730
departmentA = await createDepartment(api, { name: 'Department A' });
@@ -40,16 +43,12 @@ test.describe('OC - Tags Visibility', () => {
4043
});
4144

4245
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-
]);
46+
tagA = await createTag(api, { departments: [departmentA.data._id] });
47+
tagB = await createTag(api, { departments: [departmentB.data._id] });
48+
globalTag = await createTag(api, { departments: [] });
49+
sharedTag = await createTag(api, {
50+
departments: [departmentA.data._id, departmentB.data._id],
51+
});
5352
});
5453

5554
test.beforeAll('Create conversations', async ({ api }) => {
@@ -66,7 +65,7 @@ test.describe('OC - Tags Visibility', () => {
6665

6766
test.afterAll(async () => {
6867
await Promise.all(conversations.map((conversation) => conversation.delete()));
69-
await Promise.all(tags.map((tag) => tag.delete()));
68+
await Promise.all([tagA, tagB, globalTag, sharedTag].map((tag) => tag.delete()));
7069
await agent.delete();
7170
await departmentA.delete();
7271
await departmentB.delete();
@@ -88,31 +87,31 @@ test.describe('OC - Tags Visibility', () => {
8887
});
8988

9089
await test.step('Should see TagA (department A specific)', async () => {
91-
await expect(poOmnichannel.roomInfo.optionTags('TagA')).toBeVisible();
90+
await expect(poOmnichannel.roomInfo.optionTags(tagA.data.name)).toBeVisible();
9291
});
9392

9493
await test.step('Should see SharedTag (both departments)', async () => {
95-
await expect(poOmnichannel.roomInfo.optionTags('SharedTag')).toBeVisible();
94+
await expect(poOmnichannel.roomInfo.optionTags(sharedTag.data.name)).toBeVisible();
9695
});
9796

9897
await test.step('Should see Public Tags for all chats (no department restriction)', async () => {
99-
await expect(poOmnichannel.roomInfo.optionTags('GlobalTag')).toBeVisible();
98+
await expect(poOmnichannel.roomInfo.optionTags(globalTag.data.name)).toBeVisible();
10099
});
101100

102101
await test.step('Should not see TagB (department B specific)', async () => {
103-
await expect(poOmnichannel.roomInfo.optionTags('TagB')).not.toBeVisible();
102+
await expect(poOmnichannel.roomInfo.optionTags(tagB.data.name)).not.toBeVisible();
104103
});
105104

106105
await test.step('add tags and save', async () => {
107-
await poOmnichannel.roomInfo.selectTag('TagA');
108-
await poOmnichannel.roomInfo.selectTag('GlobalTag');
106+
await poOmnichannel.roomInfo.selectTag(tagA.data.name);
107+
await poOmnichannel.roomInfo.selectTag(globalTag.data.name);
109108
await poOmnichannel.roomInfo.btnSaveEditRoom.click();
110109
});
111110

112111
await test.step('verify selected tags are displayed under room information', async () => {
113112
await expect(poOmnichannel.roomInfo.getLabel('Tags')).toBeVisible();
114-
await expect(poOmnichannel.roomInfo.getTagInfoByLabel('TagA')).toBeVisible();
115-
await expect(poOmnichannel.roomInfo.getTagInfoByLabel('GlobalTag')).toBeVisible();
113+
await expect(poOmnichannel.roomInfo.getTagInfoByLabel(tagA.data.name)).toBeVisible();
114+
await expect(poOmnichannel.roomInfo.getTagInfoByLabel(globalTag.data.name)).toBeVisible();
116115
});
117116
});
118117

@@ -125,11 +124,11 @@ test.describe('OC - Tags Visibility', () => {
125124
});
126125

127126
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();
127+
await expect(poOmnichannel.roomInfo.optionTags(tagB.data.name)).toBeVisible();
129128
});
130129

131130
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();
131+
await expect(poOmnichannel.roomInfo.optionTags(tagA.data.name)).not.toBeVisible();
133132
});
134133
});
135134
});

apps/meteor/tests/e2e/omnichannel/omnichannel-contact-center-chats.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ test.describe('OC - Contact Center Chats [Auto Selection]', async () => {
2323
let departments: Awaited<ReturnType<typeof createDepartment>>[];
2424
let conversations: Awaited<ReturnType<typeof createConversation>>[];
2525
let agents: Awaited<ReturnType<typeof createAgent>>[];
26-
let tags: Awaited<ReturnType<typeof createTag>>[];
26+
let tagA: Awaited<ReturnType<typeof createTag>>;
27+
let tagB: Awaited<ReturnType<typeof createTag>>;
2728

2829
// Allow manual on hold
2930
test.beforeAll(async ({ api }) => {
@@ -62,9 +63,10 @@ test.describe('OC - Contact Center Chats [Auto Selection]', async () => {
6263

6364
// Create tags
6465
test.beforeAll(async ({ api }) => {
65-
tags = await Promise.all([createTag(api, { name: 'tagA' }), createTag(api, { name: 'tagB' })]);
66+
tagA = await createTag(api);
67+
tagB = await createTag(api);
6668

67-
tags.forEach((res) => expect(res.response.status()).toBe(200));
69+
[tagA, tagB].forEach((res) => expect(res.response.status()).toBe(200));
6870
});
6971

7072
// Create rooms
@@ -96,12 +98,12 @@ test.describe('OC - Contact Center Chats [Auto Selection]', async () => {
9698
updateRoom(api, {
9799
roomId: conversationA.room._id,
98100
visitorId: conversationA.visitor._id,
99-
tags: ['tagA'],
101+
tags: [tagA.data.name],
100102
}),
101103
updateRoom(api, {
102104
roomId: conversationB.room._id,
103105
visitorId: conversationB.visitor._id,
104-
tags: ['tagB'],
106+
tags: [tagB.data.name],
105107
}),
106108
]);
107109
});
@@ -122,7 +124,7 @@ test.describe('OC - Contact Center Chats [Auto Selection]', async () => {
122124
// Delete agents
123125
...agents.map((agent) => agent.delete()),
124126
// Delete tags
125-
...tags.map((tag) => tag.delete()),
127+
...[tagA, tagB].map((tag) => tag.delete()),
126128
// Reset setting
127129
api.post('/settings/Livechat_allow_manual_on_hold', { value: false }),
128130
api.post('/settings/Livechat_allow_manual_on_hold_upon_agent_engagement_only', { value: true }),

apps/meteor/tests/e2e/omnichannel/omnichannel-contact-center-filters.spec.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ test.describe('OC - Contact Center', async () => {
2626
let departments: Awaited<ReturnType<typeof createDepartment>>[];
2727
let conversations: Awaited<ReturnType<typeof createConversation>>[];
2828
let agents: Awaited<ReturnType<typeof createAgent>>[];
29-
let tags: Awaited<ReturnType<typeof createTag>>[];
29+
let tagA: Awaited<ReturnType<typeof createTag>>;
30+
let tagB: Awaited<ReturnType<typeof createTag>>;
3031
let units: Awaited<ReturnType<typeof createOrUpdateUnit>>[];
3132
let poContacts: OmnichannelContacts;
3233
let poOmniSection: OmnichannelSection;
@@ -68,9 +69,10 @@ test.describe('OC - Contact Center', async () => {
6869

6970
// Create tags
7071
test.beforeAll(async ({ api }) => {
71-
tags = await Promise.all([createTag(api, { name: 'tagA' }), createTag(api, { name: 'tagB' })]);
72+
tagA = await createTag(api);
73+
tagB = await createTag(api);
7274

73-
tags.forEach((res) => expect(res.response.status()).toBe(200));
75+
[tagA, tagB].forEach((res) => expect(res.response.status()).toBe(200));
7476
});
7577

7678
// Create unit
@@ -118,12 +120,12 @@ test.describe('OC - Contact Center', async () => {
118120
updateRoom(api, {
119121
roomId: conversationA.room._id,
120122
visitorId: conversationA.visitor._id,
121-
tags: ['tagA'],
123+
tags: [tagA.data.name],
122124
}),
123125
updateRoom(api, {
124126
roomId: conversationB.room._id,
125127
visitorId: conversationB.visitor._id,
126-
tags: ['tagB'],
128+
tags: [tagB.data.name],
127129
}),
128130
]);
129131
});
@@ -132,12 +134,12 @@ test.describe('OC - Contact Center', async () => {
132134
await Promise.all([
133135
// Delete conversations
134136
...conversations.map((conversation) => conversation.delete()),
135-
// // Delete departments
137+
// Delete departments
136138
...departments.map((department) => department.delete()),
137139
// Delete agents
138140
...agents.map((agent) => agent.delete()),
139141
// Delete tags
140-
...tags.map((tag) => tag.delete()),
142+
...[tagA, tagB].map((tag) => tag.delete()),
141143
// Delete units
142144
...units.map((unit) => unit.delete()),
143145
// Reset setting
@@ -264,19 +266,19 @@ test.describe('OC - Contact Center', async () => {
264266
});
265267

266268
await test.step('expect to filter by tags', async () => {
267-
await poContacts.selectTag('tagA');
269+
await poContacts.selectTag(tagA.data.name);
268270
await expect(poContacts.findRowByName(visitorA)).toBeVisible();
269271
await expect(poContacts.findRowByName(visitorB)).not.toBeVisible();
270272

271-
await poContacts.selectTag('tagB');
273+
await poContacts.selectTag(tagB.data.name);
272274
await expect(poContacts.findRowByName(visitorA)).toBeVisible();
273275
await expect(poContacts.findRowByName(visitorB)).toBeVisible();
274276

275-
await poContacts.removeTag('tagA');
277+
await poContacts.removeTag(tagA.data.name);
276278
await expect(poContacts.findRowByName(visitorB)).toBeVisible();
277279
await expect(poContacts.findRowByName(visitorA)).not.toBeVisible();
278280

279-
await poContacts.removeTag('tagB');
281+
await poContacts.removeTag(tagB.data.name);
280282
await expect(poContacts.findRowByName(visitorB)).toBeVisible();
281283
await expect(poContacts.findRowByName(visitorA)).toBeVisible();
282284
});
@@ -312,7 +314,7 @@ test.describe('OC - Contact Center', async () => {
312314
await poContacts.selectServedBy('user1');
313315
await poContacts.selectStatus('onhold');
314316
await poContacts.selectDepartment(departmentA.name);
315-
await poContacts.selectTag('tagA');
317+
await poContacts.selectTag(tagA.data.name);
316318
await poContacts.selectUnit(unitA.name);
317319

318320
await expect(poContacts.findRowByName(visitorA)).toBeVisible();

apps/meteor/tests/e2e/utils/omnichannel/tags.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { faker } from '@faker-js/faker';
12
import type { ILivechatTag } from '@rocket.chat/core-typings';
23

34
import type { BaseTest } from '../test';
@@ -11,12 +12,12 @@ type CreateTagParams = {
1112

1213
const removeTag = async (api: BaseTest['api'], id: string) => api.post('/livechat/tags.delete', { id });
1314

14-
export const createTag = async (api: BaseTest['api'], { id = null, name, description = '', departments = [] }: CreateTagParams = {}) => {
15+
export const createTag = async (api: BaseTest['api'], { id = null, name, description, departments = [] }: CreateTagParams = {}) => {
1516
const response = await api.post('/livechat/tags.save', {
1617
_id: id,
1718
tagData: {
18-
name,
19-
description,
19+
name: name ?? faker.string.alpha({ length: 8 }),
20+
description: description ?? faker.string.alpha({ length: 16 }),
2021
},
2122
...(departments.length > 0 && { tagDepartments: departments }),
2223
});

0 commit comments

Comments
 (0)