|
| 1 | +// SPDX-License-Identifier: MPL-2.0 |
| 2 | +// e2e test for the CadreRouter JS wrapper. |
| 3 | + |
| 4 | +import assert from 'node:assert/strict'; |
| 5 | +import { CadreRouter } from '../src/CadreRouter.js'; |
| 6 | + |
| 7 | +async function main() { |
| 8 | + const wasmPath = process.argv[2] || './router.wasm'; |
| 9 | + const router = await CadreRouter.create(wasmPath, { base: import.meta.url }); |
| 10 | + |
| 11 | + // Initial State assertions |
| 12 | + assert.equal(router.screenW, 1280, 'Initial screen width should be 1280'); |
| 13 | + assert.equal(router.screenH, 720, 'Initial screen height should be 720'); |
| 14 | + assert.equal(router.stackLen, 0, 'Initial stack should be empty'); |
| 15 | + assert.equal(router.stackTop, -1, 'Initial stack top should be -1'); |
| 16 | + assert.equal(router.popupTag, -1, 'Initial popup tag should be -1'); |
| 17 | + |
| 18 | + // Push a screen |
| 19 | + router.push(4); // 4 = Game |
| 20 | + assert.equal(router.stackLen, 1, 'Stack length should be 1 after push'); |
| 21 | + assert.equal(router.stackTop, 4, 'Stack top should be 4 (Game)'); |
| 22 | + |
| 23 | + // Push another screen |
| 24 | + router.push(1); // 1 = CharacterSelect |
| 25 | + assert.equal(router.stackLen, 2, 'Stack length should be 2 after push'); |
| 26 | + assert.equal(router.stackTop, 1, 'Stack top should be 1 (CharacterSelect)'); |
| 27 | + |
| 28 | + // Resize |
| 29 | + router.resize(1920, 1080); |
| 30 | + assert.equal(router.screenW, 1920, 'Width should be updated to 1920'); |
| 31 | + assert.equal(router.screenH, 1080, 'Height should be updated to 1080'); |
| 32 | + |
| 33 | + // Pop |
| 34 | + router.pop(); |
| 35 | + assert.equal(router.stackLen, 1, 'Stack length should be 1 after pop'); |
| 36 | + assert.equal(router.stackTop, 4, 'Stack top should be 4 (Game) after pop'); |
| 37 | + |
| 38 | + // Popup |
| 39 | + router.presentPopup(2); // 2 = Hacking |
| 40 | + assert.equal(router.popupTag, 2, 'Popup tag should be 2 (Hacking)'); |
| 41 | + |
| 42 | + router.dismissPopup(); |
| 43 | + assert.equal(router.popupTag, -1, 'Popup tag should be -1 after dismiss'); |
| 44 | + |
| 45 | + console.log('ALL ASSERTIONS PASS — CadreRouter ran end-to-end'); |
| 46 | +} |
| 47 | + |
| 48 | +main().catch((err) => { |
| 49 | + console.error(err); |
| 50 | + process.exit(1); |
| 51 | +}); |
0 commit comments