-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.test.js
99 lines (90 loc) · 2.48 KB
/
add.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
/* eslint-disable no-unused-vars */
import Display from './module/Display.js';
const LocalStorage = require('./module/LocalStorage.js');
/**
* @jest-environment jsdom
*/
document.body.innerHTML = `<main>
<h1>Today's To Do List</h1>
<form class="forms">
<input type="text" placeholder="Add to your list..." id="desc" required>
<button class="form-btn" type="submit">ENTER</button>
</form>
<div class="showList"></div>
<button class="clearBtn" type="button">Clear all Completed</button>
</main>`;
LocalStorage.getlist = jest.fn(() => [
{
description: 'First Task',
index: 1,
completed: false,
id: 1,
},
{
description: 'Second Task',
index: 2,
completed: true,
id: 2,
},
]);
const task2 = {
description: 'Third Task',
index: 3,
completed: false,
id: 3,
};
const list = LocalStorage.getlist();
describe('Add task in the list ', () => {
it('Add a task in the array for localStorage ', () => {
list.push(task2);
expect(list).toHaveLength(3);
});
it('delete a task in the array for localStorage', () => {
list.pop();
expect(list).toHaveLength(2);
});
it('Add a task in DOM', () => {
Display.addList(task2, 1);
const divlist = document.querySelectorAll('.showList > div');
expect(divlist).toHaveLength(1);
});
it('Delete a task in DOM', () => {
Display.deleteTask(2);
const divlist = document.querySelectorAll('.showList > div');
expect(divlist).toHaveLength(1);
});
});
describe('Check the completed status', () => {
it('check the value to be true', () => {
Display.changebool(1);
const info = JSON.parse(localStorage.getItem('list'));
expect(info[0].completed).toBe(true);
});
it('check the value to be false', () => {
Display.changebool(2);
const info = JSON.parse(localStorage.getItem('list'));
expect(info[1].completed).toBe(false);
});
});
describe('clear All Complete', () => {
it('Clear All complete', () => {
const task3 = {
description: 'Fourth Task',
index: 4,
completed: true,
id: 4,
};
Display.addList(task2, 1);
Display.addList(task3, 2);
Display.clearAll();
const info = JSON.parse(localStorage.getItem('list'));
expect(info.length).toBe(1);
});
});
describe('check the update function', () => {
it('change the input', () => {
Display.UpdateInput(1, 'Hello Kwaleyela');
const info = JSON.parse(localStorage.getItem('list'));
expect(info[0].description).toBe('Hello Kwaleyela');
});
});