diff --git a/__jig_init_test.html b/__jig_init_test.html
index 7db8b7d..59918c0 100644
--- a/__jig_init_test.html
+++ b/__jig_init_test.html
@@ -9,6 +9,8 @@ import * as Phaser from 'phaser';
import JigsawGame from './src/games/jigsaw/JigsawGame.js';
const log = (m) => { document.getElementById('log').textContent += m + '\n'; console.log('[t]', m); };
+let failures = 0;
+const check = (ok, msg) => { if (!ok) { failures++; log('FAIL: ' + msg); } else log('ok: ' + msg); };
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
const ART = [
@@ -37,24 +39,45 @@ const s = () => game.scene.getScene('jigsaw-game');
for (let i = 0; i < 400 && !s(); i++) await wait(50); // boot → jigsaw start is async
if (!s()) throw new Error('jigsaw scene never started');
for (let i = 0; i < 400 && !s().menu; i++) await wait(50);
- if (!s().menu) throw new Error('menu never built');
- // The preview image is loaded asynchronously; give it a moment.
- for (let i = 0; i < 200 && !s().previewImg; i++) await wait(25);
+ check(!!s().menu, 'menu built');
- const sc = s();
- const item = sc.currentImage();
- document.title = 'RESULT:' + JSON.stringify({
- idx: sc.imageIndex,
- n: sc.artwork.length,
- name: item && item.name,
- validName: ART.some((a) => a.name === item.name),
- preview: !!sc.previewImg,
- menuVisible: sc.menu.visible,
- });
- log('initial image: ' + item.name + ' (index ' + sc.imageIndex + ' of ' + sc.artwork.length + ')');
+ // Menu is back to the original shape (random-start button reverted).
+ check(s().randomStartButton === undefined, 'randomStartButton is gone (menu as before)');
+
+ // The initial image is random but always a valid artwork entry, and the
+ // preview shown in the menu matches it.
+ const n = s().artwork.length;
+ const i = s().imageIndex;
+ check(Number.isInteger(i) && i >= 0 && i < n, `initial imageIndex ${i} is a valid index (0..${n - 1})`);
+ check(!!ART.find((a) => a.name === s().currentImage().name), 'initial currentImage() is a known artwork entry');
+
+ // Preview must be built for the initial image (async image load).
+ for (let k = 0; k < 200 && !s().previewImg; k++) await wait(25);
+ check(!!s().previewImg, 'initial preview image is displayed');
+ check(s().thumbName && s().thumbName.text === s().currentImage().name, `thumb name matches initial image (${s().currentImage().name})`);
+
+ // Start Puzzle must still start the initial (random) image.
+ s().selectedDiff = 'easy';
+ s().startPuzzle();
+ let playing = false;
+ for (let k = 0; k < 400 && !playing; k++) { playing = s().state === 'playing'; await wait(25); }
+ check(playing, 'Start Puzzle reaches playing state');
+ check(s().pieces.length === 25, '25 pieces built');
+ check(s().imageName === ART[i].name, `playing image matches the initial pick (${ART[i].name})`);
+
+ // The original 🎲 Random button still randomises the preview in the menu.
+ s().toMenu();
+ const before = s().imageIndex;
+ const seen = new Set([before]);
+ for (let k = 0; k < 10; k++) { s().randomImage(); seen.add(s().imageIndex); await wait(10); }
+ check(seen.size >= 2, '🎲 Random button still changes the selected image');
+
+ document.__initIndex = i;
+ log(failures === 0 ? 'ALL PASS' : failures + ' FAILURES');
+ document.title = failures === 0 ? 'PASS' : 'FAIL:' + failures;
})().catch((e) => {
log('ERROR: ' + ((e && e.stack) || e));
- document.title = 'FAIL:' + ((e && e.message) || e);
+ document.title = 'FAIL:error';
});