-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManagerSpec.js
More file actions
100 lines (81 loc) · 2.82 KB
/
TaskManagerSpec.js
File metadata and controls
100 lines (81 loc) · 2.82 KB
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
describe('TaskManager',()=>{
describe('#constructor',()=>{
describe('when initializing a new TaskManager',()=>{
it('should create an empty tasks array',()=>{
const taskManager = new TaskManager(1);
expect(taskManager.tasks).toEqual([]);
});
it('should set the currentId to the passed in number', () => {
const taskManager = new TaskManager(1);
expect(taskManager.currentId).toBe(1);
});
});
});
describe('#addTask', () => {
describe('passing new task data as parameters', () => {
it('should add the task to the tasks array', () => {
const taskManager = new TaskManager(10);
const task = {
id: taskManager.currentId,
name: 'test',
description: 'test',
assignedTo: 'test',
dueDate: Date.now(),
status: 'TODO'
};
taskManager.addTask(task.name, task.description, task.assignedTo, task.dueDate);
expect(taskManager.tasks[0]).toEqual(task);
});
it('should increment the currentId property', () => {
const taskManager = new TaskManager(10);
const task = {
id: taskManager.currentId,
name: 'test',
description: 'test',
assignedTo: 'test',
dueDate: Date.now(),
status: 'TODO'
};
taskManager.addTask(task.name, task.description, task.assignedTo, task.dueDate);
expect(taskManager.currentId).toBe(11);
});
});
});
describe('#deleteTask', () => {
describe('when passed an existing taskId', () => {
it('should remove the task from the tasks array', () => {
const taskManager = new TaskManager();
const taskToDelete = {
id: taskManager.currentId,
name: 'test',
description: 'test',
assignedTo: 'test',
dueDate: Date.now(),
status: 'TODO'
};
taskManager.addTask(taskToDelete.name, taskToDelete.description, taskToDelete.assignedTom, taskToDelete.dueDate);
taskManager.addTask('feed puppy', 'feed the puppy a heathy meal', 'nick', Date.now());
taskManager.deleteTask(taskToDelete.id);
expect(taskManager.tasks).not.toContain(taskToDelete);
});
});
});
describe('#getTaskById', () => {
describe('when passed an existing taskId', () => {
it('should return the task', () => {
const taskManager = new TaskManager();
const task = {
id: taskManager.currentId,
name: 'test',
description: 'test',
assignedTo: 'test',
dueDate: Date.now(),
status: 'TODO'
};
taskManager.addTask(task.name, task.description, task.assignedTo, task.dueDate);
const result = taskManager.getTaskById(task.id);
expect(result).toEqual(task);
});
});
});
});