@@ -624,11 +624,55 @@ test('8. Persistence > should persist its data', function (t) {
624
624
// render the view and append it to the DOM inside the `test-app` node:
625
625
elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
626
626
// confirm that the model is saved to localStorage
627
- console . log ( 'localStorage' , localStorage . getItem ( 'todos-elmish_' + id ) ) ;
627
+ // console.log('localStorage', localStorage.getItem('todos-elmish_' + id));
628
628
t . equal ( localStorage . getItem ( 'todos-elmish_' + id ) ,
629
629
JSON . stringify ( model ) , "data is persisted to localStorage" ) ;
630
630
631
631
elmish . empty ( document . getElementById ( id ) ) ; // clear DOM ready for next test
632
632
localStorage . removeItem ( 'todos-elmish_' + id ) ;
633
633
t . end ( ) ;
634
634
} ) ;
635
+
636
+ test . only ( '9. Routing > should allow me to display active/completed/all items' ,
637
+ function ( t ) {
638
+ elmish . empty ( document . getElementById ( id ) ) ;
639
+ const model = {
640
+ todos : [
641
+ { id : 0 , title : "Make something people want." , done : false } ,
642
+ { id : 1 , title : "Bootstrap for as long as you can" , done : true } ,
643
+ { id : 2 , title : "Let's solve our own problem" , done : true }
644
+ ] ,
645
+ hash : '#/active' // ONLY ACTIVE items
646
+ } ;
647
+ // render the view and append it to the DOM inside the `test-app` node:
648
+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
649
+ t . equal ( document . querySelectorAll ( '.view' ) . length , 1 , "one active item" ) ;
650
+ let selected = document . querySelectorAll ( '.selected' ) [ 0 ]
651
+ t . equal ( selected . id , 'active' , "active footer filter is selected" ) ;
652
+
653
+ // empty:
654
+ elmish . empty ( document . getElementById ( id ) ) ;
655
+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
656
+ // show COMPLTED items:
657
+ model . hash = '#/completed' ;
658
+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
659
+ t . equal ( document . querySelectorAll ( '.view' ) . length , 2 ,
660
+ "two completed items" ) ;
661
+ selected = document . querySelectorAll ( '.selected' ) [ 0 ]
662
+ t . equal ( selected . id , 'completed' , "completed footer filter is selected" ) ;
663
+
664
+ // empty:
665
+ elmish . empty ( document . getElementById ( id ) ) ;
666
+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
667
+ // show ALL items:
668
+ model . hash = '#/' ;
669
+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
670
+ t . equal ( document . querySelectorAll ( '.view' ) . length , 3 ,
671
+ "three items total" ) ;
672
+ selected = document . querySelectorAll ( '.selected' ) [ 0 ]
673
+ t . equal ( selected . id , 'all' , "all footer filter is selected" ) ;
674
+
675
+ elmish . empty ( document . getElementById ( id ) ) ; // clear DOM ready for next test
676
+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
677
+ t . end ( ) ;
678
+ } ) ;
0 commit comments