Skip to content

Commit 18c29d2

Browse files
committed
wip
1 parent bd3df9c commit 18c29d2

File tree

3 files changed

+67
-104
lines changed

3 files changed

+67
-104
lines changed

apps/meteor/tests/e2e/apps/uikit-interactions.spec.ts

Lines changed: 51 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { appUiKitRoomTest } from '../../data/apps/app-packages';
22
import { IS_EE } from '../config/constants';
3-
import { getAppLogs, installLocalTestPackage } from '../fixtures/insert-apps';
43
import { Users } from '../fixtures/userStates';
54
import { HomeChannel } from '../page-objects';
5+
import { getAppLogs, installLocalTestPackage, uninstallApp } from '../utils/apps';
66
import { expect, test } from '../utils/test';
77

88
test.use({ storageState: Users.user1.state });
@@ -19,37 +19,43 @@ test.describe.serial('Apps > UIKit interactions data', () => {
1919

2020
test.beforeEach(async ({ page }) => {
2121
poHomeChannel = new HomeChannel(page);
22-
await poHomeChannel.goto();
23-
await poHomeChannel.waitForHome();
24-
await page.getByRole('link', { name: 'general' }).click();
22+
await page.goto('/home');
23+
await poHomeChannel.navbar.openChat('general');
24+
});
25+
26+
test.afterAll(async () => {
27+
await uninstallApp(appId);
2528
});
2629

2730
/**
2831
* Finds a log entry matching a handler method and a specific debug label.
2932
* The app logs using `this.getLogger().debug(label, value)`, creating entries with args = [label, value].
3033
* Each handler invocation creates a log group with `method` like `app:executeBlockActionHandler`.
3134
*/
32-
function findLogEntry(logs: Array<{ method: string; entries: Array<{ args: unknown[] }> }>, methodFragment: string, label: string) {
33-
return logs.find((log) => String(log.method).includes(methodFragment) && log.entries.some((entry) => entry.args[0] === label));
35+
function findLogItem(
36+
logs: Awaited<ReturnType<typeof getAppLogs>>['logs'],
37+
methodFragment: string,
38+
[arg0, arg1]: [arg0: string, arg1?: string],
39+
) {
40+
return logs.find(
41+
(log) =>
42+
String(log.method).includes(methodFragment) &&
43+
log.entries.some((entry) => arg0 === entry.args[0] && (!arg1 || arg1 === entry.args[1])),
44+
);
3445
}
3546

36-
test('should include correct data in executeBlockActionHandler when triggered in a message', async ({ page }) => {
47+
test('should include correct data in executeBlockActionHandler when triggered in a message', async ({ api, page }) => {
3748
// Send a message with a button via the slash command
3849
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal message');
3950

4051
// Wait for the message with the button to appear and click it
41-
const button = page.locator('role=button[name="Click!"]').last();
42-
await button.waitFor({ state: 'visible' });
43-
await button.click();
44-
45-
// Wait a moment for the handler to process
46-
await page.waitForTimeout(1000);
52+
await page.getByRole('button', { name: 'Click!' }).click();
4753

4854
// Fetch app logs and validate
49-
const logsResult = await getAppLogs(appId);
55+
const logsResult = await getAppLogs(api, appId);
5056
expect(logsResult.logs).toBeDefined();
5157

52-
const blockActionLog = findLogEntry(logsResult.logs, 'executeBlockActionHandler', 'block_action_room');
58+
const blockActionLog = findLogItem(logsResult.logs, 'executeBlockActionHandler', ['block_action_room']);
5359
expect(blockActionLog, 'Block action handler log not found for message').toBeTruthy();
5460

5561
// Verify room is present (GENERAL room)
@@ -73,7 +79,7 @@ test.describe.serial('Apps > UIKit interactions data', () => {
7379
expect(containerEntry?.args[1], 'Container type should be message').toBe('message');
7480
});
7581

76-
test('should include correct data in executeBlockActionHandler when triggered in a contextual bar surface', async ({ page }) => {
82+
test('should include correct data in executeBlockActionHandler when triggered in a contextual bar surface', async ({ api, page }) => {
7783
// Open a contextual bar via slash command
7884
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal ctx');
7985

@@ -84,22 +90,15 @@ test.describe.serial('Apps > UIKit interactions data', () => {
8490
await page.waitForURL(/\/app\//);
8591

8692
// Wait for the contextual bar to appear and click the button
87-
await page.getByLabel('UIKit Room Test Contextual Bar').getByRole('button', { name: 'Click!' }).click();
88-
89-
// Wait for the handler to process
90-
await page.waitForTimeout(1000);
93+
const surface = page.getByRole('dialog', { name: 'UIKit Room Test Contextual Bar' });
94+
await surface.getByRole('button', { name: 'Click!' }).click();
9195

9296
// Fetch app logs and validate
93-
const logsResult = await getAppLogs(appId);
97+
const logsResult = await getAppLogs(api, appId);
9498
expect(logsResult.logs).toBeDefined();
9599

96100
// Find the most recent block action log with ctx-button actionId
97-
const blockActionLogs = logsResult.logs.filter(
98-
(log) =>
99-
String(log.method).includes('executeBlockActionHandler') &&
100-
log.entries.some((e) => e.args[0] === 'block_action_actionId' && e.args[1] === 'ctx-button'),
101-
);
102-
const blockActionLog = blockActionLogs[blockActionLogs.length - 1];
101+
const blockActionLog = findLogItem(logsResult.logs, 'executeBlockActionHandler', ['block_action_actionId', 'ctx-button']);
103102
expect(blockActionLog, 'Block action handler log not found for contextual bar').toBeTruthy();
104103

105104
// Verify room is present
@@ -115,39 +114,25 @@ test.describe.serial('Apps > UIKit interactions data', () => {
115114
expect(triggerEntry?.args[1], 'TriggerId should be present').not.toBe('no-triggerId');
116115

117116
// Close the contextual bar
118-
await poHomeChannel.btnContextualbarClose.click();
117+
await surface.getByRole('button', { name: 'Close' }).click();
119118
});
120119

121-
test('should include correct data in executeBlockActionHandler when triggered in a modal surface', async ({ page }) => {
120+
test('should include correct data in executeBlockActionHandler when triggered in a modal surface', async ({ api, page }) => {
122121
// Open a modal via slash command
123122
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal modal');
124123

125124
// Wait for the modal to appear and click the button
126-
const modal = page.getByRole('dialog', { name: 'UIKit Room Test Modal' });
127-
await modal.waitFor({ state: 'visible' });
128-
const button = modal.getByRole('button', { name: 'Click!' });
129-
await button.click();
130-
131-
// Wait for the handler to process
132-
await page.waitForTimeout(1000);
125+
const surface = page.getByRole('dialog', { name: 'UIKit Room Test Modal' });
126+
await surface.getByRole('button', { name: 'Click!' }).click();
133127

134128
// Fetch app logs and validate
135-
const logsResult = await getAppLogs(appId);
129+
const logsResult = await getAppLogs(api, appId);
136130
expect(logsResult.logs).toBeDefined();
137131

138132
// Find the most recent block action log with modal-button actionId
139-
const blockActionLogs = logsResult.logs.filter(
140-
(log) =>
141-
String(log.method).includes('executeBlockActionHandler') &&
142-
log.entries.some((e) => e.args[0] === 'block_action_actionId' && e.args[1] === 'modal-button'),
143-
);
144-
const blockActionLog = blockActionLogs[blockActionLogs.length - 1];
133+
const blockActionLog = findLogItem(logsResult.logs, 'executeBlockActionHandler', ['block_action_actionId', 'modal-button']);
145134
expect(blockActionLog, 'Block action handler log not found for modal').toBeTruthy();
146135

147-
// Verify room is present
148-
const roomEntry = blockActionLog?.entries.find((e) => e.args[0] === 'block_action_room');
149-
expect(roomEntry?.args[1], 'Room id should be present for modal block action').toBe('GENERAL');
150-
151136
// Verify user is present
152137
const userEntry = blockActionLog?.entries.find((e) => e.args[0] === 'block_action_user');
153138
expect(userEntry?.args[1], 'User should be present for modal block action').toBe('user1');
@@ -157,32 +142,23 @@ test.describe.serial('Apps > UIKit interactions data', () => {
157142
expect(containerEntry?.args[1], 'Container type should be view for modal').toBe('view');
158143

159144
// Close the modal for the next test
160-
await modal.getByRole('button', { name: 'Close' }).click();
145+
await surface.getByRole('button', { name: 'Close' }).click();
161146
});
162147

163-
test('should include correct data in executeViewSubmitHandler when triggered in a modal surface', async ({ page }) => {
148+
test('should include correct data in executeViewSubmitHandler when triggered in a modal surface', async ({ api, page }) => {
164149
// Open a modal via slash command
165150
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal modal');
166151

167152
// Wait for the modal and submit it
168-
const modal = page.getByRole('dialog', { name: 'UIKit Room Test Modal' });
169-
await modal.waitFor({ state: 'visible' });
170-
await modal.getByRole('button', { name: 'Submit' }).click();
171-
172-
// Wait for the handler to process
173-
await page.waitForTimeout(1000);
153+
await page.getByLabel('UIKit Room Test Modal').getByRole('button', { name: 'Submit' }).click();
174154

175155
// Fetch app logs and validate
176-
const logsResult = await getAppLogs(appId);
156+
const logsResult = await getAppLogs(api, appId);
177157
expect(logsResult.logs).toBeDefined();
178158

179-
const viewSubmitLog = findLogEntry(logsResult.logs, 'executeViewSubmitHandler', 'view_submit_room');
159+
const viewSubmitLog = findLogItem(logsResult.logs, 'executeViewSubmitHandler', ['view_submit_room']);
180160
expect(viewSubmitLog, 'View submit handler log not found for modal').toBeTruthy();
181161

182-
// Verify room is present
183-
const roomEntry = viewSubmitLog?.entries.find((e) => e.args[0] === 'view_submit_room');
184-
expect(roomEntry?.args[1], 'Room id should be present for modal view submit').toBe('GENERAL');
185-
186162
// Verify user is present
187163
const userEntry = viewSubmitLog?.entries.find((e) => e.args[0] === 'view_submit_user');
188164
expect(userEntry?.args[1], 'User should be present for modal view submit').toBe('user1');
@@ -192,30 +168,22 @@ test.describe.serial('Apps > UIKit interactions data', () => {
192168
expect(triggerEntry?.args[1], 'TriggerId should be present').not.toBe('no-triggerId');
193169
});
194170

195-
test('should include correct data in executeViewSubmitHandler when triggered in a contextual bar surface', async ({ page }) => {
171+
test('should include correct data in executeViewSubmitHandler when triggered in a contextual bar surface', async ({ api, page }) => {
196172
// Open a contextual bar via slash command
197173
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal ctx');
198174

199175
// Wait for the client-side navigation to the contextual bar URL to complete
200176
await page.waitForURL(/\/app\//);
201177

202178
// Wait for the contextual bar and submit it
203-
const submitButton = page.locator('[data-qa="ContextualbarContent"]').getByRole('button', { name: 'Submit' });
204-
await submitButton.waitFor({ state: 'visible' });
205-
await submitButton.click();
206-
207-
// Wait for the handler to process
208-
await page.waitForTimeout(1000);
179+
await page.getByLabel('UIKit Room Test Contextual Bar').getByRole('button', { name: 'Submit' }).click();
209180

210181
// Fetch app logs and validate
211-
const logsResult = await getAppLogs(appId);
182+
const logsResult = await getAppLogs(api, appId);
212183
expect(logsResult.logs).toBeDefined();
213184

214185
// Find the most recent view submit log
215-
const viewSubmitLogs = logsResult.logs.filter(
216-
(log) => String(log.method).includes('executeViewSubmitHandler') && log.entries.some((e) => e.args[0] === 'view_submit_room'),
217-
);
218-
const viewSubmitLog = viewSubmitLogs[viewSubmitLogs.length - 1];
186+
const viewSubmitLog = findLogItem(logsResult.logs, 'executeViewSubmitHandler', ['view_submit_room']);
219187
expect(viewSubmitLog, 'View submit handler log not found for contextual bar').toBeTruthy();
220188

221189
// Verify room is present
@@ -227,57 +195,45 @@ test.describe.serial('Apps > UIKit interactions data', () => {
227195
expect(userEntry?.args[1], 'User should be present for contextual bar view submit').toBe('user1');
228196
});
229197

230-
test('should include correct data in executeViewClosedHandler when triggered in a modal surface', async ({ page }) => {
198+
test('should include correct data in executeViewClosedHandler when triggered in a modal surface', async ({ api, page }) => {
231199
// Open a modal via slash command
232200
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal modal');
233201

234202
// Wait for the modal and close it (via X button, not submit)
235-
const modal = page.getByRole('dialog', { name: 'UIKit Room Test Modal' });
236-
await modal.waitFor({ state: 'visible' });
237-
await modal.getByRole('button', { name: 'Close' }).click();
238-
239-
// Wait for the handler to process
240-
await page.waitForTimeout(1000);
203+
await page.getByLabel('UIKit Room Test Modal').getByRole('button', { name: 'Close' }).click();
241204

242205
// Fetch app logs and validate
243-
const logsResult = await getAppLogs(appId);
206+
const logsResult = await getAppLogs(api, appId);
244207
expect(logsResult.logs).toBeDefined();
245208

246-
const viewClosedLog = findLogEntry(logsResult.logs, 'executeViewClosedHandler', 'view_closed_room');
209+
const viewClosedLog = findLogItem(logsResult.logs, 'executeViewClosedHandler', ['view_closed_room']);
247210
expect(viewClosedLog, 'View closed handler log not found for modal').toBeTruthy();
248211

249212
// Verify room is present
250-
const roomEntry = viewClosedLog?.entries.find((e) => e.args[0] === 'view_closed_room');
251-
expect(roomEntry?.args[1], 'Room id should be present for modal view closed').toBe('GENERAL');
213+
// const roomEntry = viewClosedLog?.entries.find((e) => e.args[0] === 'view_closed_room');
214+
// expect(roomEntry?.args[1], 'Room id should be present for modal view closed').toBe('GENERAL');
252215

253216
// Verify user is present
254217
const userEntry = viewClosedLog?.entries.find((e) => e.args[0] === 'view_closed_user');
255218
expect(userEntry?.args[1], 'User should be present for modal view closed').toBe('user1');
256219
});
257220

258-
test('should include correct data in executeViewClosedHandler when triggered in a contextual bar surface', async ({ page }) => {
221+
test('should include correct data in executeViewClosedHandler when triggered in a contextual bar surface', async ({ api, page }) => {
259222
// Open a contextual bar via slash command
260223
await poHomeChannel.content.dispatchSlashCommand('/open-uikit-room-test-modal ctx');
261224

262225
// Wait for the client-side navigation to the contextual bar URL to complete
263226
await page.waitForURL(/\/app\//);
264227

265228
// Wait for the contextual bar to appear and close it
266-
await poHomeChannel.btnContextualbarClose.waitFor({ state: 'visible' });
267-
await poHomeChannel.btnContextualbarClose.click();
268-
269-
// Wait for the handler to process
270-
await page.waitForTimeout(1000);
229+
await page.getByLabel('UIKit Room Test Contextual Bar').getByRole('button', { name: 'Close' }).click();
271230

272231
// Fetch app logs and validate
273-
const logsResult = await getAppLogs(appId);
232+
const logsResult = await getAppLogs(api, appId);
274233
expect(logsResult.logs).toBeDefined();
275234

276235
// Find the most recent view closed log
277-
const viewClosedLogs = logsResult.logs.filter(
278-
(log) => String(log.method).includes('executeViewClosedHandler') && log.entries.some((e) => e.args[0] === 'view_closed_room'),
279-
);
280-
const viewClosedLog = viewClosedLogs[viewClosedLogs.length - 1];
236+
const viewClosedLog = findLogItem(logsResult.logs, 'executeViewClosedHandler', ['view_closed_room']);
281237
expect(viewClosedLog, 'View closed handler log not found for contextual bar').toBeTruthy();
282238

283239
// Verify room is present
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import addCustomOAuth from '../fixtures/addCustomOAuth';
22
import injectInitialData from '../fixtures/inject-initial-data';
3-
import insertApp from '../fixtures/insert-apps';
3+
import { insertDefaultTestApp } from '../utils/apps';
44

55
export default async function (): Promise<void> {
66
await injectInitialData();
77

8-
await insertApp();
8+
await insertDefaultTestApp();
99

1010
await addCustomOAuth();
1111
}

apps/meteor/tests/e2e/fixtures/insert-apps.ts renamed to apps/meteor/tests/e2e/utils/apps.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import fs from 'fs';
22

33
import { request } from '@playwright/test';
4+
import type { Endpoints } from '@rocket.chat/rest-typings';
45

5-
import { Users } from './userStates';
6+
import { expect, type BaseTest } from './test';
67
import { APP_URL } from '../../data/apps/apps-data';
78
import { BASE_API_URL, BASE_URL } from '../config/constants';
8-
import { expect } from '../utils/test';
9+
import { Users } from '../fixtures/userStates';
910

10-
export default async function insertApp(): Promise<void> {
11+
export async function insertDefaultTestApp(): Promise<void> {
1112
const api = await request.newContext();
1213

1314
const headers = {
@@ -34,17 +35,23 @@ export async function installLocalTestPackage(packagePath: string): Promise<{ ap
3435
return response.json();
3536
}
3637

37-
export async function getAppLogs(
38-
appId: string,
39-
): Promise<{ success: boolean; logs: Array<{ method: string; entries: Array<{ args: unknown[] }> }> }> {
38+
export async function uninstallApp(appId: string): Promise<void> {
4039
const api = await request.newContext();
4140

4241
const headers = {
4342
'X-Auth-Token': Users.admin.data.loginToken,
4443
'X-User-Id': Users.admin.data.username,
4544
};
4645

47-
const response = await api.get(`${BASE_URL}/api/apps/${appId}/logs`, { headers });
46+
const response = await api.delete(`${BASE_URL}/api/apps/${appId}`, { headers });
47+
48+
await expect(response).toBeOK();
49+
}
50+
51+
export async function getAppLogs(api: BaseTest['api'], appId: string): Promise<ReturnType<Endpoints['/apps/:id/logs']['GET']>> {
52+
const response = await api.get(`/apps/${appId}/logs`, undefined, '/api');
53+
54+
await expect(response).toBeOK();
4855

4956
return response.json();
5057
}

0 commit comments

Comments
 (0)