@@ -395,7 +395,7 @@ test('4.1 DELETE item by clicking <button class="destroy">', function (t) {
395
395
} ) ;
396
396
397
397
398
- test ( '5. Editing: > Render an item in "editing mode"' , function ( t ) {
398
+ test ( '5.1 Editing: > Render an item in "editing mode"' , function ( t ) {
399
399
elmish . empty ( document . getElementById ( id ) ) ;
400
400
localStorage . removeItem ( 'todos-elmish_' + id ) ;
401
401
const model = {
@@ -474,28 +474,27 @@ test('5.2.2 Slow clicks do not count as double-click > no edit!', function (t) {
474
474
} ) ;
475
475
476
476
477
- test . skip ( '5.1 Double-click an item <label> to edit it ' , function ( t ) {
477
+ test . only ( '5.3 [ENTER] Key in edit mode triggers SAVE action ' , function ( t ) {
478
478
elmish . empty ( document . getElementById ( id ) ) ;
479
479
localStorage . removeItem ( 'todos-elmish_' + id ) ;
480
480
const model = {
481
481
todos : [
482
- { id : 0 , title : "Make something people want." , done : false }
482
+ { id : 0 , title : "Make something people want." , done : false } ,
483
+ { id : 1 , title : "Let's solve our own problem" , done : false }
483
484
] ,
484
- hash : '#/' // the "route" to display
485
+ hash : '#/' , // the "route" to display
486
+ editing : 1 // edit the 3rd todo list item (which has id == 2)
485
487
} ;
486
488
// render the view and append it to the DOM inside the `test-app` node:
487
489
elmish . mount ( model , app . update , app . view , id , app . subscriptions ) ;
488
- // const todo_count = ;
489
- t . equal ( document . querySelectorAll ( '.destroy' ) . length , 1 , "one destroy button" )
490
-
491
- const item = document . getElementById ( '0' )
492
- t . equal ( item . textContent , model . todos [ 0 ] . title , 'Item contained in DOM.' ) ;
493
- // DELETE the item by clicking on the <button class="destroy">:
494
- const button = item . querySelectorAll ( 'button.destroy' ) [ 0 ] ;
495
- button . click ( )
496
- // confirm that there is no loger a <button class="destroy">
497
- t . equal ( document . querySelectorAll ( 'button.destroy' ) . length , 0 ,
498
- 'there is no loger a <button class="destroy"> as the only item was DELETEd' )
499
- t . equal ( document . getElementById ( '0' ) , null , 'todo item successfully DELETEd' ) ;
490
+ // change the
491
+ const updated_title = "Do things that don\'t scale!"
492
+ // apply the updated_title to the <input class="edit">:
493
+ document . querySelectorAll ( '.edit' ) [ 0 ] . value = updated_title ;
494
+ // trigger the [Enter] keyboard key to ADD the new todo:
495
+ document . dispatchEvent ( new KeyboardEvent ( 'keyup' , { 'keyCode' : 13 } ) ) ;
496
+ // confirm that the todo item title was updated to the updated_title:
497
+ const label = document . querySelectorAll ( '.view > label' ) [ 1 ] . textContent ;
498
+ t . equal ( label , updated_title , "item title updated to:" + updated_title )
500
499
t . end ( ) ;
501
500
} ) ;
0 commit comments