acammies
2018-04-13 2fa8ab7e834c36a080f5cce5b6eede1ba8bc8112
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
import mutations from "@/store/mutations";
import * as all from "../setup.js";
 
let state;
const todo = {
    completed: true,
    title: "testing sucks"
};
const newTodo = "biscuits";
const doneTodos = [{
    completed: true,
    title: "testing sucks"
},{
    completed: false,
    title: "easy testing is fun"
}];
const importantTodos = [{
    completed: true,
    title: "testing sucks",
    important: true
  }]
 
describe("Mutation tests", () => {
  beforeEach(() => {
    state = {};
  });
  it("sets the loading to true", () => {
    mutations.SET_LOADING(state, true);
    expect(state.loading).toBe(true);
  });
  it("sets the loading to false", () => {
    mutations.SET_LOADING(state, false);
    expect(state.loading).toBe(false);
  });
 
  it("sets all SET_TODOS", () => {
    mutations.SET_TODOS(state, [todo]);
    expect(state.todos.length).toBe(1);
  });
 
  it("SET_NEW_TODO", () => {
    mutations.SET_NEW_TODO(state, newTodo);
    expect(state.newTodo).toEqual(newTodo);
  });
 
  it("ADD_TODO", () => {
    state.todos = []
    mutations.ADD_TODO(state, todo);
    expect(state.todos.length).toBe(1);
  });
 
  it("CLEAR_NEW_TODO", () => {
    state.newTodo = newTodo;
    mutations.CLEAR_NEW_TODO(state, newTodo);
    expect(state.newTodo).toEqual('');
  });
 
  it("CLEAR_NEW_TODO", () => {
    state.newTodo = newTodo;
    mutations.CLEAR_NEW_TODO(state);
    expect(state.newTodo).toEqual('');
  });
 
  it("CLEAR_ALL_DONE_TODOS", () => {
    state.todos = doneTodos;
    mutations.CLEAR_ALL_DONE_TODOS(state);
    expect(state.todos.length).toBe(1);
    expect(state.todos[0].completed).toBe(false);
  });
 
  it("CLEAR_ALL_TODOS", () => {
    state.todos = doneTodos;
    mutations.CLEAR_ALL_TODOS(state);
    expect(state.todos.length).toBe(0);
  });
 
  it("MARK_TODO_COMPLETED", () => {
    state.todos = doneTodos;
    mutations.MARK_TODO_COMPLETED(state, 0);
    expect(state.todos[0].completed).toBe(false);
    // check the reversy!
    mutations.MARK_TODO_COMPLETED(state, 0);
    expect(state.todos[0].completed).toBe(true);
  });
 
  it("it should MARK_TODO_IMPORTANT as false", () => {
    state.todos = importantTodos;
    mutations.MARK_TODO_IMPORTANT(state, 0);
    expect(state.todos[0].important).toBe(false);
  });
  
  it("it should MARK_TODO_IMPORTANT as true", () => {
    state.todos = importantTodos;
    state.todos[0].important = false;
    mutations.MARK_TODO_IMPORTANT(state, 0);
    expect(state.todos[0].important).toBe(true);
  });
});