@@ -289,6 +289,16 @@ test('undo / redo', () => {
289289 let game = Game ( {
290290 moves : {
291291 move : ( G , ctx , arg ) => ( { ...G , [ arg ] : true } ) ,
292+ nextPhase : ( G , ctx ) => {
293+ ctx . events . endPhase ( { next : 'phase2' } ) ;
294+ } ,
295+ } ,
296+ flow : {
297+ startingPhase : 'phase1' ,
298+ phases : {
299+ phase1 : { } ,
300+ phase2 : { } ,
301+ } ,
292302 } ,
293303 } ) ;
294304
@@ -336,6 +346,42 @@ test('undo / redo', () => {
336346 state = reducer ( state , makeMove ( 'move' , 'A' ) ) ;
337347 expect ( state . G ) . toEqual ( { A : true } ) ;
338348
349+ state = reducer ( state , makeMove ( 'nextPhase' ) ) ;
350+ expect ( state . G ) . toEqual ( { A : true } ) ;
351+ expect ( state . ctx . phase ) . toEqual ( 'phase2' ) ;
352+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
353+
354+ state = reducer ( state , makeMove ( 'move' , 'B' ) ) ;
355+ expect ( state . G ) . toEqual ( { A : true , B : true } ) ;
356+ expect ( state . ctx . phase ) . toEqual ( 'phase2' ) ;
357+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
358+
359+ state = reducer ( state , undo ( ) ) ;
360+ expect ( state . G ) . toEqual ( { A : true } ) ;
361+ expect ( state . ctx . phase ) . toEqual ( 'phase2' ) ;
362+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
363+
364+ state = reducer ( state , redo ( ) ) ;
365+ expect ( state . G ) . toEqual ( { A : true , B : true } ) ;
366+ expect ( state . ctx . phase ) . toEqual ( 'phase2' ) ;
367+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
368+
369+ state = reducer ( state , undo ( ) ) ;
370+ expect ( state . G ) . toEqual ( { A : true } ) ;
371+ expect ( state . ctx . phase ) . toEqual ( 'phase2' ) ;
372+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
373+
374+ state = reducer ( state , undo ( ) ) ;
375+ expect ( state . G ) . toEqual ( { A : true } ) ;
376+ expect ( state . ctx . phase ) . toEqual ( 'phase1' ) ;
377+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
378+
379+ state = reducer ( state , redo ( ) ) ;
380+ expect ( state . G ) . toEqual ( { A : true } ) ;
381+ expect ( state . ctx . phase ) . toEqual ( 'phase2' ) ;
382+ expect ( state . ctx ) . toEqual ( state . _undo [ state . _undo . length - 1 ] . ctx ) ;
383+
384+ state = reducer ( state , undo ( ) ) ;
339385 state = reducer ( state , gameEvent ( 'endTurn' ) ) ;
340386 state = reducer ( state , undo ( ) ) ;
341387 expect ( state . G ) . toEqual ( { A : true } ) ;
0 commit comments