forked from N00ts/vue3-treeview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto.spec.ts
113 lines (95 loc) · 3.1 KB
/
auto.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { reactive, ref } from "vue";
import auto from '../../src/setup/checkbox/auto';
describe("test auto checkbox", () => {
let node = null;
let nodes = null;
let storeProps = null;
let mode = null;
beforeEach(() => {
node = ref({
children: ["c1", "c2"],
state: {
checked: false,
indeterminate: false
}
});
nodes = ref({
c1: {
text: "c1",
state: {
checked: false,
indeterminate: false
}
},
c2: {
text: "c2",
state: {
checked: false,
indeterminate: false
}
}
});
storeProps = reactive({
nodes
});
mode = auto(node, nodes);
});
it("Expect not to be checked", () => {
expect(mode.checked.value).toBeFalsy();
});
it("Expect not to be indeterminate", () => {
expect(mode.indeterminate.value).toBeFalsy();
});
it("Expect none to be checked", () => {
expect(mode.noneChecked.value).toBeTruthy();
});
it("Expect not all to be checked" , () => {
expect(mode.allChecked.value).toBeFalsy();
});
it("Expect to no have some indeterminate", () => {
expect(mode.someIndeterminate.value).toBeFalsy();
});
it("Expect not some checked" , () => {
expect(mode.someChecked.value).toBeFalsy();
});
it("Expect children to have state", () => {
expect(nodes.value.c1.state).toBeDefined();
expect(nodes.value.c2.state).toBeDefined();
});
it("Expect to check node", () => {
mode.click();
expect(node.value.state.checked).toBeTruthy();
expect(node.value.state.indeterminate).toBeFalsy();
});
it("Expect to rebuild", () => {
node.value.state.checked = true;
mode.rebuild();
expect(nodes.value.c1.state.checked).toBeTruthy();
expect(nodes.value.c2.state.checked).toBeTruthy();
});
it("Expect not to update state", () => {
node.value.children = [];
mode.updateState();
expect(nodes.value.c1.state.checked).toBeFalsy();
expect(nodes.value.c2.state.checked).toBeFalsy();
});
it("Expect to reset node checked on update state", () => {
node.value.state.checked = true;
node.value.state.indeterminate = true;
mode.updateState();
expect(node.value.state.checked).toBeFalsy();
expect(node.value.state.indeterminate).toBeFalsy();
});
it("Expect node to be indeterminate after update", () => {
nodes.value.c1.state.indeterminate = true;
mode.updateState();
expect(node.value.state.checked).toBeFalsy();
expect(node.value.state.indeterminate).toBeTruthy();
});
it("Expect to update nothing", () => {
node.value.children = null;
mode.updateState();
expect(node.value.state.checked).toBeFalsy();
expect(node.value.state.indeterminate).toBeFalsy();
});
});