Skip to content
File

Blob: tests/e2e/fixtures/anvil-test.ts

typescript65 lines
1import { expect, test as base, type Page } from "@playwright/test";
2import { readFile } from "node:fs/promises";
3import {
4 E2E_BASELINE_EMAIL,
5 E2E_BASELINE_NAME,
6 E2E_BASELINE_SLUG,
7 E2E_BASELINE_TESSERA_SUB,
8 setMockOidcIdentity,
9 type MockIdentity,
10} from "../../helpers/oidc-mock";
11import type { E2eContext } from "../global-setup";
12 
13export interface OperatorIdentity extends MockIdentity {
14 displayName: string;
15 slug: string;
16}
17 
18const OPERATOR_IDENTITY: OperatorIdentity = {
19 sub: E2E_BASELINE_TESSERA_SUB,
20 email: E2E_BASELINE_EMAIL,
21 email_verified: true,
22 name: E2E_BASELINE_NAME,
23 displayName: E2E_BASELINE_NAME,
24 slug: E2E_BASELINE_SLUG,
25};
26 
27export const LOGIN_URL_PATTERN = /\/app\/login(?:[?#]|$)/u;
28 
29interface AnvilFixtures {
30 e2eContext: E2eContext;
31 operatorIdentity: OperatorIdentity;
32 livePage: Page;
33}
34 
35export const test = base.extend<AnvilFixtures>({
36 e2eContext: async ({}, use) => {
37 const contextPath = process.env.ANVIL_E2E_CONTEXT_PATH!;
38 const raw = await readFile(contextPath, "utf8");
39 use(JSON.parse(raw) as E2eContext);
40 },
41 
42 operatorIdentity: async ({}, use) => {
43 use(OPERATOR_IDENTITY);
44 },
45 
46 livePage: async ({ page }, use) => {
47 await use(page);
48 },
49});
50 
51export { expect };
52 
53export async function loginViaUi(
54 page: Page,
55 e2eContext: E2eContext,
56 identity: OperatorIdentity = OPERATOR_IDENTITY,
57): Promise<void> {
58 await setMockOidcIdentity(e2eContext.oidcIssuer, identity);
59 await page.goto("/app/login");
60 const signInButton = page.getByRole("button", { name: "Sign in with tessera" });
61 await expect(signInButton).toBeEnabled({ timeout: 15_000 });
62 await signInButton.click();
63 await page.waitForURL(/\/app\/projects(?:[?#]|$)/u);
64}