refactor(e2e): organize fixtures by feature

This commit is contained in:
2026-07-16 11:49:58 +08:00
parent 764bb5a862
commit e730799aa5
28 changed files with 521 additions and 1335 deletions
+41
View File
@@ -0,0 +1,41 @@
import { expect, type BrowserContext, type Page } from "@playwright/test";
import { seedEmailSession } from "./auth";
export async function clearBrowserState(context: BrowserContext, page: Page, baseURL?: string) {
await context.clearCookies();
const client = await context.newCDPSession(page);
const origins = new Set([new URL(baseURL ?? "http://127.0.0.1:3000").origin, "http://127.0.0.1:3000", "http://localhost:3000"]);
for (const origin of origins) {
await client.send("Storage.clearDataForOrigin", { origin, storageTypes: "all" }).catch(() => {});
}
}
export async function enterChatFromSplash(page: Page, options: { expectedUrl?: RegExp; timeout?: number; waitUntil?: "commit" | "domcontentloaded" | "load" | "networkidle" } = {}) {
const { expectedUrl = /\/chat$/, timeout = 10_000, waitUntil } = options;
await page.goto("/splash", { waitUntil });
const startChatButton = page.getByRole("button", { name: "Start Chatting" });
await expect(startChatButton).toBeVisible({ timeout });
await expect(startChatButton).toBeEnabled();
for (let attempt = 0; attempt < 3; attempt += 1) {
await startChatButton.click();
try { await expect(page).toHaveURL(expectedUrl, { timeout: 3_000 }); return; } catch { await page.waitForTimeout(500); }
}
await expect(page).toHaveURL(expectedUrl, { timeout });
}
export async function dismissChatInterruptions(page: Page) {
for (const buttonName of ["Later", "Cancel", "OK"]) {
const button = page.getByRole("button", { name: buttonName }).first();
if (await button.isVisible().catch(() => false)) await button.click();
}
}
export async function signInWithEmailAndOpenChat(page: Page) {
await seedEmailSession(page);
const historyResponsePromise = page.waitForResponse("**/api/chat/history**");
await page.goto("/chat");
await historyResponsePromise;
await dismissChatInterruptions(page);
await expect(page.getByRole("textbox", { name: "Message" })).toBeEnabled({ timeout: 20_000 });
}