generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodoList.test.js
87 lines (73 loc) · 2.26 KB
/
todoList.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import TodoList from './src/modules/todoList.js';
import * as gin from './src/modules/utils.js';
class LocalStorageMock {
constructor() {
this.store = {};
}
clear() {
this.store = {};
}
getItem(key) {
return this.store[key] || null;
}
setItem(key, value) {
this.store[key] = String(value);
}
removeItem(key) {
delete this.store[key];
}
}
global.localStorage = new LocalStorageMock();
document.body.innerHTML = `<div> +
<div id="dynamic-list"></div>
</div>`;
const todoList = new TodoList();
describe('Add task', () => {
test('Add one task expect tasks length to be 1', () => {
todoList.addTodo('go shopping');
todoList.addTodo('watch a movie');
expect(todoList.todos.length).toBe(2);
});
});
describe('Add the added todo to the DOM', () => {
test('One task has been added expect one task element in DOM', () => {
gin.allTasks(todoList);
const tasksList = document.getElementById('dynamic-list');
expect(tasksList.childNodes.length).toBe(2);
});
});
describe('Remove first todo from todoList', () => {
test('One task has been remove expect zero', () => {
const { id } = todoList.todos[0];
const taskCard = document.getElementById(id);
taskCard.parentNode.removeChild(taskCard);
expect(todoList.delete(id)).toBe(id);
});
});
describe('Check if task card had been removed from DOM', () => {
test('One card removed expect node children to be 1', () => {
const tasksList = document.getElementById('dynamic-list');
expect(tasksList.childNodes.length).toBe(1);
});
});
describe('edit todos', () => {
test('Edited description should be equal to new value', () => {
todoList.addTodo('watch a movie');
const todo = todoList.todos[0];
todo.description = 'finish the week';
expect(todoList.edit(todo).description).toBe(todo.description);
});
});
describe('update completed to true', () => {
test('Todo marked as completed , should be truthy', () => {
const todo = todoList.todos[0];
todo.completed = true;
expect(todoList.edit(todo).completed).toBeTruthy();
});
});
describe('clear all completed', () => {
test('One task marked as completed and cleared, todos should be 0', () => {
todoList.clearComplete();
expect(todoList.todos.length).toBe(0);
});
});