import { expect, test } from "@playwright/test"; // P0 exit criterion (spec ยง17): an authenticated empty shell against the // real backend. Seed data comes from clawmates-server's e2e mode. const OWNER_EMAIL = "owner@acme.test"; const OWNER_PASSWORD = "e2e-password"; async function signIn(page: import("@playwright/test").Page) { await page.goto("/login"); await page.getByLabel("Email address").fill(OWNER_EMAIL); await page.getByLabel("Password").fill(OWNER_PASSWORD); await page.getByRole("button", { name: "Sign in" }).click(); await page.waitForURL((url) => !url.pathname.endsWith("/login"), { timeout: 15000 }); } test("unauthenticated visitors see the marketing landing", async ({ page }) => { await page.goto("/"); // "/" rewrites to the public marketing site for logged-out visitors. await expect( page.getByRole("heading", { name: /deploy agents at any scale/i }), ).toBeVisible(); // Sign-in is a link from the marketing nav. await page.getByRole("link", { name: "Sign in" }).first().click(); await expect(page).toHaveURL(/\/login$/); }); test("wrong password shows an error and stays on login", async ({ page }) => { await page.goto("/login"); await page.getByLabel("Email address").fill(OWNER_EMAIL); await page.getByLabel("Password").fill("wrong-password"); await page.getByRole("button", { name: "Sign in" }).click(); // Next.js's route announcer is also role="alert"; scope to the form's. await expect( page.getByRole("alert").filter({ hasText: "Invalid" }), ).toHaveText("Invalid email or password."); await expect(page).toHaveURL(/\/login$/); }); test("signing in reveals the shell: rail, roster, and current user", async ({ page, }) => { await signIn(page); const rail = page.getByRole("complementary"); await expect(rail.getByText("clawmates")).toBeVisible(); await expect( rail.getByRole("list", { name: "Your claws" }).getByText("Scout"), ).toBeVisible(); await expect( rail.getByRole("status", { name: "Scout is online" }), ).toBeVisible(); await expect(rail.getByText("Avery Owner")).toBeVisible(); }); test("team page lists workspace members from the real API", async ({ page, }) => { await signIn(page); await page.getByRole("link", { name: "Team" }).click(); await expect( page.getByRole("heading", { name: "Team", exact: true }), ).toBeVisible(); await expect(page.getByText("1 member in your workspace")).toBeVisible(); const row = page.getByRole("row").filter({ hasText: "Avery Owner" }); await expect(row.getByText(OWNER_EMAIL)).toBeVisible(); await expect(row.getByText("Owner", { exact: true })).toBeVisible(); }); test("credits page shows the seeded balance", async ({ page }) => { await signIn(page); await page.getByRole("link", { name: "Credits" }).click(); await expect( page.getByRole("heading", { name: "Credits", exact: true }), ).toBeVisible(); await expect(page.getByTestId("credit-balance")).toHaveText("1,250"); }); test("signing out returns to login and revokes the session", async ({ page, }) => { await signIn(page); await page.getByRole("button", { name: "Sign out" }).click(); await expect(page).toHaveURL(/\/login$/); // Session revoked: "/" no longer shows the app, it shows marketing. await page.goto("/"); await expect( page.getByRole("heading", { name: /agentic systems/i }), ).toBeVisible(); });