|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +async function dismissResumeModal(page) { |
| 4 | + const newGameBtn = page.locator('#resumeNoBtn'); |
| 5 | + if (await newGameBtn.isVisible({ timeout: 500 })) { |
| 6 | + await newGameBtn.click(); |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +async function waitForTestApi(page) { |
| 11 | + await page.waitForFunction(() => !!window.__shandokuTest); |
| 12 | +} |
| 13 | + |
| 14 | +test.describe('Rift mode regression coverage', () => { |
| 15 | + test.beforeEach(async ({ page }) => { |
| 16 | + await page.goto('/?e2e=1'); |
| 17 | + await dismissResumeModal(page); |
| 18 | + await waitForTestApi(page); |
| 19 | + }); |
| 20 | + |
| 21 | + test('forceRift creates visible rift node and opens modal on tap', async ({ page }) => { |
| 22 | + await page.evaluate(async () => { |
| 23 | + await window.__shandokuTest.forceRift(); |
| 24 | + }); |
| 25 | + |
| 26 | + const riftNode = page.locator('.cell.rift-node').first(); |
| 27 | + await expect(riftNode).toBeVisible(); |
| 28 | + |
| 29 | + await riftNode.click(); |
| 30 | + await expect(page.locator('#riftModal')).toBeVisible(); |
| 31 | + await expect(page.locator('#riftRestoreBtn')).toBeVisible(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('restore from Rift modal returns last solvable snapshot', async ({ page }) => { |
| 35 | + await page.evaluate(() => { |
| 36 | + const solvable = Array.from({ length: 9 }, () => Array(9).fill(0)); |
| 37 | + solvable[0][0] = 1; |
| 38 | + window.__shandokuTest.setBoardState({ |
| 39 | + grid: solvable, |
| 40 | + startingGrid: Array.from({ length: 9 }, () => Array(9).fill(0)), |
| 41 | + }); |
| 42 | + |
| 43 | + const unsolvable = solvable.map((row) => row.slice()); |
| 44 | + unsolvable[0][1] = 1; |
| 45 | + window.__shandokuTest.setBoardState({ |
| 46 | + grid: unsolvable, |
| 47 | + startingGrid: Array.from({ length: 9 }, () => Array(9).fill(0)), |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + await page.evaluate(async () => { |
| 52 | + await window.__shandokuTest.forceRift(); |
| 53 | + }); |
| 54 | + |
| 55 | + const riftNode = page.locator('.cell.rift-node').first(); |
| 56 | + await expect(riftNode).toBeVisible(); |
| 57 | + await riftNode.click(); |
| 58 | + await page.locator('#riftRestoreBtn').click(); |
| 59 | + |
| 60 | + await expect(page.locator('[data-r="0"][data-c="0"]')).toHaveText('1'); |
| 61 | + await expect(page.locator('[data-r="0"][data-c="1"]')).toHaveText(''); |
| 62 | + }); |
| 63 | +}); |
0 commit comments