// Unit test for the input mapping logic — runs without a display or nut-js. // Verifies keymap returns sane shapes and inject() no-ops gracefully. const inject = require('./inject'); const assert = require('assert'); let pass = 0; function check(name, cond) { assert.ok(cond, name); console.log(' ok -', name); pass++; } (async () => { console.log('input layer tests:'); check('module exposes inject/releaseAll/available', typeof inject.inject === 'function' && typeof inject.releaseAll === 'function'); check('available is boolean', typeof inject.available === 'boolean'); // mapKey returns null when nut-js absent (sandbox) — that is expected & safe. if (!inject.available) { check('mapKey is null-safe without nut-js', inject.mapKey('a', 'KeyA') === null); } else { check('mapKey letter -> array', Array.isArray(inject.mapKey('a', 'KeyA'))); check('mapKey Enter -> array', Array.isArray(inject.mapKey('Enter', 'Enter'))); check('mapKey symbol -> type fallback', inject.mapKey('@', 'Digit2').type === '@'); } // inject() must not throw on any event kind, even with no backend. for (const evt of [ { kind: 'mousemove', x: 0.5, y: 0.5 }, { kind: 'mousedown', button: 0, x: 0.1, y: 0.2 }, { kind: 'mouseup', button: 0 }, { kind: 'dblclick', x: 0.3, y: 0.3 }, { kind: 'scroll', dx: 0, dy: 120 }, { kind: 'keydown', key: 'a', code: 'KeyA' }, { kind: 'keyup', key: 'a', code: 'KeyA' }, ]) { await inject.inject(evt); } check('inject handled all event kinds without throwing', true); await inject.releaseAll(); check('releaseAll clears state', true); console.log(`\n${pass} checks passed.`); })();