test: Check User Registration Status and Modify Admin Rights (#36597)

pull/36812/head^2
Harmeet Kour 4 months ago committed by GitHub
parent dc5b3d238d
commit 37bb227dd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 76
      apps/meteor/tests/e2e/admin-users-role-management.spec.ts
  2. 84
      apps/meteor/tests/e2e/admin-users-status-management.spec.ts
  3. 118
      apps/meteor/tests/e2e/admin-users.spec.ts
  4. 52
      apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-users.ts

@ -0,0 +1,76 @@
import { Users } from './fixtures/userStates';
import { Admin } from './page-objects';
import { ToastBar } from './page-objects/toastBar';
import { test, expect } from './utils/test';
import type { ITestUser } from './utils/user-helpers';
import { createTestUser } from './utils/user-helpers';
let userWithoutAdminAccess: ITestUser;
let userWithAdminAccess: ITestUser;
let admin: Admin;
let poToastBar: ToastBar;
test.describe('Admin > Users Role Management', () => {
test.beforeAll('Create test users', async ({ api }) => {
userWithoutAdminAccess = await createTestUser(api);
userWithAdminAccess = await createTestUser(api, { roles: ['admin'] });
});
test.afterAll('Delete test users', async () => {
await userWithoutAdminAccess.delete();
await userWithAdminAccess.delete();
});
test.describe('Admin Role Management', () => {
test.use({ storageState: Users.admin.state });
test.beforeEach('Go to /admin/users', async ({ page }) => {
admin = new Admin(page);
poToastBar = new ToastBar(page);
await page.goto('/admin/users');
});
test('Make a newly created user as admin', async () => {
await admin.tabs.users.inputSearch.fill(userWithoutAdminAccess.data.username);
await test.step('should be visible in the All tab', async () => {
await admin.tabs.users.tabAll.click();
await expect(admin.getUserRowByUsername(userWithoutAdminAccess.data.username)).toBeVisible();
});
await test.step('make a user admin', async () => {
await admin.tabs.users.openUserActionMenu(userWithoutAdminAccess.data.username);
await admin.tabs.users.menuItemMakeAdmin.click();
await expect(poToastBar.alert).toBeVisible();
await expect(poToastBar.alert).toHaveText('User is now an admin');
});
await test.step('verify user is admin', async () => {
await admin.getUserRowByUsername(userWithoutAdminAccess.data.username).click();
await expect(admin.tabs.users.userInfoDialog).toBeVisible();
await expect(admin.tabs.users.userInfoDialog).toContainText('Admin');
});
});
test('Remove role as admin', async () => {
await admin.tabs.users.inputSearch.fill(userWithAdminAccess.data.username);
await test.step('User should be visible in the All tab', async () => {
await admin.tabs.users.tabAll.click();
await expect(admin.getUserRowByUsername(userWithAdminAccess.data.username)).toBeVisible();
});
await test.step('remove admin role', async () => {
await admin.tabs.users.openUserActionMenu(userWithAdminAccess.data.username);
await admin.tabs.users.menuItemRemoveAdmin.click();
await expect(poToastBar.alert).toBeVisible();
await expect(poToastBar.alert).toHaveText('User is no longer an admin');
});
await test.step('verify user role as admin is removed', async () => {
await admin.getUserRowByUsername(userWithAdminAccess.data.username).click();
await expect(admin.tabs.users.userInfoDialog).toBeVisible();
await expect(admin.tabs.users.userInfoDialog).not.toHaveText('Admin');
});
});
});
});

@ -0,0 +1,84 @@
import type { BrowserContext, Page } from '@playwright/test';
import { DEFAULT_USER_CREDENTIALS } from './config/constants';
import { Users } from './fixtures/userStates';
import { Admin, Registration, Utils } from './page-objects';
import { test, expect } from './utils/test';
import type { ITestUser } from './utils/user-helpers';
import { createTestUser } from './utils/user-helpers';
let user: ITestUser;
let admin: Admin;
test.describe.serial('Admin > Users', () => {
test.beforeAll('Create a new user', async ({ api }) => {
user = await createTestUser(api);
});
test.afterAll('Delete the new user', async () => {
await user.delete();
});
test.describe('Login', () => {
let context: BrowserContext;
let page: Page;
let poRegistration: Registration;
let poUtils: Utils;
test.beforeAll(async ({ browser }) => {
context = await browser.newContext();
page = await context.newPage();
poRegistration = new Registration(page);
poUtils = new Utils(page);
});
test.afterAll(async () => {
await context.close();
});
test('Login as a newly created user and verify its status is active', async () => {
await page.goto('/login');
await test.step('should log in as the newly created user', async () => {
await poRegistration.username.fill(user.data.username);
await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password);
await poRegistration.btnLogin.click();
});
await test.step('Assert user is logged in', async () => {
await expect(poUtils.mainContent).toBeVisible();
});
});
});
test.describe('Admin > Users Status Management', () => {
test.use({ storageState: Users.admin.state });
test.beforeEach('Go to /admin/users', async ({ page }) => {
admin = new Admin(page);
await page.goto('/admin/users');
});
test('After the first login, the user gets listed under the Active tab', async () => {
await admin.tabs.users.inputSearch.fill(user.data.username);
await test.step('should be visible in the All tab', async () => {
await admin.tabs.users.tabActive.click();
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
});
await test.step('should not be visible in the Pending tab', async () => {
await admin.tabs.users.tabPending.click();
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
});
await test.step('should be visible in the Active tab', async () => {
await admin.tabs.users.tabActive.click();
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
});
await test.step('should not be visible in the Deactivated tab', async () => {
await admin.tabs.users.tabDeactivated.click();
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
});
});
});
});

