index.spec.js
3.21 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { createLocalVue, shallowMount } from "@vue/test-utils";
const mockGetDefaultConditionGroup = jest.fn();
jest.mock(
"@/views/marketingManagement/marketingPushStrategy/components/conditionGroup/constant.js",
() => ({
getDefaultConditionGroup: mockGetDefaultConditionGroup,
}),
);
jest.mock(
"@/views/marketingManagement/marketingPushStrategy/components/conditionGroup/index.vue",
() => ({
name: "ConditionGroup",
render(h) {
return h("div");
},
}),
);
jest.mock(
"@/views/marketingManagement/marketingPushStrategy/components/conditionTextyPanel/index.vue",
() => ({
name: "ConditionTextPanel",
render(h) {
return h("div");
},
}),
);
const ConditionPanel = require("./index.vue").default;
describe("marketingPushStrategy components/conditionPanel", () => {
const localVue = createLocalVue();
let wrapper;
afterEach(() => {
if (wrapper) {
wrapper.destroy();
}
jest.clearAllMocks();
});
function createWrapper(propsData = {}) {
wrapper = shallowMount(ConditionPanel, {
localVue,
propsData: {
list: [],
conditionVariablesOptions: [],
...propsData,
},
stubs: {
"el-button": true,
"el-drawer": true,
},
});
return wrapper;
}
it("handleClearCondition 应清空并同步给父组件", () => {
createWrapper({ list: [{ id: 1 }] });
wrapper.vm.handleClearCondition();
expect(wrapper.emitted("input")[0]).toEqual([[]]);
expect(wrapper.emitted("change")[0]).toEqual([[]]);
});
it("handleShowConditionGroup 应复制现有条件并打开抽屉", () => {
const list = [{ id: 1, conditions: [{ conditionDesc: "A" }] }];
createWrapper({ list });
wrapper.vm.handleShowConditionGroup();
expect(wrapper.vm.dialog.step2ConditionGroup.show).toBe(true);
expect(wrapper.vm.dialog.step2ConditionGroup.conditionCache).toEqual(list);
expect(wrapper.vm.dialog.step2ConditionGroup.conditionCache).not.toBe(list);
});
it("handleShowConditionGroup 在空条件时应补默认条件组", () => {
mockGetDefaultConditionGroup.mockReturnValue({ id: "default-group" });
createWrapper({ list: [] });
wrapper.vm.handleShowConditionGroup();
expect(mockGetDefaultConditionGroup).toHaveBeenCalled();
expect(wrapper.vm.dialog.step2ConditionGroup.conditionCache).toEqual([
{ id: "default-group" },
]);
});
it("handleConfirmConditionGroup 校验通过后应透传条件并关闭抽屉", async () => {
const validate = jest.fn().mockResolvedValue();
const emit = jest.fn();
const handleCloseConditionGroup = jest.fn();
const ctx = {
$refs: {
ConditionGroupRef: {
$refs: {
ConditionFormRef: {
validate,
},
},
},
},
dialog: {
step2ConditionGroup: {
show: true,
conditionCache: [{ id: "group-1", conditions: [{ conditionDesc: "B" }] }],
},
},
$emit: emit,
handleCloseConditionGroup,
};
await ConditionPanel.methods.handleConfirmConditionGroup.call(ctx);
expect(validate).toHaveBeenCalled();
expect(emit.mock.calls[0]).toEqual([
"input",
[{ id: "group-1", conditions: [{ conditionDesc: "B" }] }],
]);
expect(emit.mock.calls[1]).toEqual([
"change",
[{ id: "group-1", conditions: [{ conditionDesc: "B" }] }],
]);
expect(handleCloseConditionGroup).toHaveBeenCalled();
});
});