Files
SnapOtter/tests/e2e/qa-auth.setup.ts
T
SnapOtter 26465cd844 test: add Playwright e2e tests for QA fixes
11 tests covering: login, tool pages, /tools/:toolId redirect,
invalid slug handling, 404 page, privacy page, automate/files/editor
pages, settings dialog, and dropzone i18n. The 404 catch-all test
gracefully skips on pre-fix builds.
2026-06-06 10:58:23 +08:00

35 lines
1.2 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { test as setup } from "@playwright/test";
const authFile = path.join(process.cwd(), ".playwright", ".auth", "qa-user.json");
setup("authenticate for QA", async ({ page }) => {
const dir = path.dirname(authFile);
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
await page.goto("/login");
await page.getByLabel("Username").fill("admin");
await page.getByLabel("Password").fill("admin");
await page.getByRole("button", { name: /login/i }).click();
const handle = await page.waitForFunction(() => localStorage.getItem("snapotter-token"), null, {
timeout: 15_000,
});
const token = await handle.jsonValue();
// Dismiss analytics consent via API (use same baseURL)
await page.request
.put("/api/v1/user/analytics", {
headers: { Authorization: `Bearer ${token}` },
data: { enabled: false },
})
.catch(() => {});
await page.goto("/", { waitUntil: "domcontentloaded" });
await page.waitForURL((url) => url.pathname === "/", { timeout: 15_000 }).catch(() => {});
await page.waitForLoadState("load");
await page.context().storageState({ path: authFile });
});