@@ -438,6 +438,125 @@ describe('Store Devtools', () => {
438
438
} ) ;
439
439
} ) ;
440
440
441
+ describe ( 'Filtered actions' , ( ) => {
442
+ it ( 'should respect the predicate option' , ( ) => {
443
+ const fixture = createStore ( counter , {
444
+ predicate : ( s , a ) => a . type !== 'INCREMENT' ,
445
+ } ) ;
446
+
447
+ expect ( fixture . getState ( ) ) . toBe ( 0 ) ;
448
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
449
+ fixture . store . dispatch ( { type : 'DECREMENT' } ) ;
450
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
451
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
452
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
453
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
454
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
455
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
456
+ fixture . store . dispatch ( { type : 'DECREMENT' } ) ;
457
+ expect ( fixture . getState ( ) ) . toBe ( 5 ) ;
458
+
459
+ // init, decrement, decrement
460
+ const {
461
+ stagedActionIds,
462
+ actionsById,
463
+ computedStates,
464
+ currentStateIndex,
465
+ } = fixture . getLiftedState ( ) ;
466
+ expect ( stagedActionIds . length ) . toBe ( 3 ) ;
467
+ expect ( Object . keys ( actionsById ) . length ) . toBe ( 3 ) ;
468
+ expect ( computedStates . length ) . toBe ( 3 ) ;
469
+ expect ( currentStateIndex ) . toBe ( 2 ) ;
470
+
471
+ fixture . devtools . jumpToAction ( 0 ) ;
472
+ expect ( fixture . getState ( ) ) . toBe ( 1 ) ;
473
+
474
+ fixture . devtools . jumpToAction ( 1 ) ;
475
+ expect ( fixture . getState ( ) ) . toBe ( 6 ) ;
476
+
477
+ fixture . devtools . jumpToAction ( 2 ) ;
478
+ expect ( fixture . getState ( ) ) . toBe ( 5 ) ;
479
+ } ) ;
480
+
481
+ it ( 'should respect the blacklist option' , ( ) => {
482
+ const fixture = createStore ( counter , {
483
+ actionsBlacklist : [ 'INCREMENT' ] ,
484
+ } ) ;
485
+
486
+ expect ( fixture . getState ( ) ) . toBe ( 0 ) ;
487
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
488
+ fixture . store . dispatch ( { type : 'DECREMENT' } ) ;
489
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
490
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
491
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
492
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
493
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
494
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
495
+ fixture . store . dispatch ( { type : 'DECREMENT' } ) ;
496
+ expect ( fixture . getState ( ) ) . toBe ( 5 ) ;
497
+
498
+ // init, decrement, decrement
499
+ const {
500
+ stagedActionIds,
501
+ actionsById,
502
+ computedStates,
503
+ currentStateIndex,
504
+ } = fixture . getLiftedState ( ) ;
505
+ expect ( stagedActionIds . length ) . toBe ( 3 ) ;
506
+ expect ( Object . keys ( actionsById ) . length ) . toBe ( 3 ) ;
507
+ expect ( computedStates . length ) . toBe ( 3 ) ;
508
+ expect ( currentStateIndex ) . toBe ( 2 ) ;
509
+
510
+ fixture . devtools . jumpToAction ( 0 ) ;
511
+ expect ( fixture . getState ( ) ) . toBe ( 1 ) ;
512
+
513
+ fixture . devtools . jumpToAction ( 1 ) ;
514
+ expect ( fixture . getState ( ) ) . toBe ( 6 ) ;
515
+
516
+ fixture . devtools . jumpToAction ( 2 ) ;
517
+ expect ( fixture . getState ( ) ) . toBe ( 5 ) ;
518
+ } ) ;
519
+
520
+ it ( 'should respect the whitelist option' , ( ) => {
521
+ const fixture = createStore ( counter , {
522
+ actionsWhitelist : [ 'DECREMENT' ] ,
523
+ } ) ;
524
+
525
+ expect ( fixture . getState ( ) ) . toBe ( 0 ) ;
526
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
527
+ fixture . store . dispatch ( { type : 'DECREMENT' } ) ;
528
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
529
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
530
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
531
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
532
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
533
+ fixture . store . dispatch ( { type : 'INCREMENT' } ) ;
534
+ fixture . store . dispatch ( { type : 'DECREMENT' } ) ;
535
+ expect ( fixture . getState ( ) ) . toBe ( 5 ) ;
536
+
537
+ // init, decrement, decrement
538
+ const {
539
+ stagedActionIds,
540
+ actionsById,
541
+ computedStates,
542
+ currentStateIndex,
543
+ } = fixture . getLiftedState ( ) ;
544
+ expect ( stagedActionIds . length ) . toBe ( 3 ) ;
545
+ expect ( Object . keys ( actionsById ) . length ) . toBe ( 3 ) ;
546
+ expect ( computedStates . length ) . toBe ( 3 ) ;
547
+ expect ( currentStateIndex ) . toBe ( 2 ) ;
548
+
549
+ fixture . devtools . jumpToAction ( 0 ) ;
550
+ expect ( fixture . getState ( ) ) . toBe ( 1 ) ;
551
+
552
+ fixture . devtools . jumpToAction ( 1 ) ;
553
+ expect ( fixture . getState ( ) ) . toBe ( 6 ) ;
554
+
555
+ fixture . devtools . jumpToAction ( 2 ) ;
556
+ expect ( fixture . getState ( ) ) . toBe ( 5 ) ;
557
+ } ) ;
558
+ } ) ;
559
+
441
560
describe ( 'maxAge option' , ( ) => {
442
561
it ( 'should auto-commit earliest non-@@INIT action when maxAge is reached' , ( ) => {
443
562
const fixture = createStore ( counter , { maxAge : 3 } ) ;
0 commit comments