152 lines
6.9 KiB
TypeScript
152 lines
6.9 KiB
TypeScript
// Gate 6 — black-box browser proof against the production build. Public controls
|
|
// only: we click rotation buttons + Commit, never inject domain state or localStorage.
|
|
// Deterministic routes come from the solver fixture so outcomes are guaranteed.
|
|
|
|
import { test, expect, type Page } from "@playwright/test";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
const fixture = JSON.parse(readFileSync(new URL("../tests/fixtures/solver-results.json", import.meta.url), "utf8"));
|
|
|
|
const BASE = "http://127.0.0.1:4173";
|
|
|
|
async function startCampaign(page: Page) {
|
|
await page.goto(BASE);
|
|
await page.click("#new-campaign-btn");
|
|
await expect(page.locator("#board")).toBeVisible();
|
|
}
|
|
|
|
async function commitAction(page: Page, loop: string, dir: string) {
|
|
await page.click(`.rotate-btn[data-loop="${loop}"][data-dir="${dir}"]`);
|
|
await expect(page.locator("#commit-btn")).toBeEnabled();
|
|
await page.click("#commit-btn");
|
|
}
|
|
|
|
async function turnText(page: Page): Promise<string> {
|
|
return (await page.locator('[data-region="objective"] .stat').first().textContent()) ?? "";
|
|
}
|
|
|
|
test("starts a campaign and renders the three-ring board with no console errors", async ({ page }) => {
|
|
const errors: string[] = [];
|
|
page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
|
|
await startCampaign(page);
|
|
await expect(page.locator("h1")).toContainText("Cultivation Quota");
|
|
// three interlocking hexagonal rings (one polygon per loop), 12 chamber nodes
|
|
await expect(page.locator("#board polygon.ring")).toHaveCount(3);
|
|
await expect(page.locator("#board g.chamber")).toHaveCount(12);
|
|
expect(errors).toEqual([]);
|
|
});
|
|
|
|
test("preview enables Commit and persists until commit; commit advances the turn", async ({ page }) => {
|
|
await startCampaign(page);
|
|
// selecting a rotation enables Commit
|
|
await page.click('.rotate-btn[data-loop="A"][data-dir="cw"]');
|
|
await expect(page.locator("#commit-btn")).toBeEnabled();
|
|
// moving focus away does NOT disable Commit (selection persists)
|
|
await page.locator("#commit-btn").focus();
|
|
await expect(page.locator("#commit-btn")).toBeEnabled();
|
|
await page.click("#commit-btn");
|
|
await expect(await turnText(page)).toContain("Turn 1");
|
|
});
|
|
|
|
test("rotation causes chamber movement + channel flow interaction", async ({ page }) => {
|
|
await startCampaign(page);
|
|
// capture a chamber's population text, commit, confirm the board changed
|
|
const before = await page.locator("#board").innerHTML();
|
|
await commitAction(page, "A", "cw");
|
|
const after = await page.locator("#board").innerHTML();
|
|
expect(after).not.toBe(before);
|
|
// flow dots are rendered along owner edges
|
|
await expect(page.locator("#board .flow-dot").first()).toBeVisible();
|
|
});
|
|
|
|
test("a full win route wins scenario 1 and offers a trait choice (adaptation exploited)", async ({ page }) => {
|
|
await startCampaign(page);
|
|
const route = fixture.scenarios.find((s: any) => s.id === "s1-heat").win.actions as { loop: string; direction: string }[];
|
|
for (const a of route) await commitAction(page, a.loop, a.direction === "cw" ? "cw" : "ccw");
|
|
// win -> scenario complete affordance
|
|
await expect(page.locator("#continue-win-btn")).toBeVisible();
|
|
// the route unlocked an adaptation (a pressure cell is marked adapted at some point)
|
|
const adapted = await page.locator('[data-region="pressures"] .pcell.adapted').count();
|
|
expect(adapted).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("a fixed bad sequence loses (expire or collapse), then retry restarts the scenario", async ({ page }) => {
|
|
await startCampaign(page);
|
|
// drive to a terminal by repeating a single rotation; stop once a terminal affordance appears
|
|
const sc = fixture.scenarios.find((s: any) => s.id === "s1-heat");
|
|
for (let i = 0; i < sc.turnLimit + 1; i++) {
|
|
if (await page.locator("#retry-btn").count() > 0) break;
|
|
await commitAction(page, "A", "cw");
|
|
}
|
|
// a terminal retry affordance appears (collapse or expire)
|
|
await expect(page.locator("#retry-btn")).toBeVisible();
|
|
await page.click("#retry-btn");
|
|
await expect(await turnText(page)).toContain("Turn 0");
|
|
});
|
|
|
|
test("Save & Quit then close/reopen/Continue restores exact state", async ({ page }) => {
|
|
await startCampaign(page);
|
|
await commitAction(page, "A", "cw");
|
|
await commitAction(page, "B", "ccw");
|
|
const saved = await turnText(page);
|
|
await page.click("#save-quit-btn");
|
|
await expect(page.locator("h1")).toContainText("Adaptive Loop"); // back to title
|
|
// close/reopen
|
|
await page.goto(BASE);
|
|
await expect(page.locator("#continue-btn")).toBeEnabled();
|
|
await page.click("#continue-btn");
|
|
await expect(await turnText(page)).toBe(saved);
|
|
});
|
|
|
|
test("core actions operable by keyboard", async ({ page }) => {
|
|
await startCampaign(page);
|
|
await page.keyboard.press("Tab"); // focus into the page
|
|
// focus a rotation control, select it, then commit via keyboard on Commit
|
|
await page.locator('.rotate-btn[data-loop="C"][data-dir="cw"]').focus();
|
|
await expect(page.locator("#commit-btn")).toBeEnabled();
|
|
await page.locator("#commit-btn").focus();
|
|
await page.keyboard.press("Enter");
|
|
await expect(await turnText(page)).toContain("Turn 1");
|
|
// Escape cancels a fresh preview
|
|
await page.locator('.rotate-btn[data-loop="A"][data-dir="ccw"]').focus();
|
|
await page.keyboard.press("Escape");
|
|
await expect(page.locator("#commit-btn")).toBeDisabled();
|
|
});
|
|
|
|
test("narrow viewport (390px) has no horizontal scroll and reachable controls", async ({ page }) => {
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await startCampaign(page);
|
|
await commitAction(page, "A", "cw");
|
|
const scrollWidth = await page.evaluate(() => document.documentElement.scrollWidth);
|
|
expect(scrollWidth).toBeLessThanOrEqual(410);
|
|
await expect(page.locator("#commit-btn")).toBeVisible();
|
|
await expect(page.locator("#save-quit-btn")).toBeVisible();
|
|
});
|
|
|
|
test("200% zoom (2x device pixel ratio) keeps the board and controls usable", async ({ browser }) => {
|
|
const context = await browser.newContext({ viewport: { width: 512, height: 800 }, deviceScaleFactor: 2 });
|
|
const page = await context.newPage();
|
|
await startCampaign(page);
|
|
await commitAction(page, "B", "cw");
|
|
await expect(page.locator("#board")).toBeVisible();
|
|
await expect(page.locator(".rotate-btn").first()).toBeVisible();
|
|
await context.close();
|
|
});
|
|
|
|
test("reduced-motion emulation renders without animation reliance", async ({ browser }) => {
|
|
const context = await browser.newContext({ reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
await startCampaign(page);
|
|
await commitAction(page, "C", "cw");
|
|
await expect(page.locator("#board")).toBeVisible();
|
|
await context.close();
|
|
});
|
|
|
|
test("multiple scenarios are reachable via Replay Standalone", async ({ page }) => {
|
|
await page.goto(BASE);
|
|
await page.click("#standalone-btn");
|
|
await expect(page.locator(".scenario-pick")).toHaveCount(5);
|
|
await page.click('.scenario-pick[data-scenario="s3-toxin"]');
|
|
await expect(page.locator("h1")).toContainText("Cleansing");
|
|
});
|