1import test from 'node:test';2import assert from 'node:assert/strict';3import {4 HUD_MOTION,5 actionMatches,6 keycapPressFrame,7 motionProgress,8 stepRollFrame,9} from '../src/render/motion.js';1011test('HUD motion uses settled end states and bounded press phases', () => {12 assert.equal(motionProgress({ now: 50, startedAt: 0, duration: 100 }), 0.5);13 assert.equal(motionProgress({ now: 50, startedAt: 0, duration: 100, reducedMotion: true }), 1);14 const start = keycapPressFrame({ now: 0, startedAt: 0 });15 const middle = keycapPressFrame({ now: HUD_MOTION.keycapPress * 0.45, startedAt: 0 });16 const end = keycapPressFrame({ now: HUD_MOTION.keycapPress, startedAt: 0 });17 assert.equal(start.offsetY, 0);18 assert.equal(middle.pressed, true);19 assert.ok(middle.offsetY > 0);20 assert.equal(end.pressed, false);21 assert.equal(end.offsetY, 0);22});2324test('keycap actions match keyboard and semantic input names', () => {25 assert.equal(actionMatches('undo', 'z'), true);26 assert.equal(actionMatches('move-right', 'ArrowRight'), true);27 assert.equal(actionMatches('menu', 'escape'), true);28 assert.equal(actionMatches('wait', 'restart'), false);29 assert.equal(actionMatches('navigate', 'ArrowDown'), true);30 assert.equal(actionMatches('confirm', 'Enter'), true);31 assert.equal(actionMatches('workshop', 'Space'), true);32 assert.equal(actionMatches('details', 'i'), true);33 assert.equal(actionMatches('copy', 'c'), true);34});3536test('step digits roll up on forward turns and down on undo', () => {37 const forward = stepRollFrame({ now: 1060, startedAt: 1000, from: 7, to: 8 });38 assert.equal(forward.direction, 1);39 assert.equal(forward.changed[1], true);40 assert.ok(forward.eased > 0);41 assert.equal(forward.newDigits, '08');42 const undo = stepRollFrame({ now: 1060, startedAt: 1000, from: 8, to: 7 });43 assert.equal(undo.direction, -1);44 assert.equal(undo.oldDigits, '08');45 assert.equal(undo.newDigits, '07');46 const reduced = stepRollFrame({ now: 0, startedAt: 1000, from: 8, to: 7, reducedMotion: true });47 assert.equal(reduced.progress, 1);48});