test: Check User Registration Status and Modify Admin Rights (#36597)
parent
dc5b3d238d
commit
37bb227dd1
@ -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(); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
Loading…
Reference in new issue