All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m28s
Reviewed-on: #46 Co-authored-by: AI Agent <ai-agent@campbellwireless.net> Co-committed-by: AI Agent <ai-agent@campbellwireless.net>
80 lines
3.0 KiB
TypeScript
80 lines
3.0 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { TEST_USERS } from './setup/test-users.js';
|
|
import { loginAsLocalUser } from './helpers/auth.js';
|
|
import { uniqueSuffix } from './helpers/trip.js';
|
|
|
|
const DASHBOARD_URL = '/trips/dashboard';
|
|
const ADMIN_USERS_URL = '/trips/admin/users';
|
|
|
|
async function expectDashboardLoaded(page: Parameters<typeof loginAsLocalUser>[0]): Promise<void> {
|
|
await expect(page).toHaveURL(/\/trips\/dashboard/);
|
|
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
|
}
|
|
|
|
test.beforeEach(async ({ context }) => {
|
|
await context.clearCookies();
|
|
});
|
|
|
|
test('regular user smoke', async ({ page }) => {
|
|
await loginAsLocalUser(page, TEST_USERS.regular.username, TEST_USERS.regular.password);
|
|
await expectDashboardLoaded(page);
|
|
|
|
await page.goto(ADMIN_USERS_URL);
|
|
await expect(page).toHaveURL(/\/trips\/dashboard/);
|
|
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
|
});
|
|
|
|
test('admin user smoke', async ({ page }) => {
|
|
await loginAsLocalUser(page, TEST_USERS.admin.username, TEST_USERS.admin.password);
|
|
await expectDashboardLoaded(page);
|
|
|
|
await page.goto(ADMIN_USERS_URL);
|
|
await expect(page).toHaveURL(/\/trips\/admin\/users/);
|
|
await expect(page.getByRole('heading', { name: 'Users' })).toBeVisible();
|
|
});
|
|
|
|
test('disposable local user smoke', async ({ page }) => {
|
|
const suffix = uniqueSuffix();
|
|
const username = `e2e_disposable_${suffix}`;
|
|
const fullName = `E2E Disposable ${suffix}`;
|
|
const email = `e2e_disposable_${suffix}@test.local`;
|
|
const password = `TempPass-${suffix}-1234`;
|
|
|
|
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();
|
|
await page.getByRole('button', { name: 'Add User' }).click();
|
|
|
|
const addDialog = page
|
|
.locator('[role="dialog"]')
|
|
.filter({ has: page.getByRole('heading', { name: 'Add user' }) })
|
|
.first();
|
|
await expect(addDialog).toBeVisible();
|
|
|
|
await addDialog.locator('input[type="text"]').nth(0).fill(username);
|
|
await addDialog.locator('input[type="text"]').nth(1).fill(fullName);
|
|
await addDialog.getByPlaceholder('name@example.com').fill(email);
|
|
await addDialog.locator('input[type="password"]').nth(0).fill(password);
|
|
await addDialog.locator('input[type="password"]').nth(1).fill(password);
|
|
|
|
const createResponse = page.waitForResponse((response) => {
|
|
return (
|
|
response.url().includes('/admin/api/users') &&
|
|
response.request().method() === 'POST' &&
|
|
response.ok()
|
|
);
|
|
});
|
|
await addDialog.getByRole('button', { name: 'Create user' }).click();
|
|
await createResponse;
|
|
|
|
await expect(page.getByRole('cell', { name: username, exact: true })).toBeVisible();
|
|
|
|
await page.context().clearCookies();
|
|
await loginAsLocalUser(page, username, password);
|
|
await expectDashboardLoaded(page);
|
|
|
|
await page.goto(ADMIN_USERS_URL);
|
|
await expect(page).toHaveURL(/\/trips\/dashboard/);
|
|
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
|
});
|