53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { test as base, expect } from '@playwright/test';
|
|
import type { ServiceUserUserInfoData } from '$lib/api';
|
|
import { mock } from './mock';
|
|
import { loginAsMockUser } from './auth';
|
|
|
|
// Auto-run mock reset: an `auto: true` fixture runs for every test whether or
|
|
// not the test destructures it, and participates in fixture ordering so any
|
|
// fixture that depends on it (like `loggedInUser`) is guaranteed to run after.
|
|
// We had previously used `test.beforeEach(mock.clear)` but Playwright skipped
|
|
// that hook for tests that reused a stable browser context across a run of
|
|
// same-route navigations — symptom was mock state leaking between consecutive
|
|
// tests that all navigate to /profile/[userId]. The auto fixture fires reliably
|
|
// per-test and fixes the leak.
|
|
export const test = base.extend<{
|
|
_autoResetMock: void;
|
|
loggedInUser: ServiceUserUserInfoData;
|
|
superAdminUser: ServiceUserUserInfoData;
|
|
staffUser: ServiceUserUserInfoData;
|
|
}>({
|
|
_autoResetMock: [
|
|
// eslint-disable-next-line no-empty-pattern
|
|
async ({}, use) => {
|
|
await mock.clear();
|
|
await use();
|
|
},
|
|
{ auto: true }
|
|
],
|
|
|
|
loggedInUser: async ({ page, _autoResetMock }, use) => {
|
|
void _autoResetMock; // force ordering: reset runs before login
|
|
const user = await loginAsMockUser(page);
|
|
await use(user);
|
|
},
|
|
|
|
superAdminUser: async ({ page, _autoResetMock }, use) => {
|
|
void _autoResetMock; // force ordering: reset runs before login
|
|
const user = await loginAsMockUser(page, {
|
|
user: { permission_level: 40, email: 'admin@test.local', username: 'superadmin' }
|
|
});
|
|
await use(user);
|
|
},
|
|
|
|
staffUser: async ({ page, _autoResetMock }, use) => {
|
|
void _autoResetMock; // force ordering: reset runs before login
|
|
const user = await loginAsMockUser(page, {
|
|
user: { permission_level: 20, email: 'staff@test.local', username: 'staff' }
|
|
});
|
|
await use(user);
|
|
}
|
|
});
|
|
|
|
export { expect };
|