Files
clawmates/frontend/tests/e2e/p5-billing.spec.ts
T
Omar Sobh c417097db2
ci / gates (push) Successful in 6s
ci / frontend (push) Successful in 40s
ci / rust (push) Successful in 3m2s
ci / publish (push) Successful in 42s
ci / e2e (push) Failing after 8m53s
LoginForm: restore proper <label> elements + update e2e tests to the single-step flow
The local-mode LoginForm had drifted to using styled <div> elements as
labels. That's an a11y regression — screen readers can't associate the
label text with the input, and it broke every e2e sign-in helper because
playwright's getByLabel needs a real <label htmlFor="…"> (or aria-label)
association. Restore proper <label htmlFor="email"|"password"> with
matching id="…" on the inputs; keeps the current design comp untouched.

The tests were also written for an OLDER two-step flow — enter email →
click "Continue with work email" → enter password → click "Sign in".
The current form is single-step (both fields, one Sign in click). Update
the shared signIn helper in every spec (p0-p8 + visual) to match, and
switch the label selector to "Email address" so it matches the newly
restored <label> text. Drop the stale a11y assertion in p6 that expected
the two-step button.

Also refresh the marketing landing check in p0-shell.spec.ts:20-22 —
"agentic systems" was in the H1 in an older copy pass; today's H1 is
"Deploy agents at any scale." Update the selector.

Together this unblocks ~30 of the 32 e2e failures; the remaining handful
are downstream product/test drift that will need per-test attention.
2026-07-05 21:27:34 -07:00

69 lines
2.5 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
// P5 exit criterion (spec §17): the full admin + billing loop — credit
// decrement matches token usage, and promo redemption grants credits.
const OWNER_EMAIL = "[email protected]";
const OWNER_PASSWORD = "e2e-password";
async function signIn(page: 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 expect(page.getByRole("heading", { name: "Clawmates" })).toBeVisible();
}
async function readBalance(page: Page): Promise<number> {
await page.getByRole("link", { name: "Credits" }).click();
await expect(page.getByText("Available credits")).toBeVisible();
const text = await page.getByTestId("credit-balance").innerText();
return Number(text.replace(/,/g, ""));
}
test("chat usage decrements credits and shows in the 7-day meter", async ({
page,
}) => {
await signIn(page);
const before = await readBalance(page);
await page.getByRole("link", { name: /Scout/ }).click();
await expect(page).toHaveURL(/\/claws\/.+\/chat\//);
// Fresh session: older sessions carry scenario markers in history that
// would steer the scripted provider away from the plain echo.
const before_url = page.url();
await page.getByRole("button", { name: "New" }).click();
await page.waitForURL((url) => url.toString() !== before_url);
const box = page.getByLabel("Message Scout");
await box.fill("bill me for this message");
await box.press("Enter");
await expect(
page.getByText("I received: bill me for this message"),
).toBeVisible();
await expect
.poll(async () => readBalance(page), { timeout: 15000 })
.toBeLessThan(before);
await expect(page.getByText(/Usage · last 7 days/i)).toBeVisible();
await expect(page.getByText(/tokens \(/)).toBeVisible();
});
test("a promo code redeems exactly once", async ({ page }) => {
await signIn(page);
const before = await readBalance(page);
await page.getByLabel("Promo code").fill("WELCOME500");
await page.getByRole("button", { name: "Redeem" }).click();
await expect(page.getByText("Added 500 credits.")).toBeVisible();
await expect
.poll(async () => readBalance(page))
.toBe(before + 500);
// Second redemption refuses.
await page.getByLabel("Promo code").fill("WELCOME500");
await page.getByRole("button", { name: "Redeem" }).click();
await expect(
page.getByText("That code is invalid or already redeemed."),
).toBeVisible();
});