@@ -27,6 +27,33 @@ test('`ADD` a new todo item to model.todos Array via `update`', function (t) {
27
27
const updated_model = app . update ( 'ADD' , model , "Add Todo List Item" ) ;
28
28
const expected = { id : 1 , title : "Add Todo List Item" , done : false } ;
29
29
t . equal ( updated_model . todos . length , 1 , "updated_model.todos.length is 1" ) ;
30
- t . deepEqual ( expected , updated_model . todos [ 0 ] , "Todo list item added." ) ;
30
+ t . deepEqual ( updated_model . todos [ 0 ] , expected , "Todo list item added." ) ;
31
+ t . end ( ) ;
32
+ } ) ;
33
+
34
+ test ( '`TOGGLE` a todo item from done=false to done=true' , function ( t ) {
35
+ const model = JSON . parse ( JSON . stringify ( app . model ) ) ; // initial state
36
+ const model_with_todo = app . update ( 'ADD' , model , "Toggle a todo list item" ) ;
37
+ const item = model_with_todo . todos [ 0 ] ;
38
+ const model_todo_done = app . update ( 'TOGGLE' , model_with_todo , item . id ) ;
39
+ const expected = { id : 1 , title : "Toggle a todo list item" , done : true } ;
40
+ t . deepEqual ( model_todo_done . todos [ 0 ] , expected , "Todo list item Toggled." ) ;
41
+ t . end ( ) ;
42
+ } ) ;
43
+
44
+ test ( '`TOGGLE` (undo) a todo item from done=true to done=false' , function ( t ) {
45
+ const model = JSON . parse ( JSON . stringify ( app . model ) ) ; // initial state
46
+ const model_with_todo = app . update ( 'ADD' , model , "Toggle a todo list item" ) ;
47
+ const item = model_with_todo . todos [ 0 ] ;
48
+ const model_todo_done = app . update ( 'TOGGLE' , model_with_todo , item . id ) ;
49
+ const expected = { id : 1 , title : "Toggle a todo list item" , done : true } ;
50
+ t . deepEqual ( model_todo_done . todos [ 0 ] , expected , "Todo list item Toggled." ) ;
51
+ // add another item before "undoing" the original one:
52
+ const model_second_item = app . update ( 'ADD' , model_todo_done , "Another todo" ) ;
53
+ t . equal ( model_second_item . todos . length , 2 , "there are two todo items" ) ;
54
+ // Toggle the original item such that: done=true >> done=false
55
+ const model_todo_undone = app . update ( 'TOGGLE' , model_second_item , item . id ) ;
56
+ const undone = { id : 1 , title : "Toggle a todo list item" , done : false } ;
57
+ t . deepEqual ( model_todo_undone . todos [ 0 ] , undone , "Todo item Toggled > undone!" ) ;
31
58
t . end ( ) ;
32
59
} ) ;
0 commit comments