commit | author | age
|
c89de6
|
1 |
import mutations from "@/store/mutations"; |
9d6970
|
2 |
import * as all from "../setup.js"; |
c89de6
|
3 |
|
D |
4 |
let state; |
|
5 |
const todo = { |
991fcf
|
6 |
completed: true, |
D |
7 |
title: "testing sucks" |
c89de6
|
8 |
}; |
D |
9 |
const newTodo = "biscuits"; |
991fcf
|
10 |
const doneTodos = [ |
D |
11 |
{ |
c89de6
|
12 |
completed: true, |
D |
13 |
title: "testing sucks" |
991fcf
|
14 |
}, |
D |
15 |
{ |
c89de6
|
16 |
completed: false, |
D |
17 |
title: "easy testing is fun" |
991fcf
|
18 |
} |
D |
19 |
]; |
|
20 |
const importantTodos = [ |
|
21 |
{ |
2fa8ab
|
22 |
completed: true, |
A |
23 |
title: "testing sucks", |
|
24 |
important: true |
991fcf
|
25 |
} |
D |
26 |
]; |
c89de6
|
27 |
|
D |
28 |
describe("Mutation tests", () => { |
|
29 |
beforeEach(() => { |
|
30 |
state = {}; |
|
31 |
}); |
|
32 |
it("sets the loading to true", () => { |
|
33 |
mutations.SET_LOADING(state, true); |
|
34 |
expect(state.loading).toBe(true); |
|
35 |
}); |
|
36 |
it("sets the loading to false", () => { |
|
37 |
mutations.SET_LOADING(state, false); |
|
38 |
expect(state.loading).toBe(false); |
|
39 |
}); |
|
40 |
|
|
41 |
it("sets all SET_TODOS", () => { |
|
42 |
mutations.SET_TODOS(state, [todo]); |
|
43 |
expect(state.todos.length).toBe(1); |
|
44 |
}); |
|
45 |
|
|
46 |
it("SET_NEW_TODO", () => { |
|
47 |
mutations.SET_NEW_TODO(state, newTodo); |
|
48 |
expect(state.newTodo).toEqual(newTodo); |
|
49 |
}); |
|
50 |
|
|
51 |
it("ADD_TODO", () => { |
991fcf
|
52 |
state.todos = []; |
c89de6
|
53 |
mutations.ADD_TODO(state, todo); |
D |
54 |
expect(state.todos.length).toBe(1); |
|
55 |
}); |
|
56 |
|
|
57 |
it("CLEAR_NEW_TODO", () => { |
|
58 |
state.newTodo = newTodo; |
|
59 |
mutations.CLEAR_NEW_TODO(state, newTodo); |
991fcf
|
60 |
expect(state.newTodo).toEqual(""); |
c89de6
|
61 |
}); |
D |
62 |
|
|
63 |
it("CLEAR_NEW_TODO", () => { |
|
64 |
state.newTodo = newTodo; |
|
65 |
mutations.CLEAR_NEW_TODO(state); |
991fcf
|
66 |
expect(state.newTodo).toEqual(""); |
c89de6
|
67 |
}); |
D |
68 |
|
|
69 |
it("CLEAR_ALL_DONE_TODOS", () => { |
|
70 |
state.todos = doneTodos; |
|
71 |
mutations.CLEAR_ALL_DONE_TODOS(state); |
|
72 |
expect(state.todos.length).toBe(1); |
|
73 |
expect(state.todos[0].completed).toBe(false); |
|
74 |
}); |
|
75 |
|
|
76 |
it("CLEAR_ALL_TODOS", () => { |
|
77 |
state.todos = doneTodos; |
|
78 |
mutations.CLEAR_ALL_TODOS(state); |
|
79 |
expect(state.todos.length).toBe(0); |
|
80 |
}); |
|
81 |
|
|
82 |
it("MARK_TODO_COMPLETED", () => { |
|
83 |
state.todos = doneTodos; |
|
84 |
mutations.MARK_TODO_COMPLETED(state, 0); |
|
85 |
expect(state.todos[0].completed).toBe(false); |
|
86 |
// check the reversy! |
|
87 |
mutations.MARK_TODO_COMPLETED(state, 0); |
|
88 |
expect(state.todos[0].completed).toBe(true); |
|
89 |
}); |
2fa8ab
|
90 |
|
A |
91 |
it("it should MARK_TODO_IMPORTANT as false", () => { |
|
92 |
state.todos = importantTodos; |
991fcf
|
93 |
// TODO - test goes here! |
78a403
|
94 |
|
2fa8ab
|
95 |
}); |
991fcf
|
96 |
|
2fa8ab
|
97 |
it("it should MARK_TODO_IMPORTANT as true", () => { |
A |
98 |
state.todos = importantTodos; |
991fcf
|
99 |
// TODO - test goes here! |
78a403
|
100 |
|
2fa8ab
|
101 |
}); |
c89de6
|
102 |
}); |