forked from N00ts/vue3-treeview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
useCommon.spec.ts
93 lines (75 loc) · 2.27 KB
/
useCommon.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
import { reactive, ref, inject } from 'vue';
import { createState, states } from '../../src/setup/store';
import useCommon from '../../src/setup/useCommon';
describe("test useCommon", () => {
let props = null;
let useTest = null;
const config = {
roots: ["id1"],
disabled: false,
editing: null
};
const storeProps = reactive({
nodes: {},
config
});
const v = require("vue");
let state = null;
v.inject = jest.fn((s) => {
return s === "emitter" ? jest.fn() : {
config: ref(config)
}
});
beforeEach(() => {
props = reactive({
node: ref({
id: "test"
})
});
const id = createState(storeProps);
state = states.get(id);
useTest = useCommon(props);
});
it("Expect to have state", () => {
expect(props.node.state).toBeDefined();
});
it("Expect to have node", () => {
expect(useTest.hasNode.value).toBeTruthy();
});
it("Expect to have config", () => {
expect(useTest.hasConfig.value).toBeTruthy();
});
it("Expect to have state", () => {
expect(useTest.hasState.value).toBeTruthy();
});
it("Expect not to be disabled", () => {
expect(useTest.disabled.value).toBeFalsy();
});
it("Expect not to be editable", () => {
expect(useTest.editable.value).toBeFalsy();
});
it("Expect not to be edited", () => {
expect(useTest.editing.value).toBeFalsy();
});
it("Expect to be editable", () => {
state.config.value.editable = true;
props.node.state.editable = true;
expect(useTest.editable.value).toBeTruthy();
});
it("Expect to be editing", () => {
state.config.value.editable = true;
state.config.value.editing = "test";
props.node.state.editable = true;
expect(useTest.editable.value).toBeTruthy();
});
it("Expect to blur", () => {
state.config.value.editing = "tata";
const e = {
currentTarget: document.createElement("div"),
relatedTarget: document.createElement("div"),
type: "blur"
};
useTest.blur(e);
expect(state.config.value.editing).toBeNull();
});
});