Ensure backward compatibility for single-player mode
Added explicit tests documenting that createCombatState, drawCards, playCard, and endTurn all accept the original single-string/no-index signatures and keep state.player and state.enemy aliases in sync.
This commit is contained in:
parent
62425eadd7
commit
7e46b190f1
1 changed files with 39 additions and 0 deletions
|
|
@ -226,3 +226,42 @@ describe("endTurn - indexed player", () => {
|
||||||
expect(next.combat.phase).toBe("player_turn");
|
expect(next.combat.phase).toBe("player_turn");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("backward compat - single string args", () => {
|
||||||
|
test("string args produce state with compat player/enemy aliases", () => {
|
||||||
|
const state = createCombatState("ironclad", "jaw_worm");
|
||||||
|
// compat aliases still work
|
||||||
|
expect(state.player).toBeDefined();
|
||||||
|
expect(state.enemy).toBeDefined();
|
||||||
|
expect(state.player.hp).toBe(11);
|
||||||
|
expect(state.enemy.name).toBe("Jaw Worm");
|
||||||
|
// arrays also populated
|
||||||
|
expect(state.players).toHaveLength(1);
|
||||||
|
expect(state.enemies).toHaveLength(1);
|
||||||
|
expect(state.combat.playerCount).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("drawCards with single count arg still works", () => {
|
||||||
|
const state = createCombatState("ironclad", "jaw_worm");
|
||||||
|
const next = drawCards(state, 3);
|
||||||
|
expect(next.player.hand).toHaveLength(3);
|
||||||
|
expect(next.players[0].hand).toHaveLength(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("playCard with just handIndex still works", () => {
|
||||||
|
let state = createCombatState("ironclad", "jaw_worm");
|
||||||
|
state = drawCards(state, 5);
|
||||||
|
const cardIndex = state.player.hand.indexOf("strike_r");
|
||||||
|
const next = playCard(state, cardIndex);
|
||||||
|
expect(next.player.energy).toBe(2);
|
||||||
|
expect(next.players[0].energy).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("endTurn with no playerIndex still works", () => {
|
||||||
|
let state = createCombatState("ironclad", "jaw_worm");
|
||||||
|
state = drawCards(state, 5);
|
||||||
|
const next = endTurn(state);
|
||||||
|
expect(next.combat.phase).toBe("enemy_turn");
|
||||||
|
expect(next.player.hand).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue