marketingPushStrategy.components.integration.spec.js
4.03 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { createLocalVue, mount } from "@vue/test-utils";
jest.mock("@/views/marketingManagement/marketingPushStrategy/components/messageType", () => ({
name: "MessageType",
render(h) {
return h("div");
},
}));
jest.mock("@/views/marketingManagement/marketingPushStrategy/components/conditionPanel/index.vue", () => ({
name: "ConditionPanel",
render(h) {
return h("div");
},
}));
const ConditionGroup = require("./components/conditionGroup/index.vue").default;
const BranchItem = require("./components/branchItem/index.vue").default;
const { ConditionVariableSourceTypeEnum } = require("./constant/index.js");
function findChildByMethod(vm, methodName) {
if (!vm || !vm.$children) {
return null;
}
for (const child of vm.$children) {
if (typeof child[methodName] === "function") {
return child;
}
const matched = findChildByMethod(child, methodName);
if (matched) {
return matched;
}
}
return null;
}
describe("marketingPushStrategy 组件联动集成测试", () => {
const localVue = createLocalVue();
let wrapper;
let consoleLogSpy;
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
});
afterEach(() => {
if (wrapper) {
wrapper.destroy();
}
consoleLogSpy.mockRestore();
jest.clearAllMocks();
});
it("conditionGroup -> ConditionItem -> ConditionContainer 应完成条件值联动更新", async () => {
const resetFieldsMock = jest.fn();
wrapper = mount(ConditionGroup, {
localVue,
propsData: {
list: [
{
_key: "g1",
conditions: [
{
_key: "c1",
variableCode: "",
valueSource: ConditionVariableSourceTypeEnum.VALUE,
},
],
},
],
options: {
conditionVariables: [
{
variableCode: "customerLevel",
variableName: "客户等级",
variableType: 4,
operators: [{ code: "EQ", name: "等于" }],
sopConditionVariableDTOList: [{ variableCode: "customerTag", variableName: "客户标签" }],
enumValues: [{ enumCode: "VIP", enumName: "VIP客户" }],
},
],
},
},
stubs: {
"el-form": {
name: "el-form",
render(h) {
return h("form", this.$slots.default);
},
methods: {
resetFields: resetFieldsMock,
},
},
"el-form-item": true,
"el-button": true,
"el-divider": true,
"el-select": true,
"el-option": true,
"el-radio-group": true,
"el-radio-button": true,
"el-input": true,
"el-input-number": true,
"el-date-picker": true,
},
});
expect(resetFieldsMock).toHaveBeenCalled();
const conditionContainerVm = findChildByMethod(wrapper.vm, "handleVariableChange");
conditionContainerVm.handleVariableChange("customerLevel");
await wrapper.vm.$nextTick();
expect(wrapper.emitted("input")[0][0][0].conditions[0]).toEqual(
expect.objectContaining({
variableCode: "customerLevel",
valueType: 4,
valueSource: ConditionVariableSourceTypeEnum.VALUE,
}),
);
});
it("branchItem -> ActionsItem 应完成动作变更向上透传", async () => {
wrapper = mount(BranchItem, {
localVue,
provide: {
elForm: {
validateField: jest.fn(),
},
},
propsData: {
propPrefix: "branches[0]",
options: {
messageVariables: [],
triggers: [],
conditionVariables: [],
},
branch: {
conditionGroups: [],
actions: [
{
_key: "a1",
actionType: 1,
targetGroupType: 1,
messageType: 1,
content: "",
medias: [],
},
],
},
},
stubs: {
"el-button": true,
"el-form-item": true,
"el-select": true,
"el-option": true,
"el-radio-group": true,
"el-radio": true,
},
});
const actionsVm = wrapper.vm.$children.find(child => child.$options && child.$options.components && child.$options.components.MessageType);
actionsVm.handleActionTypeChange(2);
await wrapper.vm.$nextTick();
expect(wrapper.emitted("input")[0]).toEqual([
{
actionItem: expect.objectContaining({
actionType: 2,
}),
actionIndex: 0,
},
]);
});
});