@@ -499,3 +499,27 @@ test('5.3 [ENTER] Key in edit mode triggers SAVE action', function (t) {
499
499
"item title updated to:" + updated_title + ' (trimmed)' ) ;
500
500
t . end ( ) ;
501
501
} ) ;
502
+
503
+ test ( '5.4 SAVE should remove the item if an empty text string was entered' ,
504
+ function ( t ) {
505
+ elmish . empty ( document . getElementById ( id ) ) ;
506
+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
507
+ const model = {
508
+ todos : [
509
+ { id : 0 , title : "Make something people want." , done : false } ,
510
+ { id : 1 , title : "Let's solve our own problem" , done : false }
511
+ ] ,
512
+ hash : '#/' , // the "route" to display
513
+ editing : 1 // edit the 3rd todo list item (which has id == 2)
514
+ } ;
515
+ // render the view and append it to the DOM inside the `test-app` node:
516
+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
517
+ t . equal ( document . querySelectorAll ( '.view' ) . length , 2 , 'todo count: 2' ) ;
518
+ // apply empty string to the <input class="edit">:
519
+ document . querySelectorAll ( '.edit' ) [ 0 ] . value = '' ;
520
+ // trigger the [Enter] keyboard key to ADD the new todo:
521
+ document . dispatchEvent ( new KeyboardEvent ( 'keyup' , { 'keyCode' : 13 } ) ) ;
522
+ // confirm that the todo item was removed!
523
+ t . equal ( document . querySelectorAll ( '.view' ) . length , 1 , 'todo count: 1' ) ;
524
+ t . end ( ) ;
525
+ } ) ;
0 commit comments