@@ -314,10 +314,10 @@ test('undo / redo', () => {
314314
315315 let state = InitializeGame ( { game } ) ;
316316
317- state = reducer ( state , makeMove ( 'move' , 'A' ) ) ;
317+ state = reducer ( state , makeMove ( 'move' , 'A' , '0' ) ) ;
318318 expect ( state . G ) . toMatchObject ( { A : true } ) ;
319319
320- state = reducer ( state , makeMove ( 'move' , 'B' ) ) ;
320+ state = reducer ( state , makeMove ( 'move' , 'B' , '0' ) ) ;
321321 expect ( state . G ) . toMatchObject ( { A : true , B : true } ) ;
322322 expect ( state . _undo [ 1 ] . ctx . events ) . toBeUndefined ( ) ;
323323 expect ( state . _undo [ 1 ] . ctx . random ) . toBeUndefined ( ) ;
@@ -340,7 +340,7 @@ test('undo / redo', () => {
340340 expect ( state . G ) . toEqual ( { } ) ;
341341
342342 state = reducer ( state , redo ( ) ) ;
343- state = reducer ( state , makeMove ( 'move' , 'C' ) ) ;
343+ state = reducer ( state , makeMove ( 'move' , 'C' , '0' ) ) ;
344344 expect ( state . G ) . toMatchObject ( { A : true , C : true } ) ;
345345
346346 state = reducer ( state , undo ( ) ) ;
@@ -351,7 +351,7 @@ test('undo / redo', () => {
351351
352352 state = reducer ( state , undo ( ) ) ;
353353 state = reducer ( state , undo ( ) ) ;
354- state = reducer ( state , makeMove ( 'roll' ) ) ;
354+ state = reducer ( state , makeMove ( 'roll' , null , '0' ) ) ;
355355 expect ( state . G ) . toMatchObject ( { roll : 4 } ) ;
356356
357357 state = reducer ( state , undo ( ) ) ;
@@ -377,12 +377,12 @@ test('disable undo / redo', () => {
377377
378378 let state = InitializeGame ( { game } ) ;
379379
380- state = reducer ( state , makeMove ( 'move' , 'A' ) ) ;
380+ state = reducer ( state , makeMove ( 'move' , 'A' , '0' ) ) ;
381381 expect ( state . G ) . toMatchObject ( { A : true } ) ;
382382 expect ( state . _undo ) . toEqual ( [ ] ) ;
383383 expect ( state . _redo ) . toEqual ( [ ] ) ;
384384
385- state = reducer ( state , makeMove ( 'move' , 'B' ) ) ;
385+ state = reducer ( state , makeMove ( 'move' , 'B' , '0' ) ) ;
386386 expect ( state . G ) . toMatchObject ( { A : true , B : true } ) ;
387387 expect ( state . _undo ) . toEqual ( [ ] ) ;
388388 expect ( state . _redo ) . toEqual ( [ ] ) ;
@@ -419,33 +419,49 @@ describe('undo stack', () => {
419419 test ( 'contains initial state at start of game' , ( ) => {
420420 expect ( state . _undo ) . toHaveLength ( 1 ) ;
421421 expect ( state . _undo [ 0 ] . ctx ) . toEqual ( state . ctx ) ;
422+ expect ( state . _undo [ 0 ] . plugins ) . toEqual ( state . plugins ) ;
422423 } ) ;
423424
424425 test ( 'grows when a move is made' , ( ) => {
425- state = reducer ( state , makeMove ( 'basic' ) ) ;
426+ state = reducer ( state , makeMove ( 'basic' , null , '0' ) ) ;
426427 expect ( state . _undo ) . toHaveLength ( 2 ) ;
427428 expect ( state . _undo [ 1 ] . moveType ) . toBe ( 'basic' ) ;
428429 expect ( state . _undo [ 1 ] . ctx ) . toEqual ( state . ctx ) ;
430+ expect ( state . _undo [ 1 ] . plugins ) . toEqual ( state . plugins ) ;
429431 } ) ;
430432
431433 test ( 'shrinks when a move is undone' , ( ) => {
432434 state = reducer ( state , undo ( ) ) ;
433435 expect ( state . _undo ) . toHaveLength ( 1 ) ;
434436 expect ( state . _undo [ 0 ] . ctx ) . toEqual ( state . ctx ) ;
437+ expect ( state . _undo [ 0 ] . plugins ) . toEqual ( state . plugins ) ;
435438 } ) ;
436439
437440 test ( 'grows when a move is redone' , ( ) => {
438441 state = reducer ( state , redo ( ) ) ;
439442 expect ( state . _undo ) . toHaveLength ( 2 ) ;
440443 expect ( state . _undo [ 1 ] . moveType ) . toBe ( 'basic' ) ;
441444 expect ( state . _undo [ 1 ] . ctx ) . toEqual ( state . ctx ) ;
445+ expect ( state . _undo [ 1 ] . plugins ) . toEqual ( state . plugins ) ;
442446 } ) ;
443447
444448 test ( 'is reset when a turn ends' , ( ) => {
445449 state = reducer ( state , makeMove ( 'endTurn' ) ) ;
446450 expect ( state . _undo ) . toHaveLength ( 1 ) ;
447451 expect ( state . _undo [ 0 ] . ctx ) . toEqual ( state . ctx ) ;
448- expect ( state . _undo [ 0 ] . moveType ) . toBeUndefined ( ) ;
452+ expect ( state . _undo [ 0 ] . plugins ) . toEqual ( state . plugins ) ;
453+ expect ( state . _undo [ 0 ] . moveType ) . toBe ( 'endTurn' ) ;
454+ } ) ;
455+
456+ test ( 'can’t undo at the start of a turn' , ( ) => {
457+ const newState = reducer ( state , undo ( ) ) ;
458+ expect ( state ) . toEqual ( newState ) ;
459+ } ) ;
460+
461+ test ( 'can’t undo another player’s move' , ( ) => {
462+ state = reducer ( state , makeMove ( 'basic' , null , '1' ) ) ;
463+ const newState = reducer ( state , undo ( '0' ) ) ;
464+ expect ( state ) . toEqual ( newState ) ;
449465 } ) ;
450466} ) ;
451467
@@ -467,7 +483,7 @@ describe('redo stack', () => {
467483 } ) ;
468484
469485 test ( 'grows when a move is undone' , ( ) => {
470- state = reducer ( state , makeMove ( 'basic' ) ) ;
486+ state = reducer ( state , makeMove ( 'basic' , null , '0' ) ) ;
471487 state = reducer ( state , undo ( ) ) ;
472488 expect ( state . _redo ) . toHaveLength ( 1 ) ;
473489 expect ( state . _redo [ 0 ] . moveType ) . toBe ( 'basic' ) ;
@@ -479,21 +495,30 @@ describe('redo stack', () => {
479495 } ) ;
480496
481497 test ( 'is reset when a move is made' , ( ) => {
482- state = reducer ( state , makeMove ( 'basic' ) ) ;
498+ state = reducer ( state , makeMove ( 'basic' , null , '0' ) ) ;
483499 state = reducer ( state , undo ( ) ) ;
484500 state = reducer ( state , undo ( ) ) ;
485501 expect ( state . _redo ) . toHaveLength ( 2 ) ;
486- state = reducer ( state , makeMove ( 'basic' ) ) ;
502+ state = reducer ( state , makeMove ( 'basic' , null , '0' ) ) ;
487503 expect ( state . _redo ) . toHaveLength ( 0 ) ;
488504 } ) ;
489505
490506 test ( 'is reset when a turn ends' , ( ) => {
491- state = reducer ( state , makeMove ( 'basic' ) ) ;
507+ state = reducer ( state , makeMove ( 'basic' , null , '0' ) ) ;
492508 state = reducer ( state , undo ( ) ) ;
493509 expect ( state . _redo ) . toHaveLength ( 1 ) ;
494510 state = reducer ( state , makeMove ( 'endTurn' ) ) ;
495511 expect ( state . _redo ) . toHaveLength ( 0 ) ;
496512 } ) ;
513+
514+ test ( 'can’t redo another player’s undo' , ( ) => {
515+ state = reducer ( state , makeMove ( 'basic' , null , '1' ) ) ;
516+ state = reducer ( state , undo ( '1' ) ) ;
517+ expect ( state . _redo ) . toHaveLength ( 1 ) ;
518+ const newState = reducer ( state , redo ( '0' ) ) ;
519+ expect ( state . _redo ) . toHaveLength ( 1 ) ;
520+ expect ( newState ) . toEqual ( state ) ;
521+ } ) ;
497522} ) ;
498523
499524describe ( 'undo / redo with stages' , ( ) => {
0 commit comments