-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-delete.test.js
61 lines (52 loc) · 1.48 KB
/
add-delete.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
import ToDoList from './src/modules/render.js';
document.body.innerHTML = `
<form action='#' class='add-submit'>
<input placeholder='Add your task...' type='text' class='add-list'>
<input type='submit' class='submit' value='' title='click this or press enter to submit'>
</form>
</div>
</div>
<div id='to-do-list'></div>
<button class='clear-completed'>Clear all completed</button>
`;
describe('ToDo', () => {
let todo;
beforeEach(() => {
todo = new ToDoList();
});
afterEach(() => {
localStorage.clear();
});
test('adds a task', () => {
todo.addBook('Task 1');
expect(todo.collection.length).toBe(1);
});
test('removes a task', () => {
todo.addBook('Task 1');
todo.addBook('Task 2');
todo.removeBook(0);
expect(todo.collection.length).toBe(1);
});
test('edit a task', () => {
todo.addBook('Task 1');
todo.addBook('Task 1');
const index = 1;
const description = 'new list';
todo.editBook(index, description);
expect(todo.collection[1].description).toBe('new list');
});
test('update completeed status', () => {
todo.addBook('Task 1');
todo.addBook('Task 1');
todo.collection[0].completed = true;
expect(todo.collection[0].completed).toBe(true);
});
test('clear All', () => {
todo.addBook('Task 1');
todo.addBook('Task 2');
todo.collection[0].completed = true;
todo.clearAll();
expect(todo.collection[0].description).toBe('Task 2');
expect(todo.collection.length).toBe(1);
});
});