Files
trips/e2e/admin-auth-source.test.ts
AI Agent 1ef5deeb98
All checks were successful
PR Checks / lint-test-and-docker-build (pull_request) Successful in 2m17s
e2e) add admin auth source and login flows
2026-02-22 21:27:41 +00:00

56 lines
2.5 KiB
TypeScript

import { test, expect, type Locator, type Page } from '@playwright/test';
import { TEST_USERS } from './setup/test-users.js';
const LOGIN_URL = '/trips/login';
const ADMIN_USERS_URL = '/trips/admin/users';
async function loginAsLocalUser(page: Page, username: string, password: string): Promise<void> {
await page.goto(LOGIN_URL);
await page.fill('input[name="identifier"]', username);
await page.fill('input[name="password"]', password);
await page.click('button[type="submit"]:has-text("Sign in locally")');
await page.waitForURL('**/trips/dashboard', { timeout: 15_000 });
}
function rowForUser(page: Page, username: string): Locator {
return page.getByRole('cell', { name: username }).locator('..');
}
test.beforeEach(async ({ context }) => {
await context.clearCookies();
});
test('admin sees auth source and can set local password', async ({ page }) => {
await loginAsLocalUser(page, TEST_USERS.admin.username, TEST_USERS.admin.password);
await page.goto(ADMIN_USERS_URL);
await expect(page.getByRole('heading', { name: 'Users' })).toBeVisible();
const regularRow = rowForUser(page, TEST_USERS.regular.username);
await expect(regularRow.getByText('Local', { exact: true })).toBeVisible();
const adminRow = rowForUser(page, TEST_USERS.admin.username);
await expect(adminRow.getByText('Local', { exact: true })).toBeVisible();
await regularRow.getByRole('button', { name: 'Set local password' }).click();
const dialog = page.getByRole('dialog', { name: 'Set local password' });
await expect(dialog).toBeVisible();
await dialog.getByRole('button', { name: 'Save password' }).click();
await expect(dialog.getByText('Password is required')).toBeVisible();
await dialog.locator('input[type="password"]').nth(0).fill('short');
await dialog.locator('input[type="password"]').nth(1).fill('short');
await dialog.getByRole('button', { name: 'Save password' }).click();
await expect(dialog.getByText('Password must be at least 12 characters')).toBeVisible();
await dialog.locator('input[type="password"]').nth(0).fill('long-enough-password');
await dialog.locator('input[type="password"]').nth(1).fill('long-enough-password-mismatch');
await dialog.getByRole('button', { name: 'Save password' }).click();
await expect(dialog.getByText('Passwords do not match')).toBeVisible();
await dialog.locator('input[type="password"]').nth(0).fill('local-password-123');
await dialog.locator('input[type="password"]').nth(1).fill('local-password-123');
await dialog.getByRole('button', { name: 'Save password' }).click();
await expect(dialog).toBeHidden();
});