mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-07 21:33:18 +01:00
Add basic e2e tests for admin panel
This commit is contained in:
committed by
Constantin Graf
parent
a12ee1b029
commit
06a2048771
@@ -1,8 +1,11 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { test as baseTest } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { PLAYWRIGHT_BASE_URL, TEST_USER_PASSWORD } from './config';
|
||||
import { type TestContext, setupTestContext } from '../e2e/utils/api';
|
||||
import { setupAdminUser, setupEmployeeUser } from '../e2e/utils/members';
|
||||
import { loginAsSuperAdmin } from '../e2e/utils/admin';
|
||||
|
||||
export * from '@playwright/test';
|
||||
export type { TestContext };
|
||||
@@ -116,3 +119,33 @@ export const test = baseTest.extend<
|
||||
await closeAdmin();
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Authentication fixture for the Filament admin panel.
|
||||
*
|
||||
* The admin panel can only be accessed by the seeded super admin user, so the
|
||||
* throwaway users of the default fixture cannot be used. Logging in is rate
|
||||
* limited (5 attempts per minute and email address), therefore the session is
|
||||
* created once per worker and reused by all tests of that worker.
|
||||
*/
|
||||
export const adminTest = baseTest.extend<object, { adminStorageState: string }>({
|
||||
adminStorageState: [
|
||||
async ({ browser }, use, workerInfo) => {
|
||||
const fileName = path.resolve(
|
||||
workerInfo.project.outputDir,
|
||||
`.auth/admin-${workerInfo.workerIndex}.json`
|
||||
);
|
||||
|
||||
if (!fs.existsSync(fileName)) {
|
||||
const context = await browser.newContext({ storageState: undefined });
|
||||
await loginAsSuperAdmin(await context.newPage());
|
||||
await context.storageState({ path: fileName });
|
||||
await context.close();
|
||||
}
|
||||
|
||||
await use(fileName);
|
||||
},
|
||||
{ scope: 'worker' },
|
||||
],
|
||||
storageState: ({ adminStorageState }, use) => use(adminStorageState),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user