77 */
88
99import { FlowWithPhases } from './flow' ;
10- import { TurnOrder , Pass } from './turn-order' ;
10+ import { UpdateTurnOrderState , TurnOrder , Pass } from './turn-order' ;
1111import Game from './game' ;
1212import { makeMove , gameEvent } from './action-creators' ;
1313import { CreateGameReducer } from './reducer' ;
@@ -27,20 +27,6 @@ describe('turnOrder', () => {
2727 expect ( state . ctx . actionPlayers ) . toEqual ( [ '1' ] ) ;
2828 } ) ;
2929
30- test ( 'any' , ( ) => {
31- const flow = FlowWithPhases ( {
32- phases : [ { name : 'A' , turnOrder : TurnOrder . ANY } ] ,
33- } ) ;
34-
35- let state = { ctx : flow . ctx ( 10 ) } ;
36- state = flow . init ( state ) ;
37- expect ( state . ctx . currentPlayer ) . toBe ( 'any' ) ;
38- expect ( state . ctx . actionPlayers ) . toEqual ( [ 'any' ] ) ;
39- state = flow . processGameEvent ( state , gameEvent ( 'endTurn' ) ) ;
40- expect ( state . ctx . currentPlayer ) . toBe ( 'any' ) ;
41- expect ( state . ctx . actionPlayers ) . toEqual ( [ 'any' ] ) ;
42- } ) ;
43-
4430 test ( 'custom' , ( ) => {
4531 const flow = FlowWithPhases ( {
4632 phases : [ { name : 'A' , turnOrder : { first : ( ) => 9 , next : ( ) => 3 } } ] ,
@@ -68,7 +54,7 @@ test('passing', () => {
6854 let state = reducer ( undefined , { type : 'init' } ) ;
6955
7056 expect ( state . ctx . currentPlayer ) . toBe ( '0' ) ;
71- state = reducer ( state , makeMove ( 'pass' ) ) ;
57+ state = reducer ( state , makeMove ( 'pass' , null , '0' ) ) ;
7258 state = reducer ( state , gameEvent ( 'endTurn' ) ) ;
7359 expect ( state . G . allPassed ) . toBe ( undefined ) ;
7460 expect ( state . G . passOrder ) . toEqual ( [ '0' ] ) ;
@@ -83,7 +69,7 @@ test('passing', () => {
8369 expect ( state . G . allPassed ) . toBe ( undefined ) ;
8470
8571 expect ( state . ctx . currentPlayer ) . toBe ( '1' ) ;
86- state = reducer ( state , makeMove ( 'pass' ) ) ;
72+ state = reducer ( state , makeMove ( 'pass' , null , '1' ) ) ;
8773 state = reducer ( state , gameEvent ( 'endTurn' ) ) ;
8874 expect ( state . G . allPassed ) . toBe ( undefined ) ;
8975 expect ( state . G . passOrder ) . toEqual ( [ '0' , '1' ] ) ;
@@ -93,7 +79,7 @@ test('passing', () => {
9379 expect ( state . G . allPassed ) . toBe ( undefined ) ;
9480
9581 expect ( state . ctx . currentPlayer ) . toBe ( '2' ) ;
96- state = reducer ( state , makeMove ( 'pass' ) ) ;
82+ state = reducer ( state , makeMove ( 'pass' , null , '2' ) ) ;
9783 expect ( state . G . allPassed ) . toBe ( true ) ;
9884 expect ( state . ctx . currentPlayer ) . toBe ( '2' ) ;
9985 state = reducer ( state , gameEvent ( 'endTurn' ) ) ;
@@ -114,7 +100,7 @@ test('end game after everyone passes', () => {
114100 const reducer = CreateGameReducer ( { game, numPlayers : 3 } ) ;
115101
116102 let state = reducer ( undefined , { type : 'init' } ) ;
117- expect ( state . ctx . currentPlayer ) . toBe ( 'any' ) ;
103+ expect ( state . ctx . actionPlayers ) . toEqual ( [ '0' , '1' , '2' ] ) ;
118104
119105 // Passes can be make in any order with TurnOrder.ANY.
120106
@@ -250,3 +236,31 @@ describe('change action players', () => {
250236 expect ( state . G ) . toMatchObject ( { } ) ;
251237 } ) ;
252238} ) ;
239+
240+ describe ( 'UpdateTurnOrderState' , ( ) => {
241+ const G = { } ;
242+ const ctx = {
243+ currentPlayer : '0' ,
244+ playOrder : [ '0' , '1' , '2' ] ,
245+ playOrderPos : 0 ,
246+ actionPlayers : [ '0' ] ,
247+ } ;
248+
249+ test ( 'without nextPlayer' , ( ) => {
250+ const t = UpdateTurnOrderState ( G , ctx , TurnOrder . DEFAULT ) ;
251+ expect ( t ) . toMatchObject ( { currentPlayer : '1' } ) ;
252+ } ) ;
253+
254+ test ( 'with nextPlayer' , ( ) => {
255+ const t = UpdateTurnOrderState ( G , ctx , TurnOrder . DEFAULT , '2' ) ;
256+ expect ( t ) . toMatchObject ( { currentPlayer : '2' } ) ;
257+ } ) ;
258+
259+ test ( 'with actionPlayers' , ( ) => {
260+ const t = UpdateTurnOrderState ( G , ctx , TurnOrder . ANY ) ;
261+ expect ( t ) . toMatchObject ( {
262+ currentPlayer : '1' ,
263+ actionPlayers : [ '0' , '1' , '2' ] ,
264+ } ) ;
265+ } ) ;
266+ } ) ;
0 commit comments