-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
108 lines (90 loc) · 2.51 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const Task = require('./modules/Task.js');
const { saveToLocalStorage, getFromLocalStorage } = require('./modules/Storage.js');
const task = new Task();
const array = [
{
description: 'Go to work',
index: 1,
completed: false,
},
{
description: 'Go to School',
index: 2,
completed: true,
},
{
description: 'Go to home',
index: 3,
completed: false,
},
];
beforeEach(() => {
saveToLocalStorage('tasks', array);
});
describe('updateIndex', () => {
test('Test updateIndex', () => {
const result1 = {
description: 'Go to home',
index: 2,
completed: false,
};
const result2 = {
description: 'Go to home',
index: 1,
completed: false,
};
expect(task.updateIndex(0, array)).toContainEqual(result1);
expect(task.updateIndex(1, array)).toContainEqual(result2);
});
});
describe('add list to task in localStorage', () => {
test('save to localStorage', () => {
saveToLocalStorage('tasks', array);
expect(JSON.parse(window.localStorage.getItem('tasks'))).toEqual(array);
});
});
describe('delete task', () => {
const ul = document.createElement('ul');
ul.className = 'list-container';
ul.innerHTML = `
<li> Go to work </li>
<li> Buy groceries </li>
`;
test('remove all task from list', () => {
document.body.appendChild(ul);
expect(task.removeChild()).toBe(undefined);
});
const result = {
description: 'Go to work',
index: 1,
completed: false,
};
test('remove completed task from list', () => {
const testTask = new Task();
expect(testTask.removeCompleted()).toContainEqual(result);
});
});
describe('update', () => {
test('update task description of second list', () => {
const updated = task.update('Take a break', 1);
const tasks = getFromLocalStorage('tasks');
expect(tasks[1]).toEqual(updated);
});
test('update task description of first list', () => {
const updated = task.update('Walk the dog', 0);
const tasks = getFromLocalStorage('tasks');
expect(tasks[0]).toEqual(updated);
});
});
describe('update completed status', () => {
test('check completed status of first list to true', () => {
const status = task.checked(true, 1);
const tasks = getFromLocalStorage('tasks');
expect(status).toEqual(tasks[1].completed);
});
test('check completed status of second list to false', () => {
const status = task.checked(false, 1);
const tasks = getFromLocalStorage('tasks');
expect(status).toEqual(tasks[1].completed);
});
});