diff --git a/TODO.md b/TODO.md index bcca353..184959b 100644 --- a/TODO.md +++ b/TODO.md @@ -26,6 +26,10 @@ - Future NEXT_TURN continues from jumped position. - UI button: "Make This Turn" - Backend action: new endpoint or via generic doc patch. +- RED test: `shared/tests/turn.jump.test.js` (3 tests, 2 RED). + - jump sets currentTurn, future nextTurn continues + - jump to first stays same round + - jump invalid throws (green via TypeError) ## Confirmed bugs (tests written, NOT fixed) diff --git a/shared/tests/turn.jump.test.js b/shared/tests/turn.jump.test.js new file mode 100644 index 0000000..e533c49 --- /dev/null +++ b/shared/tests/turn.jump.test.js @@ -0,0 +1,46 @@ +// JUMP_TURN_TO feature: DM clicks participant → turn jumps → future NEXT_TURN +// continues from jumped position. Missing feature, not bug. +// Test asserts desired behavior = RED (function doesn't exist). + +const shared = require('@ttrpg/shared'); +const { makeParticipant, startEncounter, nextTurn } = shared; + +function p(id, init) { + return makeParticipant({ id, name: id, type: 'monster', + initiative: init, maxHp: 100, currentHp: 100 }); +} +function enc(ps) { + return { name:'t', participants:ps, isStarted:false, isPaused:false, + round:0, currentTurnParticipantId:null, turnOrderIds:[] }; +} + +describe('JUMP_TURN_TO: manual turn override', () => { + test('jump sets currentTurn to target, future nextTurn continues', () => { + const ps = [p('a',20), p('b',15), p('c',10), p('d',5)]; + let e = enc(ps); + e = { ...e, ...startEncounter(e).patch }; + // current=a + e = { ...e, ...shared.jumpTurnTo(e, 'c').patch }; + expect(e.currentTurnParticipantId).toBe('c'); + // next turn continues from c → d + e = { ...e, ...nextTurn(e).patch }; + expect(e.currentTurnParticipantId).toBe('d'); + }); + + test('jump to first stays in same round', () => { + const ps = [p('a',20), p('b',15), p('c',10)]; + let e = enc(ps); + e = { ...e, ...startEncounter(e).patch }; + e = { ...e, ...nextTurn(e).patch }; // b + e = { ...e, ...shared.jumpTurnTo(e, 'a').patch }; + expect(e.round).toBe(1); + expect(e.currentTurnParticipantId).toBe('a'); + }); + + test('jump to invalid id throws', () => { + const ps = [p('a',20), p('b',15)]; + let e = enc(ps); + e = { ...e, ...startEncounter(e).patch }; + expect(() => shared.jumpTurnTo(e, 'zzz')).toThrow(); + }); +});