Files
agentic-labs-challenge/adaptive-loop/tests/e2e.spec.ts
T
AlexKucera 2c1d0fc4d0 (Adaptive Loop) Pass 3
(Adaptive Loop) Record freeze commit hash in context manifest
2026-08-13 15:23:35 +02:00

135 lines
6.3 KiB
TypeScript

import { test, expect } from "@playwright/test";
import { readFileSync } from "fs";
type Fix = { fixtures: Record<string, { win: { ring: string; dir: string }[]; loss: { ring: string; dir: string }[] }> };
const data = JSON.parse(readFileSync("test/solver-fixtures.json", "utf8")) as Fix;
const s1win = data.fixtures["s1-heat"].win;
const s1loss = data.fixtures["s1-heat"].loss;
const BASE = "http://localhost:4173";
test("loads, renders title, no console errors", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (e) => errors.push(String(e)));
page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
await page.goto(BASE);
await expect(page.locator("h1")).toContainText("Adaptive Loop");
await expect(page.getByRole("button", { name: "New Campaign" })).toBeVisible();
expect(errors).toEqual([]);
});
test("start campaign, board renders, controls present", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
await expect(page.locator(".board-svg")).toBeVisible();
await expect(page.getByRole("button", { name: /Rotate inner clockwise/ })).toBeVisible();
await expect(page.locator(".tile").first()).toBeVisible();
// 36 tiles total
await expect(page.locator(".tile")).toHaveCount(36);
});
test("preview then commit advances turn and moves tiles", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
const turnBefore = await page.locator(".turn").textContent();
expect(turnBefore).toContain("Turn 0");
// select outer cw
await page.getByRole("button", { name: /Rotate outer clockwise/ }).click();
await expect(page.locator("#btnCommit")).toBeEnabled();
// selection persists: move focus away, commit still enabled
await page.locator("#btnCancel").focus();
await expect(page.locator("#btnCommit")).toBeEnabled();
await page.locator("#btnCommit").click();
await expect(page.locator(".turn")).toContainText("Turn 1");
});
test("keyboard operation (1 selects, Enter commits, Esc cancels)", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
await page.keyboard.press("3"); // middle cw
await expect(page.locator(".rot.selected")).toHaveCount(1);
await page.keyboard.press("Enter");
await expect(page.locator(".turn")).toContainText("Turn 1");
await page.keyboard.press("1"); // inner cw
await page.keyboard.press("Escape");
await expect(page.locator(".rot.selected")).toHaveCount(0);
});
test("full scenario 1 win via verified route -> outcome + lineage choice (adaptation)", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
for (const a of s1win) {
await page.getByRole("button", { name: new RegExp(`Rotate ${a.ring} ${a.dir === "cw" ? "clockwise" : "counter-clockwise"}`) }).click();
await page.locator("#btnCommit").click();
}
// won -> lineage choice or next scenario
await expect(page.locator("h1, h2").first()).toContainText(/Lineage choice|Endurance|Adaptive Loop/i, { timeout: 10000 });
});
test("lose then retry via verified loss route", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
for (const a of s1loss) {
await page.getByRole("button", { name: new RegExp(`Rotate ${a.ring} ${a.dir === "cw" ? "clockwise" : "counter-clockwise"}`) }).click();
await page.locator("#btnCommit").click();
}
await expect(page.locator(".turn").first()).toContainText(/collapsed|expired|Turn limit|Ecosystem|Turn 8/i);
await expect(page.getByRole("button", { name: "Retry" })).toBeVisible();
await page.getByRole("button", { name: "Retry" }).click();
await expect(page.locator(".turn")).toContainText("Turn 0");
});
test("Save & Quit, reload, Continue restores exact state", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
await page.getByRole("button", { name: /Rotate inner clockwise/ }).click();
await page.locator("#btnCommit").click();
await expect(page.locator(".turn")).toContainText("Turn 1");
await page.locator("#btnSaveQuit").click();
await expect(page.locator("#btnContinue")).toBeEnabled();
// reload (simulates close/reopen)
await page.reload();
await page.locator("#btnContinue").click();
await expect(page.locator(".turn")).toContainText("Turn 1");
});
test("narrow viewport (390px) has no horizontal scroll and controls reachable", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 800 });
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
await expect(page.locator(".board-svg")).toBeVisible();
const scrollWidth = await page.evaluate(() => document.documentElement.scrollWidth);
const clientWidth = await page.evaluate(() => document.documentElement.clientWidth);
expect(scrollWidth).toBeLessThanOrEqual(clientWidth);
await expect(page.locator("#btnCommit")).toBeVisible();
});
test("200% zoom keeps board and controls usable", async ({ page }) => {
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
await page.evaluate(() => { (document.body.style as any).zoom = "2"; });
await expect(page.locator(".board-svg")).toBeVisible();
await expect(page.locator("#btnCommit")).toBeVisible();
});
test("reduced-motion preference renders without error", async ({ browser }) => {
const ctx = await browser.newContext({ reducedMotion: "reduce", viewport: { width: 1280, height: 900 } });
const page = await ctx.newPage();
const errors: string[] = [];
page.on("pageerror", (e) => errors.push(String(e)));
await page.goto(BASE);
await page.getByRole("button", { name: "New Campaign" }).click();
await expect(page.locator(".board-svg")).toBeVisible();
expect(errors).toEqual([]);
await ctx.close();
});
test("malformed save recovers safely", async ({ page }) => {
await page.goto(BASE);
await page.evaluate(() => localStorage.setItem("adaptive-loop-save-v1", "{not valid json"));
await page.reload(); // re-evaluate hasSave()
await page.locator("#btnContinue").click();
// should not crash; announce a recovery reason
await expect(page.locator("#announce")).toContainText(/corrupt|invalid|version|missing/i);
});