Skip to content

Commit

Permalink
Maintain currentPlayer/playOrderPos when phase ends (#444)
Browse files Browse the repository at this point in the history
* test: Is `playerOrderPos` maintained on phase end?

* fix: Don’t set `playerOrderPos` to 0 when resetting phase

* test: Change expected `currentPlayer` in test

“turn › endTurn is not called twice in one move” expected 
`currentPlayer` to be `0` for a new phase. This is no longer the case.
  • Loading branch information
delucis authored and nicolodavis committed Aug 27, 2019
1 parent a2961c8 commit 28e8b67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export function Flow({ moves, phases, endIf, turn, events, plugins }) {
G = conf.onEnd(G, ctx);

// Reset the phase.
ctx = { ...ctx, phase: null, playOrderPos: 0 };
ctx = { ...ctx, phase: null };

// Add log entry.
const action = gameEvent('endPhase', arg);
Expand Down
16 changes: 15 additions & 1 deletion src/core/flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ describe('phases', () => {
state = flow.processGameEvent(state, gameEvent('endPhase'));
expect(state.ctx.phase).toBe(null);
});

test('maintain playOrderPos on phase end', () => {
const flow = Flow({
phases: { A: { start: true, next: 'B' }, B: { next: 'A' } },
});
let state = { G: {}, ctx: flow.ctx(3) };
state = flow.init(state);

expect(state.ctx.playOrderPos).toBe(0);
state = flow.processGameEvent(state, gameEvent('endTurn'));
expect(state.ctx.playOrderPos).toBe(1);
state = flow.processGameEvent(state, gameEvent('endPhase'));
expect(state.ctx.playOrderPos).toBe(1);
});
});

describe('turn', () => {
Expand Down Expand Up @@ -357,7 +371,7 @@ describe('turn', () => {
state = flow.processMove(state, makeMove().payload);

expect(state.ctx.phase).toBe('B');
expect(state.ctx.currentPlayer).toBe('0');
expect(state.ctx.currentPlayer).toBe('1');
expect(state.ctx.turn).toBe(3);
});
});
Expand Down

0 comments on commit 28e8b67

Please sign in to comment.