Skip to content

Commit 4b8d0df

Browse files
authored
test: Remove Utils page object (RocketChat#37371)
1 parent 276ec51 commit 4b8d0df

18 files changed

Lines changed: 139 additions & 125 deletions

apps/meteor/tests/e2e/admin-users-role-management.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ test.describe('Admin > Users Role Management', () => {
3636
await test.step('should be visible in the All tab', async () => {
3737
await admin.getTabByName().click();
3838
await expect(admin.getUserRowByUsername(userWithoutAdminAccess.data.username)).toBeVisible();
39+
await expect(admin.getUserRowByUsername(userWithoutAdminAccess.data.username)).toHaveCount(1);
3940
});
4041

4142
await test.step('make a user admin', async () => {
42-
await admin.openUserActionMenu(userWithoutAdminAccess.data.username);
43-
await admin.menuItemMakeAdmin.click();
43+
await admin.dispatchUserAction(userWithoutAdminAccess.data.username, 'Make Admin');
4444
await expect(poToastBar.alert).toBeVisible();
4545
await expect(poToastBar.alert).toHaveText('User is now an admin');
4646
});
@@ -60,8 +60,7 @@ test.describe('Admin > Users Role Management', () => {
6060
});
6161

6262
await test.step('remove admin role', async () => {
63-
await admin.openUserActionMenu(userWithAdminAccess.data.username);
64-
await admin.menuItemRemoveAdmin.click();
63+
await admin.dispatchUserAction(userWithAdminAccess.data.username, 'Remove Admin');
6564
await expect(poToastBar.alert).toBeVisible();
6665
await expect(poToastBar.alert).toHaveText('User is no longer an admin');
6766
});

apps/meteor/tests/e2e/admin-users-status-management.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BrowserContext, Page } from '@playwright/test';
22

33
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
44
import { Users } from './fixtures/userStates';
5-
import { AdminUsers, Registration, Utils } from './page-objects';
5+
import { AdminUsers, Registration, Authenticated } from './page-objects';
66
import { test, expect } from './utils/test';
77
import type { ITestUser } from './utils/user-helpers';
88
import { createTestUser } from './utils/user-helpers';
@@ -22,13 +22,13 @@ test.describe.serial('Admin > Users', () => {
2222
let context: BrowserContext;
2323
let page: Page;
2424
let poRegistration: Registration;
25-
let poUtils: Utils;
25+
let poAuth: Authenticated;
2626

2727
test.beforeAll(async ({ browser }) => {
2828
context = await browser.newContext();
2929
page = await context.newPage();
3030
poRegistration = new Registration(page);
31-
poUtils = new Utils(page);
31+
poAuth = new Authenticated(page);
3232
});
3333

3434
test.afterAll(async () => {
@@ -44,7 +44,7 @@ test.describe.serial('Admin > Users', () => {
4444
});
4545

4646
await test.step('Assert user is logged in', async () => {
47-
await expect(poUtils.mainContent).toBeVisible();
47+
await poAuth.waitForDisplay();
4848
});
4949
});
5050
});

apps/meteor/tests/e2e/admin-users.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test.describe('Admin > Users', () => {
2222
admin = new AdminUsers(page);
2323
await page.goto('/admin/users');
2424
});
25+
2526
test('New user shows in correct tabs when deactivated', async () => {
2627
await admin.inputSearchUsers.fill(user.data.username);
2728

@@ -47,17 +48,15 @@ test.describe('Admin > Users', () => {
4748

4849
await test.step('should move from Pending to Deactivated tab', async () => {
4950
await admin.getTabByName('Pending').click();
50-
await admin.btnMoreActionsMenu.click();
51-
await admin.menuItemDeactivated.click();
51+
await admin.dispatchUserAction(user.data.username, 'Deactivate');
5252
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
5353
await admin.getTabByName('Deactivated').click();
5454
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
5555
});
5656

5757
await test.step('should move from Deactivated to Pending tab', async () => {
5858
await admin.getTabByName('Deactivated').click();
59-
await admin.btnMoreActionsMenu.click();
60-
await admin.menuItemActivate.click();
59+
await admin.dispatchUserAction(user.data.username, 'Activate');
6160
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
6261
await admin.getTabByName('Pending').click();
6362
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();

apps/meteor/tests/e2e/administration.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ import type { IUser } from '@rocket.chat/apps-engine/definition/users';
33

44
import { IS_EE } from './config/constants';
55
import { Users } from './fixtures/userStates';
6-
import { Utils, AdminUsers, AdminRoles, AdminRooms, AdminThirdPartyLogin, AdminIntegrations } from './page-objects';
6+
import { AdminUsers, AdminRoles, AdminRooms, AdminThirdPartyLogin, AdminIntegrations } from './page-objects';
7+
import { ToastMessages } from './page-objects/fragments';
78
import { createTargetChannel, setSettingValueById } from './utils';
89
import { test, expect } from './utils/test';
910

1011
test.use({ storageState: Users.admin.state });
1112

1213
test.describe.parallel('administration', () => {
13-
let poUtils: Utils;
1414
let targetChannel: string;
1515

16-
test.beforeEach(async ({ page }) => {
17-
poUtils = new Utils(page);
18-
});
19-
2016
test.describe('Workspace', () => {
2117
test.beforeEach(async ({ page }) => {
2218
await page.goto('/admin/info');
@@ -119,6 +115,11 @@ test.describe.parallel('administration', () => {
119115
const emptyChannelName = faker.string.uuid();
120116
let ownerUser: IUser;
121117
let user: IUser;
118+
let poToastMessage: ToastMessages;
119+
120+
test.beforeEach(({ page }) => {
121+
poToastMessage = new ToastMessages(page);
122+
});
122123

123124
test.beforeAll(async ({ api }) => {
124125
const createUserResponse = await api.post('/users.create', {
@@ -168,7 +169,7 @@ test.describe.parallel('administration', () => {
168169
await expect(page.getByRole('dialog').getByRole('button', { name: 'Delete' })).toBeVisible();
169170

170171
await page.getByRole('dialog').getByRole('button', { name: 'Delete' }).click();
171-
await expect(poUtils.toastBarSuccess).toBeVisible();
172+
await poToastMessage.waitForDisplay();
172173
await expect(page.getByRole('heading', { name: 'No users' })).toBeVisible();
173174
});
174175

@@ -177,7 +178,8 @@ test.describe.parallel('administration', () => {
177178
await expect(page.getByRole('dialog', { name: 'Are you sure?' })).toBeVisible();
178179

179180
await page.getByRole('dialog').getByRole('button', { name: 'Delete' }).click();
180-
await expect(poUtils.toastBarSuccess).toBeVisible();
181+
182+
await poToastMessage.waitForDisplay();
181183
await expect(page.getByRole('heading', { name: 'No users' })).toBeVisible();
182184
});
183185
});

apps/meteor/tests/e2e/delete-account.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
2-
import { AccountProfile, Registration, Utils } from './page-objects';
2+
import { AccountProfile, Registration, Authenticated } from './page-objects';
33
import { ToastBar } from './page-objects/toastBar';
44
import { test, expect } from './utils/test';
55
import { createTestUser, type ITestUser } from './utils/user-helpers';
@@ -8,7 +8,7 @@ test.describe('Delete Own Account', () => {
88
let poAccountProfile: AccountProfile;
99
let poRegistration: Registration;
1010
let poToastBar: ToastBar;
11-
let poUtils: Utils;
11+
let poAuth: Authenticated;
1212
let userToDelete: ITestUser;
1313
let userWithInvalidPassword: ITestUser;
1414
let userWithoutPermissions: ITestUser;
@@ -25,7 +25,7 @@ test.describe('Delete Own Account', () => {
2525
poAccountProfile = new AccountProfile(page);
2626
poRegistration = new Registration(page);
2727
poToastBar = new ToastBar(page);
28-
poUtils = new Utils(page);
28+
poAuth = new Authenticated(page);
2929
await page.goto('/home');
3030
});
3131

@@ -43,7 +43,7 @@ test.describe('Delete Own Account', () => {
4343
await poRegistration.username.fill(userWithInvalidPassword.data.username);
4444
await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password);
4545
await poRegistration.btnLogin.click();
46-
await expect(poUtils.mainContent).toBeVisible();
46+
await poAuth.waitForDisplay();
4747
});
4848

4949
await test.step('navigate to profile and locate Delete My Account button', async () => {
@@ -81,7 +81,7 @@ test.describe('Delete Own Account', () => {
8181
await poRegistration.username.fill(userToDelete.data.username);
8282
await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password);
8383
await poRegistration.btnLogin.click();
84-
await expect(poUtils.mainContent).toBeVisible();
84+
await poAuth.waitForDisplay();
8585
});
8686

8787
await test.step('navigate to profile and locate Delete My Account button', async () => {
@@ -105,6 +105,7 @@ test.describe('Delete Own Account', () => {
105105
});
106106

107107
await test.step('verify user is redirected to login page', async () => {
108+
await poRegistration.waitForDisplay();
108109
await expect(poRegistration.btnLogin).toBeVisible();
109110
userToDelete.markAsDeleted();
110111
});
@@ -121,7 +122,7 @@ test.describe('Delete Own Account', () => {
121122
await poRegistration.username.fill(userWithoutPermissions.data.username);
122123
await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password);
123124
await poRegistration.btnLogin.click();
124-
await expect(poUtils.mainContent).toBeVisible();
125+
await poAuth.waitForDisplay();
125126
});
126127

127128
await test.step('navigate to profile and locate Delete My Account button', async () => {

apps/meteor/tests/e2e/export-messages.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { faker } from '@faker-js/faker';
22

33
import { Users } from './fixtures/userStates';
4-
import { HomeChannel, Utils } from './page-objects';
5-
import { ExportMessagesTab } from './page-objects/fragments/export-messages-tab';
4+
import { HomeChannel } from './page-objects';
5+
import { ExportMessagesTab } from './page-objects/fragments';
66
import { createTargetChannel, deleteChannel } from './utils';
77
import { test, expect } from './utils/test';
88

@@ -12,7 +12,6 @@ const uniqueMessage = (): string => `msg-${faker.string.uuid()}`;
1212

1313
test.describe('export-messages', () => {
1414
let poHomeChannel: HomeChannel;
15-
let poUtils: Utils;
1615
let targetChannel: string;
1716

1817
test.beforeAll(async ({ api }) => {
@@ -21,7 +20,6 @@ test.describe('export-messages', () => {
2120

2221
test.beforeEach(async ({ page }) => {
2322
poHomeChannel = new HomeChannel(page);
24-
poUtils = new Utils(page);
2523

2624
await page.goto('/home');
2725
});
@@ -90,7 +88,9 @@ test.describe('export-messages', () => {
9088
await exportMessagesTab.send();
9189

9290
await expect(
93-
poUtils.getAlertByText('You must select one or more users or provide one or more email addresses, separated by commas'),
91+
page.locator('[role="alert"]', {
92+
hasText: 'You must select one or more users or provide one or more email addresses, separated by commas',
93+
}),
9494
).toBeVisible();
9595
});
9696

@@ -104,7 +104,11 @@ test.describe('export-messages', () => {
104104
await exportMessagesTab.setAdditionalEmail('mail@mail.com');
105105
await exportMessagesTab.send();
106106

107-
await expect(poUtils.getAlertByText(`You haven't selected any messages`)).toBeVisible();
107+
await expect(
108+
page.locator('[role="alert"]', {
109+
hasText: `You haven't selected any messages`,
110+
}),
111+
).toBeVisible();
108112
});
109113

110114
test('should be able to send messages after closing export messages', async () => {
@@ -134,7 +138,7 @@ test.describe('export-messages', () => {
134138

135139
await poHomeChannel.tabs.kebab.click({ force: true });
136140
await poHomeChannel.tabs.btnExportMessages.click();
137-
await expect(exportMessagesTab.dialog).toBeVisible();
141+
await exportMessagesTab.waitForDisplay();
138142

139143
await poHomeChannel.content.getMessageByText(message1).click();
140144

@@ -162,7 +166,7 @@ test.describe('export-messages', () => {
162166
await poHomeChannel.tabs.kebab.click({ force: true });
163167
await poHomeChannel.tabs.btnExportMessages.click();
164168

165-
await expect(exportMessagesTab.dialog).toBeVisible();
169+
await exportMessagesTab.waitForDisplay();
166170
await poHomeChannel.content.getMessageByText(message1).click();
167171

168172
await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked();

apps/meteor/tests/e2e/iframe-authentication.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import fs from 'fs';
22
import path from 'path';
33

44
import { Users } from './fixtures/userStates';
5-
import { Utils, Registration } from './page-objects';
5+
import { Registration, Authenticated } from './page-objects';
66
import { test, expect } from './utils/test';
77

88
const IFRAME_URL = 'http://iframe.rocket.chat';
99
const API_URL = 'http://auth.rocket.chat/api/login';
1010

1111
test.describe('iframe-authentication', () => {
1212
let poRegistration: Registration;
13-
let poUtils: Utils;
13+
let poAuth: Authenticated;
1414

1515
test.beforeAll(async ({ api }) => {
1616
await api.post('/settings/Accounts_iframe_enabled', { value: true });
@@ -28,7 +28,7 @@ test.describe('iframe-authentication', () => {
2828

2929
test.beforeEach(async ({ page }) => {
3030
poRegistration = new Registration(page);
31-
poUtils = new Utils(page);
31+
poAuth = new Authenticated(page);
3232

3333
await page.route(API_URL, async (route) => {
3434
await route.fulfill({
@@ -77,7 +77,7 @@ test.describe('iframe-authentication', () => {
7777
});
7878

7979
await page.goto('/home');
80-
await expect(poUtils.mainContent).toBeVisible();
80+
await poAuth.waitForDisplay();
8181
});
8282

8383
test('should show login page when API returns invalid token', async ({ page }) => {
@@ -100,7 +100,7 @@ test.describe('iframe-authentication', () => {
100100

101101
await poRegistration.loginIframeSubmitButton.click();
102102

103-
await expect(poUtils.mainContent).toBeVisible();
103+
await poAuth.waitForDisplay();
104104
});
105105

106106
test('should return error to iframe when login fails', async ({ page }) => {

apps/meteor/tests/e2e/login.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { faker } from '@faker-js/faker';
22

33
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
4-
import { Utils, Registration } from './page-objects';
4+
import { Registration, Authenticated } from './page-objects';
55
import { setSettingValueById } from './utils/setSettingValueById';
66
import { test, expect } from './utils/test';
77

88
test.describe.parallel('Login', () => {
99
let poRegistration: Registration;
10-
let poUtils: Utils;
10+
let poAuth: Authenticated;
1111

1212
test.beforeEach(async ({ page }) => {
1313
poRegistration = new Registration(page);
14-
poUtils = new Utils(page);
14+
poAuth = new Authenticated(page);
1515

1616
await page.goto('/home');
1717
});
@@ -42,7 +42,7 @@ test.describe.parallel('Login', () => {
4242
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password);
4343
await poRegistration.btnLogin.click();
4444

45-
await expect(poUtils.mainContent).toBeVisible();
45+
await poAuth.waitForDisplay();
4646
});
4747
});
4848

@@ -52,7 +52,7 @@ test.describe.parallel('Login', () => {
5252
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password);
5353
await poRegistration.btnLogin.click();
5454

55-
await expect(poUtils.mainContent).toBeVisible();
55+
await poAuth.waitForDisplay();
5656
});
5757
});
5858

0 commit comments

Comments
 (0)