54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
import { test, expect, type Page } from '@playwright/test';
|
|
|
|
async function login(page: Page, user: string, pass: string) {
|
|
await page.goto('/login/');
|
|
await page.fill('#lg-username', user);
|
|
await page.fill('#lg-password', pass);
|
|
await page.click('button[type=submit]');
|
|
await expect(page.getByTestId('nav-menu')).toBeVisible();
|
|
}
|
|
|
|
test('a non-staff user cannot reach the admin panel', async ({ page }) => {
|
|
await login(page, 'demo', 'demo');
|
|
// The menu entry is staff-only...
|
|
await page.getByTestId('nav-menu').click();
|
|
await expect(page.getByTestId('nav-admin')).toHaveCount(0);
|
|
|
|
// ...and visiting the route directly redirects away from it.
|
|
await page.goto('/admin/');
|
|
await expect(page).toHaveURL(/\/app/);
|
|
await expect(page.getByTestId('admin-table')).toHaveCount(0);
|
|
});
|
|
|
|
test('staff can list, search and deactivate a user', async ({ page }) => {
|
|
await login(page, 'admin', 'admin');
|
|
await page.getByTestId('nav-menu').click();
|
|
await page.getByTestId('nav-admin').click();
|
|
await expect(page.getByTestId('admin-table')).toBeVisible();
|
|
|
|
// Both seeded users are listed.
|
|
await expect(page.getByTestId('admin-row')).toHaveCount(2);
|
|
|
|
// Search narrows the list.
|
|
await page.getByTestId('admin-search').fill('demo');
|
|
await expect(page.getByTestId('admin-row')).toHaveCount(1);
|
|
|
|
// Deactivation asks for an inline confirm first.
|
|
await page.getByTestId('admin-deactivate').click();
|
|
await page.getByTestId('admin-confirm-deactivate').click();
|
|
await expect(page.getByTestId('admin-state')).toContainText(/отключён|disabled/i);
|
|
|
|
// And it can be reversed.
|
|
await page.getByTestId('admin-activate').click();
|
|
await expect(page.getByTestId('admin-state')).toContainText(/активен|active/i);
|
|
});
|
|
|
|
test('staff cannot deactivate their own account', async ({ page }) => {
|
|
await login(page, 'admin', 'admin');
|
|
await page.goto('/admin/');
|
|
await page.getByTestId('admin-search').fill('admin');
|
|
await expect(page.getByTestId('admin-row')).toHaveCount(1);
|
|
// The row is marked as "you" and offers no deactivate control.
|
|
await expect(page.getByTestId('admin-row')).toContainText(/вы|you/i);
|
|
await expect(page.getByTestId('admin-deactivate')).toHaveCount(0);
|
|
});
|