|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +async function openFreshGame(page) { |
| 4 | + await page.addInitScript(() => { |
| 5 | + localStorage.clear(); |
| 6 | + sessionStorage.clear(); |
| 7 | + }); |
| 8 | + await page.goto('/?e2e=1'); |
| 9 | + await expect(page.locator('#board .cell')).toHaveCount(81); |
| 10 | +} |
| 11 | + |
| 12 | +test.describe('Shandoku smoke + core interactions', () => { |
| 13 | + test('app loads and board renders 81 cells', async ({ page }) => { |
| 14 | + await openFreshGame(page); |
| 15 | + |
| 16 | + await expect(page.locator('h1')).toContainText('Shandoku'); |
| 17 | + await expect(page.locator('#status')).toContainText('Tap a cell'); |
| 18 | + }); |
| 19 | + |
| 20 | + test('cell selection works', async ({ page }) => { |
| 21 | + await openFreshGame(page); |
| 22 | + |
| 23 | + const targetCell = page.locator('.cell:not(.fixed)').first(); |
| 24 | + await targetCell.click(); |
| 25 | + await expect(targetCell).toHaveClass(/selected/); |
| 26 | + }); |
| 27 | + |
| 28 | + test('entering a number updates the cell', async ({ page }) => { |
| 29 | + await openFreshGame(page); |
| 30 | + |
| 31 | + await page.evaluate(() => { |
| 32 | + window.__shandokuTest.setBoardState({ |
| 33 | + grid: Array.from({ length: 9 }, () => Array.from({ length: 9 }, () => 0)), |
| 34 | + startingGrid: Array.from({ length: 9 }, () => Array.from({ length: 9 }, () => 0)), |
| 35 | + selected: { r: 0, c: 0 } |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + await page.getByRole('button', { name: 'Enter 5' }).click(); |
| 40 | + |
| 41 | + const editedCell = page.locator('.cell[data-r="0"][data-c="0"]'); |
| 42 | + await expect(editedCell).toHaveText('5'); |
| 43 | + await expect(editedCell).toHaveClass(/user/); |
| 44 | + }); |
| 45 | + |
| 46 | + test('direct conflict is visibly indicated', async ({ page }) => { |
| 47 | + await openFreshGame(page); |
| 48 | + |
| 49 | + await page.evaluate(() => { |
| 50 | + const emptyBoard = Array.from({ length: 9 }, () => Array.from({ length: 9 }, () => 0)); |
| 51 | + emptyBoard[0][0] = 1; |
| 52 | + window.__shandokuTest.setBoardState({ |
| 53 | + grid: emptyBoard, |
| 54 | + startingGrid: Array.from({ length: 9 }, () => Array.from({ length: 9 }, () => 0)), |
| 55 | + selected: { r: 0, c: 1 } |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + await page.getByRole('button', { name: 'Enter 1' }).click(); |
| 60 | + |
| 61 | + const conflictCell = page.locator('.cell[data-r="0"][data-c="1"]'); |
| 62 | + await expect(conflictCell).toHaveClass(/error/); |
| 63 | + await expect(page.locator('#errorStat')).toContainText('err'); |
| 64 | + }); |
| 65 | + |
| 66 | + test('notes mode can be toggled', async ({ page }) => { |
| 67 | + await openFreshGame(page); |
| 68 | + |
| 69 | + const notesBtn = page.locator('#notesModeBtn'); |
| 70 | + await notesBtn.click(); |
| 71 | + await expect(notesBtn).toContainText('Notes On'); |
| 72 | + await expect(notesBtn).toHaveClass(/active/); |
| 73 | + }); |
| 74 | + |
| 75 | + test('saved game can be resumed', async ({ page }) => { |
| 76 | + await openFreshGame(page); |
| 77 | + |
| 78 | + await page.evaluate(() => { |
| 79 | + window.__shandokuTest.setBoardState({ |
| 80 | + grid: [ |
| 81 | + [7, 0, 0, 0, 0, 0, 0, 0, 0], |
| 82 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 83 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 84 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 85 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 86 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 87 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 88 | + [0, 0, 0, 0, 0, 0, 0, 0, 0], |
| 89 | + [0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 90 | + ], |
| 91 | + startingGrid: Array.from({ length: 9 }, () => Array.from({ length: 9 }, () => 0)) |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + await page.reload(); |
| 96 | + |
| 97 | + await expect(page.locator('#resumeModal')).toBeVisible(); |
| 98 | + await page.getByRole('button', { name: 'Resume' }).click(); |
| 99 | + |
| 100 | + await expect(page.locator('.cell[data-r="0"][data-c="0"]')).toHaveText('7'); |
| 101 | + }); |
| 102 | +}); |
0 commit comments