import { expect, test } from "@playwright/test"; /** * Smoke coverage for the unified minigames leaderboards: the period view, the * All-Time switch (which also reveals the cardtable games) and the period * standings card plus collapsed all-time board on a game page. */ test.describe("Minigame leaderboards", () => { 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 the period boards, game tabs and achievements", async ({ page }) => { await page.goto("/minigames/leaderboards"); await expect( page.getByRole("heading", { level: 1, name: "Minigame Leaderboards" }), ).toBeVisible(); await expect(page.getByRole("tab", { name: "Flight Simulator" })).toBeVisible(); await expect(page.getByRole("tab", { name: "OPORD Recall" })).toBeVisible(); // Cardtable games are not period-scored, so they only appear All-Time. await expect(page.getByRole("tab", { name: "Poker" })).toHaveCount(0); await expect(page.getByText("Achievements", { exact: true })).toBeVisible(); }); test("switching to All-Time surfaces every registered game", async ({ page }) => { await page.goto("/minigames/leaderboards"); await page.getByRole("combobox").click(); await page.getByRole("option", { name: /All-Time/ }).click(); await expect(page.getByRole("tab", { name: "Poker" })).toBeVisible({ timeout: 15_000 }); await expect(page.getByRole("tab", { name: "Blackjack" })).toBeVisible(); }); test("a game page centers period standings with all-time collapsed", async ({ page }) => { await page.goto("/minigames/flappy"); await expect(page.getByRole("link", { name: "All boards" })).toBeVisible(); const allTime = page.getByRole("button", { name: /All-time leaderboard/ }); await expect(allTime).toBeVisible(); await expect(allTime).toHaveAttribute("data-state", "closed"); await expect(page.getByText("Flight Simulator Leaderboard")).toHaveCount(0); // The dev-server first navigation can hydrate slowly, so retry the toggle // until the collapsed board actually mounts. await expect(async () => { await allTime.click(); await expect(page.getByText("Flight Simulator Leaderboard")).toBeVisible({ timeout: 1000 }); }).toPass({ timeout: 20_000 }); }); });