-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.basic.spec.ts
98 lines (77 loc) · 2.79 KB
/
test.basic.spec.ts
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 Vue from "vue";
import store from "../store";
import { undo, redo } from "./utils-test";
const item = {
foo: "bar"
};
const state: any = store.state;
describe("Simple testing for undo/redo on a namespaced vuex store", () => {
it("Add item to list", () => {
const expectedState = [{ ...item }];
// Commit the item to the store and assert
store.commit("list/addItem", { item });
expect(state.list.list).toEqual(expectedState);
});
it("Check 'canUndo' value; The undo function should remove the item", async () => {
expect(state.list.canUndo).toBeTruthy();
await undo(store)("list");
await Vue.nextTick();
// Check 'canUndo' value, Assert list items after undo
expect(state.list.canUndo).toBeFalsy();
expect(state.list.list).toEqual([]);
});
it("Redo 'addItem' commit", async () => {
expect(state.list.canRedo).toBeTruthy();
await redo(store)("list");
});
it("Grouped mutations: adding two items to the list", async () => {
const anotherItem = { foo: "baz" };
const expectedState = [{ ...item }, { ...item }, { ...anotherItem }];
const actionGroup = "myAction";
// Commit the items to the store and assert
store.commit("list/addItem", { item, actionGroup });
store.commit("list/addItem", { item: anotherItem, actionGroup });
expect(state.list.list).toEqual(expectedState);
});
it("Dispatch undo", async () => {
// The undo function should remove the item
await undo(store)("list");
// Assert list items after undo: should contain 1 item
expect(state.list.list).toEqual([{ ...item }]);
});
it("Redo 'addItem' twice (grouped mutations)", async () => {
// Redo 'addItem'
await redo(store)("list");
const anotherItem = { foo: "baz" };
const expectedState = [{ ...item }, { ...item }, { ...anotherItem }];
// Assert list items after redo: should contain 3 items
expect(state.list.list).toEqual(expectedState);
});
it('"addShadow" action should be dispatched on undo', async () => {
let expectedState = [...state.list.list, item];
store.commit("list/addItem", {
index: 0,
item,
undoCallback: "addShadow",
redoCallback: "removeShadow"
});
expect(state.list.list).toEqual(expectedState);
await undo(store)("list");
expectedState = [{ ...item }];
expect(state.list.shadow).toEqual(expectedState);
});
it("Check shadow: should contain 1 item", () => {});
it('"removeShadow" should be dispatched on redo', async () => {
// Redo 'addItem'
await redo(store)("list");
const expectedState = [
{ foo: "bar" },
{ foo: "bar" },
{ foo: "baz" },
{ foo: "bar" }
];
expect(state.list.list).toEqual(expectedState);
// Check shadow: should contain no items
expect(state.list.shadow).toEqual([]);
});
});