@ -1,88 +1,66 @@
import { faker } from '@faker-js/faker';
import type { IUser } from '@rocket.chat/core-typings';
import { Users } from './fixtures/userStates';
import { expect, test } from './utils/test';
import { Admin } from './page-objects';
import { test, expect } from './utils/test';
import type { ITestUser } from './utils/user-helpers';
import { createTestUser } from './utils/user-helpers';
let user: ITestUser;
let admin: Admin;
test.use({ storageState: Users.admin.state });
test.describe('Admin > Users', () => {
let user: IUser & { username: string };
test.beforeAll('Create a new user', async ({ api }) => {
const response = await api.post('/users.create', {
email: faker.internet.email(),
name: faker.person.fullName(),
password: faker.internet.password(),
username: faker.internet.userName(),
});
expect(response.status()).toBe(200);
const json = await response.json();
user = json.user;
user = await createTestUser(api);
});
test.beforeEach('Go to /admin/users', async ({ page }) => {
await page.goto('/admin/users');
test.afterAll('Delete the new user', async () => {
await user.delete();
});
test.afterAll('Delete the new user', async ({ api }) => {
const response = await api.post('/users.delete', { userId: user._id });
expect(response.status()).toBe(200);
test.beforeEach('Go to /admin/users', async ({ page }) => {
admin = new Admin(page);
await page.goto('/admin/users');
});
test('New user shows in correct tabs when deactivated', async () => {
await admin.tabs.users.inputSearch.fill(user.data.username);
test(
'New user shows in correct tabs when deactivated',
{
tag: '@admin',
annotation: {
type: 'issue',
description: 'https://rocketchat.atlassian.net/browse/SUP-775',
},
},
async ({ page }) => {
const { username } = user;
await page.getByPlaceholder('Search Users').fill(username);
await test.step('is visible in the All tab', async () => {
await page.getByRole('tab', { name: 'All' }).click();
await expect(page.getByRole('link', { name: username })).toBeVisible();
});
await test.step('is visible in the Pending tab', async () => {
await page.getByRole('tab', { name: 'Pending' }).click();
await expect(page.getByRole('link', { name: username })).toBeVisible();
});
await test.step('is not visible in the Active tab', async () => {
await page.getByRole('tab', { name: 'Active' }).click();
await expect(page.getByRole('link', { name: username })).not.toBeVisible();
});
await test.step('should be visible in the All tab', async () => {
await admin.tabs.users.tabAll.click();
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
});
await test.step('is not visible in the Deactivated tab', async () => {
await page.getByRole('tab', { name: 'Deactivated' }).click();
await expect(page.getByRole('link', { name: username })).not.toBeVisible();
});
await test.step('should be visible in the Pending tab', async () => {
await admin.tabs.users.tabPending.click();
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
});
await test.step('moves from Pending to Deactivated tab', async () => {
await page.getByRole('tab', { name: 'Pending' }).click();
await page.getByRole('button', { name: 'More actions' }).click();
await page.getByRole('menuitem', { name: 'Deactivate' }).click();
await expect(page.getByRole('link', { name: username })).not.toBeVisible();
await test.step('should not be visible in the Active tab', async () => {
await admin.tabs.users.tabActive.click();
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
});
await page.getByRole('tab', { name: 'Deactivated' }).click();
await expect(page.getByRole('link', { name: username })).toBeVisible();
});
await test.step('should not be visible in the Deactivated tab', async () => {
await admin.tabs.users.tabDeactivated.click();
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
});
await test.step('moves from Deactivated to Pending tab', async () => {
await page.getByRole('tab', { name: 'Deactivated' }).click();
await page.getByRole('button', { name: 'More actions' }).click();
await page.getByRole('menuitem', { name: 'Activate' }).click();
await expect(page.getByRole('link', { name: username })).not.toBeVisible();
await test.step('should move from Pending to Deactivated tab', async () => {
await admin.tabs.users.tabPending.click();
await admin.tabs.users.btnMoreActionsMenu.click();
await admin.tabs.users.menuItemDeactivated.click();
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
await admin.tabs.users.tabDeactivated.click();
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
});
await page.getByRole('tab', { name: 'Pending' }).click();
await expect(page.getByRole('link', { name: username })).toBeVisible();
});
},
);
await test.step('should move from Deactivated to Pending tab', async () => {
await admin.tabs.users.tabDeactivated.click();
await admin.tabs.users.btnMoreActionsMenu.click();
await admin.tabs.users.menuItemActivate.click();
await expect(admin.getUserRowByUsername(user.data.username)).not.toBeVisible();
await admin.tabs.users.tabPending.click();
await expect(admin.getUserRowByUsername(user.data.username)).toBeVisible();
});
});
});

@ -71,6 +71,58 @@ export class AdminFlextabUsers {
return this.page.locator('button[data-qa="ContextualbarActionClose"]');
}
get btnMoreActionsMenu(): Locator {
return this.page.getByRole('button', { name: 'More actions' });
}
get menuItemDeactivated(): Locator {
return this.page.getByRole('menuitem', { name: 'Deactivate' });
}
get menuItemActivate(): Locator {
return this.page.getByRole('menuitem', { name: 'Activate' });
}
get tabActive(): Locator {
return this.page.getByRole('tab', { name: 'Active' });
}
get tabDeactivated(): Locator {
return this.page.getByRole('tab', { name: 'Deactivated' });
}
get tabPending(): Locator {
return this.page.getByRole('tab', { name: 'Pending' });
}
get tabAll(): Locator {
return this.page.getByRole('tab', { name: 'All' });
}
get inputSearch(): Locator {
return this.page.getByRole('textbox', { name: 'Search Users' });
}
get menuItemMakeAdmin(): Locator {
return this.page.getByRole('menuitem', { name: 'Make Admin' });
}
get menuItemRemoveAdmin(): Locator {
return this.page.getByRole('menuitem', { name: 'Remove Admin' });
}
get userInfoDialog(): Locator {
return this.page.getByRole('dialog');
}
getUserRowByUsername(username: string): Locator {
return this.page.getByRole('link', { name: username });
}
async openUserActionMenu(username: string): Promise<void> {
await this.getUserRowByUsername(username).getByRole('button', { name: 'More actions' }).click();
}
getCustomField(fieldName: string): Locator {
return this.page.getByRole('textbox', { name: fieldName });
}

Loading…
Cancel
Save