WFDASH-WEBAPP/e2e/_helpers.ts

35 lines
1.2 KiB
TypeScript
Raw Normal View History

import { test as base, expect, type Page } from "@playwright/test";
/**
* Whether the auth-required specs can actually run.
*
* They need:
* - PocketBase reachable at E2E_POCKETBASE_URL (so we can create a fixture user)
* - A test email/password supplied via env
*
* When any of those are missing we mark the relevant specs `test.skip` so the
* suite still runs the no-infra checks.
*/
export const HAS_AUTH_FIXTURE =
!!process.env.E2E_TEST_EMAIL && !!process.env.E2E_TEST_PASSWORD;
export const POCKETBASE_URL = process.env.E2E_POCKETBASE_URL ?? "http://127.0.0.1:8090";
/** Calls PocketBase's create-and-auth endpoint and stores the auth record in localStorage. */
export async function signIn(
page: Page,
email: string,
password: string
): Promise<void> {
// Trigger the actual client-side login path used by AuthProvider.
await page.goto("/login");
await page.getByLabel(/email/i).fill(email);
await page.getByLabel(/password/i).fill(password);
await page.getByRole("button", { name: /sign in|log in|login/i }).click();
// Wait for redirect into the protected area (or an error to surface).
await page.waitForURL((u) => !u.pathname.startsWith("/login"), { timeout: 10_000 });
}
export const test = base;
export { expect };