@@ -1338,38 +1338,38 @@ https://github.com/tastejs/todomvc/tree/master/tests#example-output
1338
1338
1339
1339
```
1340
1340
TodoMVC
1341
- No Todos
1341
+ 1. No Todos
1342
1342
✓ should hide #main and #footer (201ms)
1343
- New Todo
1343
+ 2. New Todo
1344
1344
✓ should allow me to add todo items (548ms)
1345
1345
✓ should clear text input field when an item is added (306ms)
1346
1346
✓ should trim text input (569ms)
1347
1347
✓ should show #main and #footer when items added (405ms)
1348
- Mark all as completed
1348
+ 3. Mark all as completed
1349
1349
✓ should allow me to mark all items as completed (1040ms)
1350
1350
✓ should allow me to clear the completion state of all items (1014ms)
1351
1351
✓ complete all checkbox should update state when items are completed (1413ms)
1352
- Item
1352
+ 4. Item
1353
1353
✓ should allow me to mark items as complete (843ms)
1354
1354
✓ should allow me to un-mark items as complete (978ms)
1355
1355
✓ should allow me to edit an item (1155ms)
1356
1356
✓ should show the remove button on hover
1357
- Editing
1357
+ 5. Editing
1358
1358
✓ should hide other controls when editing (718ms)
1359
1359
✓ should save edits on enter (1093ms)
1360
1360
✓ should save edits on blur (1256ms)
1361
1361
✓ should trim entered text (1163ms)
1362
1362
✓ should remove the item if an empty text string was entered (1033ms)
1363
1363
✓ should cancel edits on escape (1115ms)
1364
- Counter
1364
+ 6. Counter
1365
1365
✓ should display the current number of todo items (462ms)
1366
- Clear completed button
1366
+ 7. Clear completed button
1367
1367
✓ should display the number of completed items (873ms)
1368
1368
✓ should remove completed items when clicked (898ms)
1369
1369
✓ should be hidden when there are no items that are completed (893ms)
1370
- Persistence
1370
+ 8. Persistence
1371
1371
✓ should persist its data (3832ms)
1372
- Routing
1372
+ 9. Routing
1373
1373
✓ should allow me to display active items (871ms)
1374
1374
✓ should allow me to display completed items (960ms)
1375
1375
✓ should allow me to display all items (1192ms)
@@ -1384,7 +1384,7 @@ We are going to write each one of these tests and then
1384
1384
1385
1385
Add the following test to your ` test/todo-app.test.js ` file:
1386
1386
``` js
1387
- test .only (' No Todos, should hide #footer and #main' , function (t ) {
1387
+ test .only (' 1. No Todos, should hide #footer and #main' , function (t ) {
1388
1388
// render the view and append it to the DOM inside the `test-app` node:
1389
1389
document .getElementById (id).appendChild (app .view ({todos: []})); // No Todos
1390
1390
@@ -1406,7 +1406,6 @@ node test/todo-app.js
1406
1406
You should see the following output:
1407
1407
![ image] ( https://user-images.githubusercontent.com/194400/43868621-59e1aba0-9b66-11e8-95c1-0034892128cd.png )
1408
1408
1409
-
1410
1409
##### Make it Pass!
1411
1410
1412
1411
Simply replace the instances of ` "style=display: block;" ` in the view code
@@ -1421,12 +1420,72 @@ var display = "style=display:"
1421
1420
You should see:
1422
1421
![ no-todos-test-passing] ( https://user-images.githubusercontent.com/194400/43868724-e3e2249c-9b66-11e8-8228-a5c1528c17b0.png )
1423
1422
1423
+ Testing it in your web browser you should see the desired result:
1424
1424
1425
+ ![ no-todos-hide-main-and-footer] ( https://user-images.githubusercontent.com/194400/43869170-1982648e-9b69-11e8-8f7a-4730edbc07ca.png )
1425
1426
1427
+ > If you get stuck trying to make the test pass, see:
1428
+ [ todo-app.js] ( https://github.com/dwyl/learn-elm-architecture-in-javascript/pull/45/commits/d1bd85e4d75afdc69fcf38b9d58947cdce18a9cf#diff-6be3e16fe7cfb4c00788d4d587374afdR85 )
1426
1429
1427
- Recommended reading:
1430
+ Recommended reading on CSS ` visibility:hidden ` vs. ` display:none ` :
1428
1431
https://stackoverflow.com/questions/133051/what-is-the-difference-between-visibilityhidden-and-displaynone
1429
1432
1433
+ <br />
1434
+
1435
+ #### 2. New Todo, should allow me to add todo items
1436
+
1437
+ The second batch of tests involves adding a new todo item to the list:
1438
+
1439
+ ```
1440
+ 2. New Todo
1441
+ ✓ should allow me to add todo items (548ms)
1442
+ ✓ should clear text input field when an item is added (306ms)
1443
+ ✓ should trim text input (569ms)
1444
+ ✓ should show #main and #footer when items added (405ms)
1445
+ ```
1446
+ Let's create a test with these 4 assertions.
1447
+
1448
+ Add the following code/test to your ` test/todo-app.test.js ` file:
1449
+ ``` js
1450
+ test .only (' 2. New Todo, should allow me to add todo items' , function (t ) {
1451
+ // render the view and append it to the DOM inside the `test-app` node:
1452
+ elmish .mount ({todos: []}, app .update , app .view , id, app .subscriptions );
1453
+ const new_todo = document .getElementById (' new-todo' );
1454
+ // "type" content in the <input id="new-todo">:
1455
+ const todo_text = ' Make Everything Awesome! ' ; // deliberate whitespace!
1456
+ new_todo .value = todo_text;
1457
+ // trigger the [Enter] keyboard key to ADD the new todo:
1458
+ new_todo .dispatchEvent (new KeyboardEvent (' keypress' , {' keyCode' : 13 }));
1459
+ const items = document .querySelectorAll (' .view' )
1460
+ t .equal (items .length , 1 , " ✓ should allow me to add todo items" );
1461
+ // check if the new todo was added to the DOM:
1462
+ const actual = document .getElementById (' 1' ).textContent ;
1463
+ t .equal (todo_text .trim (), actual, " ✓ should trim text input" )
1464
+
1465
+ // check that the <input id="new-todo"> was reset after the new item was added
1466
+ t .equal (new_todo .value , ' ' ,
1467
+ " ✓ should clear text input field when an item is added" )
1468
+
1469
+ const main_display = window .getComputedStyle (document .getElementById (' main' ));
1470
+ t .equal (' block' , main_display ._values .display ,
1471
+ " ✓ should show #main and #footer when items added" );
1472
+ const main_footer = window .getComputedStyle (document .getElementById (' footer' ));
1473
+ t .equal (' block' , main_footer ._values .display , " show #footer" );
1474
+
1475
+ elmish .empty (document .getElementById (id)); // clear DOM ready for next test
1476
+ t .end ();
1477
+ });
1478
+ ```
1479
+
1480
+ Run the test with:
1481
+ ``` sh
1482
+ node test/todo-app.js
1483
+ ```
1484
+ You should see the following output:
1485
+
1486
+ ![ test-failing] ( https://user-images.githubusercontent.com/194400/43929259-1880b41e-9c2c-11e8-9615-1372928c905d.png )
1487
+
1488
+
1430
1489
1431
1490
1432
1491
<!--
0 commit comments