|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { login, logout, waitModal, waitPageLoading } from './utils.js'; |
| 3 | + |
| 4 | +// Reset storage state for this file to avoid being authenticated |
| 5 | +test.use({ storageState: { cookies: [], origins: [] } }); |
| 6 | + |
| 7 | +test('Admin without profile', async ({ page }) => { |
| 8 | + const randomValue = Math.random().toString(36).substring(7); |
| 9 | + const randomEmail = `${randomValue}@example.com`; |
| 10 | + |
| 11 | + await test.step('Login as admin and create test user', async () => { |
| 12 | + await login(page, '[email protected]', '1234'); |
| 13 | + await page.goto('/v2/admin/users/register'); |
| 14 | + await waitPageLoading(page); |
| 15 | + await page.getByRole('textbox', { name: 'E-mail' }).fill(randomEmail); |
| 16 | + await page.getByRole('textbox', { name: 'Password', exact: true }).fill('1234'); |
| 17 | + await page.getByRole('textbox', { name: 'Confirm password' }).fill('1234'); |
| 18 | + await page.getByRole('textbox', { name: 'Project dir' }).fill('/tmp'); |
| 19 | + await page.getByRole('button', { name: 'Save' }).first().click(); |
| 20 | + await page.waitForURL(/\/v2\/admin\/users\/\d+\/edit/); |
| 21 | + }); |
| 22 | + |
| 23 | + await test.step('Grant superuser privileges and unset the profile', async () => { |
| 24 | + await page.getByLabel('Superuser').check(); |
| 25 | + |
| 26 | + // Unset the profile |
| 27 | + await page |
| 28 | + .getByRole('combobox', { name: 'Select resource' }) |
| 29 | + .selectOption('Select resource...'); |
| 30 | + await expect(page.getByRole('combobox', { name: 'Select profile' })).toBeDisabled(); |
| 31 | + await expect(page.getByRole('combobox', { name: 'Select profile' })).toHaveValue(''); |
| 32 | + |
| 33 | + await page.getByRole('button', { name: 'Save' }).click(); |
| 34 | + |
| 35 | + const modal = await waitModal(page); |
| 36 | + await modal.getByRole('button', { name: 'Confirm' }).click(); |
| 37 | + |
| 38 | + await expect(page.getByText('User successfully updated')).toBeVisible(); |
| 39 | + }); |
| 40 | + |
| 41 | + await test.step('Login as test user', async () => { |
| 42 | + await logout(page, '[email protected]'); |
| 43 | + |
| 44 | + await page.goto('/auth/login'); |
| 45 | + await waitPageLoading(page); |
| 46 | + await page.getByRole('button', { name: 'Log in with username & password' }).click(); |
| 47 | + await page.getByLabel('Email address').fill(randomEmail); |
| 48 | + await page.getByLabel('Password').fill('1234'); |
| 49 | + await page.getByRole('button', { name: 'Log in', exact: true }).click(); |
| 50 | + |
| 51 | + await page.waitForURL(/\/v2\/projects/); |
| 52 | + |
| 53 | + await expect(page.getByText(/Forbidden access/)).toBeVisible(); |
| 54 | + }); |
| 55 | + |
| 56 | + await test.step('Set user profile', async () => { |
| 57 | + await page.goto('/v2/admin/users'); |
| 58 | + await waitPageLoading(page); |
| 59 | + |
| 60 | + await page.getByRole('row', { name: randomEmail }).getByRole('link', { name: 'Edit' }).click(); |
| 61 | + |
| 62 | + await page.getByRole('combobox', { name: 'Select resource' }).selectOption('Local resource'); |
| 63 | + await page.getByRole('combobox', { name: 'Select profile' }).selectOption('Local profile'); |
| 64 | + await page.getByRole('button', { name: 'Save' }).click(); |
| 65 | + await expect(page.getByText('User successfully updated')).toBeVisible(); |
| 66 | + }); |
| 67 | + |
| 68 | + await test.step('Check projects page', async () => { |
| 69 | + await page.goto('/v2/projects'); |
| 70 | + await waitPageLoading(page); |
| 71 | + |
| 72 | + await expect(page.getByRole('button', { name: 'Create new project' })).toBeVisible(); |
| 73 | + await logout(page, randomEmail); |
| 74 | + }); |
| 75 | +}); |
0 commit comments