@@ -547,6 +547,90 @@ test('5.5 CANCEL should cancel edits on escape', function (t) {
547547 t . end ( ) ;
548548} ) ;
549549
550+ test ( '5.6 ESCAPE in new-todo with content should clear input and keep focus' , function ( t ) {
551+ elmish . empty ( document . getElementById ( id ) ) ;
552+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
553+ const model = {
554+ todos : [
555+ { id : 0 , title : "Make something people want." , done : false } ,
556+ { id : 1 , title : "Let's solve our own problem" , done : false }
557+ ] ,
558+ hash : '#/'
559+ } ;
560+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
561+
562+ const new_todo = document . getElementById ( 'new-todo' ) ;
563+ new_todo . value = 'This is a test todo' ;
564+ t . equal ( new_todo . value , 'This is a test todo' , 'new-todo has content before ESC' ) ;
565+
566+ document . dispatchEvent ( new KeyboardEvent ( 'keyup' , { 'keyCode' : 27 } ) ) ;
567+
568+ t . equal ( new_todo . value , '' , 'new-todo should be cleared after ESC' ) ;
569+ t . equal ( document . activeElement , new_todo , 'new-todo should keep focus after ESC' ) ;
570+ t . equal ( document . querySelectorAll ( '.editing' ) . length , 0 , 'not in editing mode' ) ;
571+ t . equal ( document . querySelectorAll ( '.view' ) . length , 2 , 'todos remain unchanged' ) ;
572+
573+ elmish . empty ( document . getElementById ( id ) ) ;
574+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
575+ t . end ( ) ;
576+ } ) ;
577+
578+ test ( '5.7 ESCAPE in new-todo with empty content should do nothing' , function ( t ) {
579+ elmish . empty ( document . getElementById ( id ) ) ;
580+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
581+ const model = {
582+ todos : [
583+ { id : 0 , title : "Make something people want." , done : false } ,
584+ { id : 1 , title : "Let's solve our own problem" , done : false }
585+ ] ,
586+ hash : '#/'
587+ } ;
588+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
589+
590+ const new_todo = document . getElementById ( 'new-todo' ) ;
591+ t . equal ( new_todo . value , '' , 'new-todo is empty before ESC' ) ;
592+
593+ document . dispatchEvent ( new KeyboardEvent ( 'keyup' , { 'keyCode' : 27 } ) ) ;
594+
595+ t . equal ( new_todo . value , '' , 'new-todo remains empty after ESC' ) ;
596+ t . equal ( document . querySelectorAll ( '.view' ) . length , 2 , 'todos remain unchanged' ) ;
597+
598+ elmish . empty ( document . getElementById ( id ) ) ;
599+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
600+ t . end ( ) ;
601+ } ) ;
602+
603+ test ( '5.8 ESCAPE in editing mode should cancel edit and not affect new-todo' , function ( t ) {
604+ elmish . empty ( document . getElementById ( id ) ) ;
605+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
606+ const model = {
607+ todos : [
608+ { id : 0 , title : "Make something people want." , done : false } ,
609+ { id : 1 , title : "Let's solve our own problem" , done : false }
610+ ] ,
611+ hash : '#/' ,
612+ editing : 1
613+ } ;
614+ elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
615+
616+ const new_todo = document . getElementById ( 'new-todo' ) ;
617+ new_todo . value = 'New todo content' ;
618+
619+ t . equal ( document . querySelectorAll ( '.editing' ) . length , 1 , 'in editing mode' ) ;
620+ t . equal ( new_todo . value , 'New todo content' , 'new-todo has content' ) ;
621+
622+ document . dispatchEvent ( new KeyboardEvent ( 'keyup' , { 'keyCode' : 27 } ) ) ;
623+
624+ t . equal ( document . querySelectorAll ( '.editing' ) . length , 0 , 'editing mode canceled' ) ;
625+ t . equal ( document . querySelectorAll ( '.view > label' ) [ 1 ] . textContent ,
626+ model . todos [ 1 ] . title , 'todo item title unchanged' ) ;
627+ t . equal ( new_todo . value , 'New todo content' , 'new-todo content preserved' ) ;
628+
629+ elmish . empty ( document . getElementById ( id ) ) ;
630+ localStorage . removeItem ( 'todos-elmish_' + id ) ;
631+ t . end ( ) ;
632+ } ) ;
633+
550634test ( '6. Counter > should display the current number of todo items' ,
551635 function ( t ) {
552636 elmish . empty ( document . getElementById ( id ) ) ;
0 commit comments