SPB Git
1.6 KB · 19 lines typescript
1import { expect, test } from "@playwright/test";2/** Admin flows run only when E2E_ADMIN_EMAIL / E2E_ADMIN_PASSWORD are provided (desktop project). */3const email = process.env.E2E_ADMIN_EMAIL, pw = process.env.E2E_ADMIN_PASSWORD;4test.describe("admin @desktop-only", () => {5  test("unauthenticated access is refused", async ({ request }) => {6    for (const p of ["/admin", "/admin/papers", "/admin/settings"]) { const r = await request.get(p, { maxRedirects: 0 }); expect([302, 307]).toContain(r.status()); expect(r.headers().location).toContain("/login"); }7    const u = await request.post("/api/admin/upload", { multipart: { paper_id: "x" } }); expect(u.status()).toBe(401);8  });9  test("login, dashboard, paper edit, audit", async ({ page }) => {10    test.skip(!email || !pw, "no admin credentials in env");11    await page.goto("/login"); await page.getByLabel("E-mail").fill(email!); await page.getByLabel("Password").fill(pw!); await page.getByRole("button", { name: "Sign in" }).click();12    await page.waitForURL(/\/admin/); await expect(page.getByRole("heading", { name: /Dashboard|Account/ })).toBeVisible();13    if (page.url().includes("must_change")) { await expect(page.getByText(/change the initial password/i)).toBeVisible(); return; } // first login: password change enforced before anything else14    await page.goto("/admin/papers"); await expect(page.locator("table.data tbody tr").first()).toBeVisible();15    await page.goto("/admin/ingest"); await expect(page.getByRole("heading", { name: "Manuscript ingestion" })).toBeVisible();16    await page.goto("/admin/audit"); await expect(page.locator("table.data tbody tr").first()).toBeVisible();17  });18});19
Files · 734affbc3f56470ca2e43d159e14b200279bfbfc
Menu

Theme