|
| 1 | +import type { Page } from 'playwright-core'; |
| 2 | + |
| 3 | +import { IS_EE } from './config/constants'; |
| 4 | +import { createAuxContext } from './fixtures/createAuxContext'; |
| 5 | +import injectInitialData from './fixtures/inject-initial-data'; |
| 6 | +import { Users } from './fixtures/userStates'; |
| 7 | +import { Registration } from './page-objects'; |
| 8 | +import { AdminDeviceManagement } from './page-objects/admin-device-management'; |
| 9 | +import { test, expect } from './utils/test'; |
| 10 | + |
| 11 | +test.describe('Admin Device Management Page', () => { |
| 12 | + test.skip(!IS_EE); |
| 13 | + test.use({ storageState: Users.admin.state }); |
| 14 | + |
| 15 | + let page: Page; |
| 16 | + let adminDeviceManagement: AdminDeviceManagement; |
| 17 | + let loginPage: Registration; |
| 18 | + |
| 19 | + test.beforeEach(async ({ browser }) => { |
| 20 | + ({ page } = await createAuxContext(browser, Users.admin)); |
| 21 | + adminDeviceManagement = new AdminDeviceManagement(page); |
| 22 | + loginPage = new Registration(page); |
| 23 | + await page.goto('/admin/device-management'); |
| 24 | + }); |
| 25 | + |
| 26 | + test.afterEach(async () => { |
| 27 | + await page.close(); |
| 28 | + await injectInitialData(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should show Device management page', async () => { |
| 32 | + await expect(adminDeviceManagement.adminPageContent).toBeVisible(); |
| 33 | + }); |
| 34 | + |
| 35 | + test('should logout current device and redirect to login page', async () => { |
| 36 | + const deviceId = await adminDeviceManagement.getUsersDeviceId('rocketchat.internal.admin.test'); |
| 37 | + await adminDeviceManagement.logoutDeviceById(deviceId); |
| 38 | + await expect(loginPage.loginForm).toBeVisible(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('should logout current device from device info tab and redirect to login page', async () => { |
| 42 | + const deviceId = await adminDeviceManagement.getUsersDeviceId('rocketchat.internal.admin.test'); |
| 43 | + await adminDeviceManagement.searchUserDevice('rocketchat.internal.admin.test'); |
| 44 | + await adminDeviceManagement.table.getDeviceRowById(deviceId).click(); |
| 45 | + |
| 46 | + await expect(adminDeviceManagement.deviceInfo.getDeviceInfoId(deviceId)).toBeVisible(); |
| 47 | + await adminDeviceManagement.deviceInfo.btnLogoutDevice.click(); |
| 48 | + await adminDeviceManagement.logoutModal.confirmLogout(); |
| 49 | + await expect(loginPage.loginForm).toBeVisible(); |
| 50 | + }); |
| 51 | + |
| 52 | + test('should logout other device successfully', async ({ browser }) => { |
| 53 | + const user2Page = await browser.newPage({ storageState: Users.user2.state }); |
| 54 | + const loginPage2 = new Registration(user2Page); |
| 55 | + await user2Page.goto('/'); |
| 56 | + await expect(user2Page.getByRole('main')).toBeVisible(); |
| 57 | + |
| 58 | + const user2DeviceId = await adminDeviceManagement.getUsersDeviceId('user2'); |
| 59 | + |
| 60 | + await test.step('should logout user2 and redirect to login page', async () => { |
| 61 | + await adminDeviceManagement.logoutDeviceById(user2DeviceId); |
| 62 | + await loginPage2.loginForm.waitFor(); |
| 63 | + await expect(loginPage2.loginForm).toBeVisible(); |
| 64 | + }); |
| 65 | + |
| 66 | + await test.step('should no longer show user2 device in admin device management page', async () => { |
| 67 | + await adminDeviceManagement.searchUserDevice('user2'); |
| 68 | + await expect(adminDeviceManagement.table.getDeviceRowById(user2DeviceId)).not.toBeVisible(); |
| 69 | + }); |
| 70 | + |
| 71 | + await user2Page.close(); |
| 72 | + }); |
| 73 | +}); |
0 commit comments