Skip to content

Commit 09874ae

Browse files
authored
test: Flaky admin search users (#37501)
1 parent c0dee8d commit 09874ae

6 files changed

Lines changed: 20 additions & 30 deletions

File tree

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ test.describe('Admin users custom fields', () => {
6161

6262
test('should allow admin to add user custom fields', async () => {
6363
await test.step('should find and click on add test user', async () => {
64-
await poAdmin.inputSearchUsers.fill(addTestUser.data.username);
65-
66-
await expect(poAdmin.getUserRowByUsername(addTestUser.data.username)).toBeVisible();
64+
await poAdmin.searchUser(addTestUser.data.username);
6765
await poAdmin.getUserRowByUsername(addTestUser.data.username).click();
6866
});
6967

@@ -93,9 +91,7 @@ test.describe('Admin users custom fields', () => {
9391

9492
test('should allow admin to update existing user custom fields', async () => {
9593
await test.step('should find and click on update test user', async () => {
96-
await poAdmin.inputSearchUsers.fill(updateTestUser.data.username);
97-
98-
await expect(poAdmin.getUserRowByUsername(updateTestUser.data.username)).toBeVisible();
94+
await poAdmin.searchUser(updateTestUser.data.username);
9995
await poAdmin.getUserRowByUsername(updateTestUser.data.username).click();
10096
});
10197

@@ -144,9 +140,7 @@ test.describe('Admin users custom fields', () => {
144140

145141
test('should not render fields with invalid custom field type', async () => {
146142
await test.step('should find and click on add test user', async () => {
147-
await poAdmin.inputSearchUsers.fill(addTestUser.data.username);
148-
149-
await expect(poAdmin.getUserRowByUsername(addTestUser.data.username)).toBeVisible();
143+
await poAdmin.searchUser(addTestUser.data.username);
150144
await poAdmin.getUserRowByUsername(addTestUser.data.username).click();
151145
});
152146

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ test.describe('Admin > Users Role Management', () => {
2828
});
2929

3030
test('Make a newly created user as admin', async () => {
31-
await admin.inputSearchUsers.fill(userWithoutAdminAccess.data.username);
32-
3331
await test.step('should be visible in the All tab', async () => {
3432
await admin.getTabByName().click();
35-
await expect(admin.getUserRowByUsername(userWithoutAdminAccess.data.username)).toBeVisible();
36-
await expect(admin.getUserRowByUsername(userWithoutAdminAccess.data.username)).toHaveCount(1);
33+
await admin.searchUser(userWithoutAdminAccess.data.username);
3734
});
3835

3936
await test.step('make a user admin', async () => {
@@ -49,10 +46,9 @@ test.describe('Admin > Users Role Management', () => {
4946
});
5047

5148
test('Remove role as admin', async () => {
52-
await admin.inputSearchUsers.fill(userWithAdminAccess.data.username);
5349
await test.step('User should be visible in the All tab', async () => {
5450
await admin.getTabByName().click();
55-
await expect(admin.getUserRowByUsername(userWithAdminAccess.data.username)).toBeVisible();
51+
await admin.searchUser(userWithAdminAccess.data.username);
5652
});
5753

5854
await test.step('remove admin role', async () => {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ test.describe.serial('Admin > Users', () => {
5858
});
5959

6060
test('After the first login, the user gets listed under the Active tab', async () => {
61-
await adminUsers.inputSearchUsers.fill(user.data.username);
62-
6361
await test.step('should be visible in the All tab', async () => {
64-
await adminUsers.getTabByName('Active').click();
65-
await expect(adminUsers.getUserRowByUsername(user.data.username)).toBeVisible();
62+
await adminUsers.getTabByName().click();
63+
await adminUsers.searchUser(user.data.username);
6664
});
6765

6866
await test.step('should not be visible in the Pending tab', async () => {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ test.describe('Admin > Users', () => {
2424
});
2525

2626
test('New user shows in correct tabs when deactivated', async () => {
27-
await admin.inputSearchUsers.fill(user.data.username);
28-
2927
await test.step('should be visible in the All tab', async () => {
3028
await admin.getTabByName().click();
31-
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
29+
await admin.searchUser(user.data.username);
3230
});
3331

3432
await test.step('should be visible in the Pending tab', async () => {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ test.describe.parallel('administration', () => {
6565
await page.goto('/admin/users');
6666
});
6767

68-
test('expect find "user1" user', async ({ page }) => {
69-
await poAdminUsers.inputSearchUsers.fill('user1');
70-
71-
await expect(page.locator('table tr[qa-user-id="user1"]')).toBeVisible();
68+
test('expect find "user1" user', async () => {
69+
await poAdminUsers.searchUser('user1');
7270
});
7371

7472
test('expect create a user', async () => {
@@ -103,7 +101,7 @@ test.describe.parallel('administration', () => {
103101
await expect(poAdminUsers.editUser.joinDefaultChannels).toBeVisible();
104102
await poAdminUsers.editUser.btnAddUser.click();
105103

106-
await poAdminUsers.inputSearchUsers.fill(username);
104+
await poAdminUsers.searchUser(username);
107105
await poAdminUsers.getUserRowByUsername(username).click();
108106
await poAdminUsers.userInfo.btnEdit.click();
109107
await expect(poAdminUsers.editUser.inputUserName).toHaveValue(username);

apps/meteor/tests/e2e/page-objects/admin-users.ts

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

33
import { Admin } from './admin';
44
import { MenuMoreActions, UserInfoFlexTab, EditUserFlexTab } from './fragments';
5+
import { expect } from '../utils/test';
56

67
type UserActions = 'Make Admin' | 'Remove Admin' | 'Activate' | 'Deactivate';
78

@@ -27,7 +28,7 @@ export class AdminUsers extends Admin {
2728
return this.page.getByRole('button', { name: 'Invite', exact: true });
2829
}
2930

30-
get inputSearchUsers(): Locator {
31+
private get inputSearchUsers(): Locator {
3132
return this.page.getByRole('textbox', { name: 'Search Users' });
3233
}
3334

@@ -36,7 +37,7 @@ export class AdminUsers extends Admin {
3637
}
3738

3839
getUserRowByUsername(username: string): Locator {
39-
return this.page.locator('tr', { hasText: username });
40+
return this.page.locator('tr', { hasText: username }).first();
4041
}
4142

4243
getTabByName(name: 'All' | 'Pending' | 'Active' | 'Deactivated' = 'All'): Locator {
@@ -53,9 +54,14 @@ export class AdminUsers extends Admin {
5354
}
5455

5556
async deleteUser(username: string): Promise<void> {
56-
await this.inputSearchUsers.fill(username);
57+
await this.searchUser(username);
5758
await this.getUserRowByUsername(username).click();
5859
await this.userInfo.btnMoreActions.click();
5960
await this.userInfo.menuItemDeleteUser.click();
6061
}
62+
63+
async searchUser(username: string): Promise<void> {
64+
await this.inputSearchUsers.fill(username);
65+
await expect(this.getUserRowByUsername(username)).toHaveCount(1);
66+
}
6167
}

0 commit comments

Comments
 (0)