Skip to content

Commit 4fdb098

Browse files
committed
add test for [esc] CANCEL ediing for #64
1 parent 0887ba8 commit 4fdb098

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

+25
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,28 @@ test('5.4 SAVE should remove the item if an empty text string was entered',
523523
t.equal(document.querySelectorAll('.view').length, 1, 'todo count: 1');
524524
t.end();
525525
});
526+
527+
test.only('5.5 CANCEL should cancel edits on escape', function (t) {
528+
elmish.empty(document.getElementById(id));
529+
localStorage.removeItem('todos-elmish_' + id);
530+
const model = {
531+
todos: [
532+
{ id: 0, title: "Make something people want.", done: false },
533+
{ id: 1, title: "Let's solve our own problem", done: false }
534+
],
535+
hash: '#/', // the "route" to display
536+
editing: 1 // edit the 3rd todo list item (which has id == 2)
537+
};
538+
// render the view and append it to the DOM inside the `test-app` node:
539+
elmish.mount(model, app.update, app.view, id, app.subscriptions);
540+
t.equal(document.querySelectorAll('.view > label')[1].textContent,
541+
model.todos[1].title, 'todo id 1 has title: ' + model.todos[1].title);
542+
// apply empty string to the <input class="edit">:
543+
document.querySelectorAll('.edit')[0].value = 'Hello World';
544+
// trigger the [esc] keyboard key to CANCEL editing
545+
document.dispatchEvent(new KeyboardEvent('keyup', {'keyCode': 27}));
546+
// confirm the item.title is still the original title:
547+
t.equal(document.querySelectorAll('.view > label')[1].textContent,
548+
model.todos[1].title, 'todo id 1 has title: ' + model.todos[1].title);
549+
t.end();
550+
});

0 commit comments

Comments
 (0)