import { expect, test } from "@playwright/test"; /** Admin flows run only when E2E_ADMIN_EMAIL / E2E_ADMIN_PASSWORD are provided (desktop project). */ const email = process.env.E2E_ADMIN_EMAIL, pw = process.env.E2E_ADMIN_PASSWORD; test.describe("admin @desktop-only", () => { test("unauthenticated access is refused", async ({ request }) => { 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"); } const u = await request.post("/api/admin/upload", { multipart: { paper_id: "x" } }); expect(u.status()).toBe(401); }); test("login, dashboard, paper edit, audit", async ({ page }) => { test.skip(!email || !pw, "no admin credentials in env"); 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(); await page.waitForURL(/\/admin/); await expect(page.getByRole("heading", { name: /Dashboard|Account/ })).toBeVisible(); if (page.url().includes("must_change")) { await expect(page.getByText(/change the initial password/i)).toBeVisible(); return; } // first login: password change enforced before anything else await page.goto("/admin/papers"); await expect(page.locator("table.data tbody tr").first()).toBeVisible(); await page.goto("/admin/ingest"); await expect(page.getByRole("heading", { name: "Manuscript ingestion" })).toBeVisible(); await page.goto("/admin/audit"); await expect(page.locator("table.data tbody tr").first()).toBeVisible(); }); });