Skip to content

Commit fc2ed3c

Browse files
committed
add test for routing based on clicking links in footer #48
1 parent b1f895b commit fc2ed3c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

test/todo-app.test.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,55 @@ test('8. Persistence > should persist its data', function (t) {
624624
// render the view and append it to the DOM inside the `test-app` node:
625625
elmish.mount(model, app.update, app.view, id, app.subscriptions);
626626
// confirm that the model is saved to localStorage
627-
console.log('localStorage', localStorage.getItem('todos-elmish_' + id));
627+
// console.log('localStorage', localStorage.getItem('todos-elmish_' + id));
628628
t.equal(localStorage.getItem('todos-elmish_' + id),
629629
JSON.stringify(model), "data is persisted to localStorage");
630630

631631
elmish.empty(document.getElementById(id)); // clear DOM ready for next test
632632
localStorage.removeItem('todos-elmish_' + id);
633633
t.end();
634634
});
635+
636+
test.only('9. Routing > should allow me to display active/completed/all items',
637+
function (t) {
638+
elmish.empty(document.getElementById(id));
639+
const model = {
640+
todos: [
641+
{ id: 0, title: "Make something people want.", done: false },
642+
{ id: 1, title: "Bootstrap for as long as you can", done: true },
643+
{ id: 2, title: "Let's solve our own problem", done: true }
644+
],
645+
hash: '#/active' // ONLY ACTIVE items
646+
};
647+
// render the view and append it to the DOM inside the `test-app` node:
648+
elmish.mount(model, app.update, app.view, id, app.subscriptions);
649+
t.equal(document.querySelectorAll('.view').length, 1, "one active item");
650+
let selected = document.querySelectorAll('.selected')[0]
651+
t.equal(selected.id, 'active', "active footer filter is selected");
652+
653+
// empty:
654+
elmish.empty(document.getElementById(id));
655+
localStorage.removeItem('todos-elmish_' + id);
656+
// show COMPLTED items:
657+
model.hash = '#/completed';
658+
elmish.mount(model, app.update, app.view, id, app.subscriptions);
659+
t.equal(document.querySelectorAll('.view').length, 2,
660+
"two completed items");
661+
selected = document.querySelectorAll('.selected')[0]
662+
t.equal(selected.id, 'completed', "completed footer filter is selected");
663+
664+
// empty:
665+
elmish.empty(document.getElementById(id));
666+
localStorage.removeItem('todos-elmish_' + id);
667+
// show ALL items:
668+
model.hash = '#/';
669+
elmish.mount(model, app.update, app.view, id, app.subscriptions);
670+
t.equal(document.querySelectorAll('.view').length, 3,
671+
"three items total");
672+
selected = document.querySelectorAll('.selected')[0]
673+
t.equal(selected.id, 'all', "all footer filter is selected");
674+
675+
elmish.empty(document.getElementById(id)); // clear DOM ready for next test
676+
localStorage.removeItem('todos-elmish_' + id);
677+
t.end();
678+
});

0 commit comments

Comments
 (0)