Skip to content

Commit 8506b50

Browse files
authored
Merge pull request #30 from ssfinney/codex/inspect-shandoku-codebase-for-rift-mode-5fl5wq
Add test hooks, rift extension API, and Playwright rift-mode tests
2 parents 5b6aedf + 5ce2de9 commit 8506b50

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

tests/rift-mode.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)