import { expect, test, type APIRequestContext } from "@playwright/test"; /** * Upcoming-game treatment: a registry row with `status: "upcoming"` is shown * greyed out and non-interactive in the sidebar with a countdown tooltip, and * its game page renders the coming-soon gate instead of the arena. * * The test seeds its own registry rows over the REST API (the e2e database is * seeded from the schema push, which does not run the registry migration) and * deletes them again, so other specs see the built-in fallback list. */ const RELEASE = new Date(Date.now() + 12 * 86_400_000 + 3 * 3_600_000).toISOString(); const seedGame = async ( request: APIRequestContext, game: { key: string; label: string; status: "active" | "upcoming"; route: string }, ): Promise => { const res = await request.post("/api/minigames", { data: { key: game.key, label: game.label, description: "e2e upcoming game", route: game.route, icon: "Radio", category: "core", status: game.status, order: 90, countsForPeriods: false, scoreLabel: "Score", estimatedReleaseDate: RELEASE, }, }); expect(res.status(), `seed ${game.key}: ${await res.text()}`).toBeLessThan(400); const body = (await res.json()) as { doc?: { id: number } }; expect(body.doc?.id, `seed ${game.key} returned no id`).toBeTruthy(); return body.doc!.id; }; const deleteGame = async (request: APIRequestContext, id: number) => { await request.delete(`/api/minigames/${id}`); }; test.describe("Upcoming minigames", () => { test.beforeEach(async ({ page }) => { await page.goto("/login"); await page.getByLabel("Username").fill("dev"); await page.getByLabel("Password").fill("Test123"); await page.getByRole("button", { name: "Log in" }).click(); await page.waitForURL((url) => !url.pathname.startsWith("/login"), { timeout: 30_000 }); }); test("shows a disabled sidebar entry with a countdown tooltip", async ({ page }) => { const id = await seedGame(page.request, { key: "signals-e2e", label: "Signals Intercept", status: "upcoming", route: "/minigames/leaderboards", }); try { await page.goto("/"); await page.getByRole("button", { name: "Minigames" }).click(); const entry = page.getByText("Signals Intercept"); await expect(entry).toBeVisible(); // Non-interactive: the row is not a link and not a menu item. await expect(page.getByRole("menuitem", { name: /Signals Intercept/ })).toHaveCount(0); await entry.hover(); const tooltip = page.getByRole("tooltip"); await expect(tooltip).toContainText("Upcoming ยท releases"); await expect(tooltip).toContainText(/in \d+[dhms]/); } finally { await deleteGame(page.request, id); } }); test("gates the game page with a coming-soon screen", async ({ page }) => { const id = await seedGame(page.request, { key: "flappy", label: "Flight Simulator", status: "upcoming", route: "/minigames/flappy", }); try { await page.goto("/minigames/flappy"); // exact: true keeps this from also matching the countdown's "coming soon" // placeholder text. await expect(page.getByText("Coming soon", { exact: true })).toBeVisible(); await expect(page.getByText(/Estimated release/)).toBeVisible(); // The playable arena is not rendered. await expect(page.getByText("Tap or press Space to flap")).toHaveCount(0); } finally { await deleteGame(page.request, id); } }); });