|
| 1 | +import { test, expect, mockPhoto, mockApiRoutes } from "./fixtures"; |
| 2 | + |
| 3 | +test.describe("Game page – layout", () => { |
| 4 | + test("displays puzzle pieces", async ({ gamePage }) => { |
| 5 | + const pieces = gamePage.locator("[draggable='true']"); |
| 6 | + await expect(pieces.first()).toBeVisible(); |
| 7 | + }); |
| 8 | + |
| 9 | + test("displays the correct number of pieces for 9x13 level", async ({ |
| 10 | + gamePage, |
| 11 | + }) => { |
| 12 | + // mockPhoto: height=800, width=1200 → cols=9, rows=Math.round(800/1200*9)=6 → 54 pieces |
| 13 | + const pieces = gamePage.locator("[draggable='true']"); |
| 14 | + await expect(pieces).toHaveCount(54); |
| 15 | + }); |
| 16 | + |
| 17 | + test("displays the image preview thumbnail", async ({ gamePage }) => { |
| 18 | + const preview = gamePage.locator("img[alt='']").first(); |
| 19 | + await expect(preview).toBeVisible(); |
| 20 | + }); |
| 21 | + |
| 22 | + test("displays move counter starting at 0", async ({ gamePage }) => { |
| 23 | + await expect(gamePage.getByText(/0 Move/)).toBeVisible(); |
| 24 | + }); |
| 25 | + |
| 26 | + test("displays stopwatch starting at 00:00:00", async ({ gamePage }) => { |
| 27 | + await expect(gamePage.getByText("00:00:00")).toBeVisible(); |
| 28 | + }); |
| 29 | + |
| 30 | + test("displays RESTART button", async ({ gamePage }) => { |
| 31 | + await expect( |
| 32 | + gamePage.getByRole("button", { name: /RESTART/i }) |
| 33 | + ).toBeVisible(); |
| 34 | + }); |
| 35 | + |
| 36 | + test("displays PAUSE button", async ({ gamePage }) => { |
| 37 | + await expect( |
| 38 | + gamePage.getByRole("button", { name: /PAUSE/i }) |
| 39 | + ).toBeVisible(); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +test.describe("Game page – pause flow", () => { |
| 44 | + test("opens pause modal when PAUSE is clicked", async ({ gamePage }) => { |
| 45 | + await gamePage.getByRole("button", { name: /PAUSE/i }).click(); |
| 46 | + await expect(gamePage.locator("div.fixed")).toBeVisible(); |
| 47 | + await expect(gamePage.locator("div.text-7xl")).toContainText("Pause"); |
| 48 | + }); |
| 49 | + |
| 50 | + test("pause modal shows Continue button", async ({ gamePage }) => { |
| 51 | + await gamePage.getByRole("button", { name: /PAUSE/i }).click(); |
| 52 | + await expect( |
| 53 | + gamePage.getByRole("button", { name: /Continue/i }) |
| 54 | + ).toBeVisible(); |
| 55 | + }); |
| 56 | + |
| 57 | + test("continue button closes pause modal", async ({ gamePage }) => { |
| 58 | + await gamePage.getByRole("button", { name: /PAUSE/i }).click(); |
| 59 | + await gamePage.getByRole("button", { name: /Continue/i }).click(); |
| 60 | + await expect(gamePage.locator("div.fixed")).not.toBeVisible(); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +test.describe("Game page – restart", () => { |
| 65 | + test("RESTART resets move counter to 0", async ({ gamePage }) => { |
| 66 | + await gamePage.getByRole("button", { name: /RESTART/i }).click(); |
| 67 | + await expect(gamePage.getByText(/0 Move/)).toBeVisible(); |
| 68 | + }); |
| 69 | + |
| 70 | + test("RESTART resets stopwatch to 00:00:00", async ({ gamePage }) => { |
| 71 | + await gamePage.getByRole("button", { name: /RESTART/i }).click(); |
| 72 | + await expect(gamePage.getByText("00:00:00")).toBeVisible(); |
| 73 | + }); |
| 74 | +}); |
| 75 | + |
| 76 | +test.describe("Game page – levels", () => { |
| 77 | + test("15x23 level renders correct piece count", async ({ page }) => { |
| 78 | + await mockApiRoutes(page); |
| 79 | + await page.goto(`/game/${mockPhoto.id}?level=15x23`); |
| 80 | + await page.waitForSelector("[draggable='true']", { timeout: 15_000 }); |
| 81 | + // mockPhoto: height=800, width=1200 → cols=15, rows=Math.round(800/1200*15)=10 → 150 pieces |
| 82 | + await expect(page.locator("[draggable='true']")).toHaveCount(150); |
| 83 | + }); |
| 84 | + |
| 85 | + test("18x26 level renders correct piece count", async ({ page }) => { |
| 86 | + await mockApiRoutes(page); |
| 87 | + await page.goto(`/game/${mockPhoto.id}?level=18x26`); |
| 88 | + await page.waitForSelector("[draggable='true']", { timeout: 15_000 }); |
| 89 | + // mockPhoto: height=800, width=1200 → cols=18, rows=Math.round(800/1200*18)=12 → 216 pieces |
| 90 | + await expect(page.locator("[draggable='true']")).toHaveCount(216); |
| 91 | + }); |
| 92 | +}); |
0 commit comments