Skip to content

Commit eec3642

Browse files
committed
add test for SAVE *blank* todo title > should delete item for #60
1 parent c8098e9 commit eec3642

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: test/todo-app.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,27 @@ test('5.3 [ENTER] Key in edit mode triggers SAVE action', function (t) {
499499
"item title updated to:" + updated_title + ' (trimmed)');
500500
t.end();
501501
});
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

Comments
 (0)