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