@infly/ui 1.0.29 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +799 -799
- package/package.json +1 -1
- package/src/Base/InflyForm/InflyForm.test.js +329 -329
- package/src/Base/InflyForm/InflyForm.vue +986 -986
- package/src/Base/InflyInput/InflyInput.test.js +105 -105
- package/src/Base/InflyInput/InflyInput.vue +167 -167
- package/src/Base/InflyList/InflyList.test.js +229 -229
- package/src/Base/InflyList/InflyList.vue +926 -926
- package/src/Business/BusinessSwitch/BusinessSwitch.test.js +250 -250
- package/src/Business/BusinessTag/BusinessTag.test.js +70 -70
- package/src/Business/InstitutionSelect/InstitutionSelect.test.js +281 -281
package/package.json
CHANGED
|
@@ -1,329 +1,329 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* InflyForm 组件测试
|
|
3
|
-
*
|
|
4
|
-
* 验证配置化表单的渲染、筛选列表、按钮组、编辑/展示模式等核心行为。
|
|
5
|
-
* 使用 shallowMount 隔离子组件依赖。
|
|
6
|
-
*/
|
|
7
|
-
const { shallowMount, createLocalVue } = require("../../../test/helper");
|
|
8
|
-
const InflyForm = require("./InflyForm.vue");
|
|
9
|
-
|
|
10
|
-
describe("InflyForm", () => {
|
|
11
|
-
describe("渲染", () => {
|
|
12
|
-
it("渲染容器 div", () => {
|
|
13
|
-
const wrapper = shallowMount(InflyForm, {
|
|
14
|
-
propsData: { formData: {} },
|
|
15
|
-
});
|
|
16
|
-
assert.ok(wrapper.find(".comp-InflyForm").exists());
|
|
17
|
-
wrapper.destroy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("注入表单 class", () => {
|
|
21
|
-
const wrapper = shallowMount(InflyForm, {
|
|
22
|
-
propsData: {
|
|
23
|
-
formData: {},
|
|
24
|
-
formClass: "my-form",
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
assert.ok(wrapper.exists());
|
|
28
|
-
wrapper.destroy();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("layout 属性影响 class", () => {
|
|
32
|
-
const wrapper = shallowMount(InflyForm, {
|
|
33
|
-
propsData: {
|
|
34
|
-
formData: {},
|
|
35
|
-
layout: "inline",
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
assert.ok(wrapper.vm.layoutClass.includes("standard-form--inline"));
|
|
39
|
-
wrapper.destroy();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("多 layout 组合", () => {
|
|
43
|
-
const wrapper = shallowMount(InflyForm, {
|
|
44
|
-
propsData: {
|
|
45
|
-
formData: {},
|
|
46
|
-
layout: ["inline", "compact"],
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
const cls = wrapper.vm.layoutClass;
|
|
50
|
-
assert.ok(cls.includes("standard-form--inline"));
|
|
51
|
-
assert.ok(cls.includes("standard-form--compact"));
|
|
52
|
-
wrapper.destroy();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("按钮", () => {
|
|
57
|
-
it("默认显示查询按钮,隐藏重置按钮", () => {
|
|
58
|
-
const wrapper = shallowMount(InflyForm, {
|
|
59
|
-
propsData: { formData: {} },
|
|
60
|
-
});
|
|
61
|
-
const optList = wrapper.vm.formOptBtnList;
|
|
62
|
-
// 默认 hideSearchBtn=false(显示查询),hideResetBtn=true(隐藏重置)
|
|
63
|
-
const queryBtn = optList.find((b) => b.label === "查询");
|
|
64
|
-
const resetBtn = optList.find((b) => b.label === "重置");
|
|
65
|
-
assert.equal(queryBtn.isHide, false);
|
|
66
|
-
assert.equal(resetBtn.isHide, true);
|
|
67
|
-
wrapper.destroy();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("hideSearchBtn=true 时隐藏查询按钮", () => {
|
|
71
|
-
const wrapper = shallowMount(InflyForm, {
|
|
72
|
-
propsData: {
|
|
73
|
-
formData: {},
|
|
74
|
-
hideSearchBtn: true,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const queryBtn = wrapper.vm.formOptBtnList.find((b) => b.label === "查询");
|
|
78
|
-
assert.equal(queryBtn.isHide, true);
|
|
79
|
-
wrapper.destroy();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("hideResetBtn=false 时显示重置按钮", () => {
|
|
83
|
-
const wrapper = shallowMount(InflyForm, {
|
|
84
|
-
propsData: {
|
|
85
|
-
formData: {},
|
|
86
|
-
hideResetBtn: false,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
const resetBtn = wrapper.vm.formOptBtnList.find((b) => b.label === "重置");
|
|
90
|
-
assert.equal(resetBtn.isHide, false);
|
|
91
|
-
wrapper.destroy();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("btnList 渲染外部按钮", () => {
|
|
95
|
-
const btnList = [{ name: "导出", label: "导出" }];
|
|
96
|
-
const wrapper = shallowMount(InflyForm, {
|
|
97
|
-
propsData: {
|
|
98
|
-
formData: {},
|
|
99
|
-
btnList,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
assert.equal(wrapper.vm.visibleBtnList.length, 1);
|
|
103
|
-
assert.equal(wrapper.vm.visibleBtnList[0].name, "导出");
|
|
104
|
-
wrapper.destroy();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("optBtnList 追加操作按钮", () => {
|
|
108
|
-
const optBtnList = [{ name: "批量操作", label: "批量操作" }];
|
|
109
|
-
const wrapper = shallowMount(InflyForm, {
|
|
110
|
-
propsData: {
|
|
111
|
-
formData: {},
|
|
112
|
-
optBtnList,
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
assert.ok(wrapper.vm.formOptBtnList.length >= 3); // 查询+重置+optBtnList
|
|
116
|
-
wrapper.destroy();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe("筛选列表", () => {
|
|
121
|
-
it("filterList 过滤 isHide=true 项", () => {
|
|
122
|
-
const filterList = [
|
|
123
|
-
{ label: "姓名", name: "name", type: "text" },
|
|
124
|
-
{ label: "隐藏项", name: "secret", type: "text", isHide: true },
|
|
125
|
-
];
|
|
126
|
-
const wrapper = shallowMount(InflyForm, {
|
|
127
|
-
propsData: { formData: {}, filterList },
|
|
128
|
-
});
|
|
129
|
-
// visibleFilterList 不包含隐藏项
|
|
130
|
-
const names = wrapper.vm.visibleFilterList.map((f) => f.name);
|
|
131
|
-
assert.ok(names.includes("name"));
|
|
132
|
-
assert.ok(!names.includes("secret"));
|
|
133
|
-
wrapper.destroy();
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("filterList isHide 支持函数", () => {
|
|
137
|
-
const filterList = [
|
|
138
|
-
{ label: "姓名", name: "name", type: "text" },
|
|
139
|
-
{
|
|
140
|
-
label: "条件项",
|
|
141
|
-
name: "conditional",
|
|
142
|
-
type: "text",
|
|
143
|
-
isHide: (formData) => formData.showSecret !== true,
|
|
144
|
-
},
|
|
145
|
-
];
|
|
146
|
-
const wrapper = shallowMount(InflyForm, {
|
|
147
|
-
propsData: {
|
|
148
|
-
formData: { showSecret: true },
|
|
149
|
-
filterList,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
// showSecret=true 时条件项不隐藏
|
|
153
|
-
const names = wrapper.vm.visibleFilterList.map((f) => f.name);
|
|
154
|
-
assert.ok(names.includes("conditional"));
|
|
155
|
-
wrapper.destroy();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("labelRender 不归入事件,保留在属性层", () => {
|
|
159
|
-
const labelRender = (value, formData) => `自定义 ${formData.name}`;
|
|
160
|
-
const filterList = [{ label: "姓名", name: "name", type: "text", labelRender }];
|
|
161
|
-
const wrapper = shallowMount(InflyForm, {
|
|
162
|
-
propsData: { formData: {}, filterList },
|
|
163
|
-
});
|
|
164
|
-
const item = wrapper.vm.visibleFilterList[0];
|
|
165
|
-
assert.equal(item.labelRender, labelRender);
|
|
166
|
-
assert.equal(item.__events__.labelRender, undefined);
|
|
167
|
-
wrapper.destroy();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("配置 labelRender 时传入 label 插槽", () => {
|
|
171
|
-
const labelRender = () => "自定义 label";
|
|
172
|
-
const filterList = [{ label: "姓名", name: "name", type: "text", labelRender }];
|
|
173
|
-
const wrapper = shallowMount(InflyForm, {
|
|
174
|
-
propsData: { formData: {}, filterList },
|
|
175
|
-
});
|
|
176
|
-
const formItem = wrapper.find("el-form-item-stub");
|
|
177
|
-
// VTU stub 不渲染插槽内容,断言插槽已正确传递
|
|
178
|
-
assert.ok(Array.isArray(formItem.vm.$slots.label) && formItem.vm.$slots.label.length > 0);
|
|
179
|
-
wrapper.destroy();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("labelRender 支持 VNode 对象直传(JSX 元素)", () => {
|
|
183
|
-
const Vue = createLocalVue();
|
|
184
|
-
const vnode = new Vue().$createElement("span", "自定义 label");
|
|
185
|
-
const filterList = [{ label: "姓名", name: "name", type: "text", labelRender: vnode }];
|
|
186
|
-
const wrapper = shallowMount(InflyForm, {
|
|
187
|
-
propsData: { formData: {}, filterList },
|
|
188
|
-
});
|
|
189
|
-
const item = wrapper.vm.visibleFilterList[0];
|
|
190
|
-
assert.equal(item.labelRender, vnode);
|
|
191
|
-
assert.equal(item.__events__.labelRender, undefined);
|
|
192
|
-
wrapper.destroy();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("未配置 labelRender 时渲染 label 文本,无 label 插槽", () => {
|
|
196
|
-
const filterList = [{ label: "姓名", name: "name", type: "text" }];
|
|
197
|
-
const wrapper = shallowMount(InflyForm, {
|
|
198
|
-
propsData: { formData: {}, filterList },
|
|
199
|
-
});
|
|
200
|
-
const formItem = wrapper.find("el-form-item-stub");
|
|
201
|
-
assert.ok(!formItem.vm.$slots.label);
|
|
202
|
-
assert.equal(formItem.props().label, "姓名");
|
|
203
|
-
wrapper.destroy();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("无 name 时使用 prop 作为回退", () => {
|
|
207
|
-
const filterList = [{ label: "姓名", prop: "name", type: "text" }];
|
|
208
|
-
const wrapper = shallowMount(InflyForm, {
|
|
209
|
-
propsData: { formData: {}, filterList },
|
|
210
|
-
});
|
|
211
|
-
assert.equal(wrapper.vm.visibleFilterList[0].name, "name");
|
|
212
|
-
wrapper.destroy();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("自定义空值显示 emptyStr", () => {
|
|
216
|
-
const wrapper = shallowMount(InflyForm, {
|
|
217
|
-
propsData: {
|
|
218
|
-
formData: { name: "" },
|
|
219
|
-
emptyStr: "暂无数据",
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
assert.equal(wrapper.props().emptyStr, "暂无数据");
|
|
223
|
-
wrapper.destroy();
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe("表单方法", () => {
|
|
228
|
-
it("validate 方法存在", () => {
|
|
229
|
-
const wrapper = shallowMount(InflyForm, {
|
|
230
|
-
propsData: { formData: {} },
|
|
231
|
-
});
|
|
232
|
-
assert.equal(typeof wrapper.vm.validate, "function");
|
|
233
|
-
wrapper.destroy();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it("getFormInstance 方法存在", () => {
|
|
237
|
-
const wrapper = shallowMount(InflyForm, {
|
|
238
|
-
propsData: { formData: {}, formRef: "myForm" },
|
|
239
|
-
});
|
|
240
|
-
assert.equal(typeof wrapper.vm.getFormInstance, "function");
|
|
241
|
-
wrapper.destroy();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("clearValidate 方法存在", () => {
|
|
245
|
-
const wrapper = shallowMount(InflyForm, {
|
|
246
|
-
propsData: { formData: {} },
|
|
247
|
-
});
|
|
248
|
-
assert.equal(typeof wrapper.vm.clearValidate, "function");
|
|
249
|
-
wrapper.destroy();
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe("编辑模式", () => {
|
|
254
|
-
it("isEdit prop 控制编辑模式", () => {
|
|
255
|
-
const wrapper = shallowMount(InflyForm, {
|
|
256
|
-
propsData: {
|
|
257
|
-
formData: {},
|
|
258
|
-
isEdit: false,
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
assert.equal(wrapper.vm.computedEdit, false);
|
|
262
|
-
wrapper.destroy();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("isEdit=true 时进入编辑模式", () => {
|
|
266
|
-
const wrapper = shallowMount(InflyForm, {
|
|
267
|
-
propsData: {
|
|
268
|
-
formData: {},
|
|
269
|
-
isEdit: true,
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
assert.equal(wrapper.vm.computedEdit, true);
|
|
273
|
-
wrapper.destroy();
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe("InflyFormRenderCell", () => {
|
|
278
|
-
function getRenderCell() {
|
|
279
|
-
const wrapper = shallowMount(InflyForm, { propsData: { formData: {} } });
|
|
280
|
-
const RenderCell = wrapper.vm.$options.components.InflyFormRenderCell;
|
|
281
|
-
wrapper.destroy();
|
|
282
|
-
return RenderCell;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
it("renderFn 为函数且返回 VNode 时渲染该 VNode", () => {
|
|
286
|
-
const RenderCell = getRenderCell();
|
|
287
|
-
const h = new (createLocalVue())().$createElement;
|
|
288
|
-
const cell = shallowMount(RenderCell, {
|
|
289
|
-
propsData: { renderFn: () => h("b", "加粗文本") },
|
|
290
|
-
});
|
|
291
|
-
assert.ok(cell.find("b").exists());
|
|
292
|
-
assert.equal(cell.text(), "加粗文本");
|
|
293
|
-
cell.destroy();
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("renderFn 为 VNode 对象时原样渲染(labelRender JSX 直传)", () => {
|
|
297
|
-
const RenderCell = getRenderCell();
|
|
298
|
-
const h = new (createLocalVue())().$createElement;
|
|
299
|
-
const vnode = h("span", "自定义 label");
|
|
300
|
-
const cell = shallowMount(RenderCell, {
|
|
301
|
-
propsData: { renderFn: vnode },
|
|
302
|
-
});
|
|
303
|
-
assert.ok(cell.find("span").exists());
|
|
304
|
-
assert.equal(cell.text(), "自定义 label");
|
|
305
|
-
cell.destroy();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it("renderFn 为函数且返回字符串时包裹 containerTag", () => {
|
|
309
|
-
const RenderCell = getRenderCell();
|
|
310
|
-
const cell = shallowMount(RenderCell, {
|
|
311
|
-
propsData: { renderFn: () => "纯文本", containerTag: "span" },
|
|
312
|
-
});
|
|
313
|
-
assert.ok(cell.find("span").exists());
|
|
314
|
-
assert.equal(cell.text(), "纯文本");
|
|
315
|
-
cell.destroy();
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
describe("事件", () => {
|
|
320
|
-
it("resetFormData 触发 reset-form 事件", () => {
|
|
321
|
-
const wrapper = shallowMount(InflyForm, {
|
|
322
|
-
propsData: { formData: { name: "test" } },
|
|
323
|
-
});
|
|
324
|
-
wrapper.vm.resetFormData();
|
|
325
|
-
assert.ok(wrapper.emitted("reset-form"));
|
|
326
|
-
wrapper.destroy();
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* InflyForm 组件测试
|
|
3
|
+
*
|
|
4
|
+
* 验证配置化表单的渲染、筛选列表、按钮组、编辑/展示模式等核心行为。
|
|
5
|
+
* 使用 shallowMount 隔离子组件依赖。
|
|
6
|
+
*/
|
|
7
|
+
const { shallowMount, createLocalVue } = require("../../../test/helper");
|
|
8
|
+
const InflyForm = require("./InflyForm.vue");
|
|
9
|
+
|
|
10
|
+
describe("InflyForm", () => {
|
|
11
|
+
describe("渲染", () => {
|
|
12
|
+
it("渲染容器 div", () => {
|
|
13
|
+
const wrapper = shallowMount(InflyForm, {
|
|
14
|
+
propsData: { formData: {} },
|
|
15
|
+
});
|
|
16
|
+
assert.ok(wrapper.find(".comp-InflyForm").exists());
|
|
17
|
+
wrapper.destroy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("注入表单 class", () => {
|
|
21
|
+
const wrapper = shallowMount(InflyForm, {
|
|
22
|
+
propsData: {
|
|
23
|
+
formData: {},
|
|
24
|
+
formClass: "my-form",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
assert.ok(wrapper.exists());
|
|
28
|
+
wrapper.destroy();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("layout 属性影响 class", () => {
|
|
32
|
+
const wrapper = shallowMount(InflyForm, {
|
|
33
|
+
propsData: {
|
|
34
|
+
formData: {},
|
|
35
|
+
layout: "inline",
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
assert.ok(wrapper.vm.layoutClass.includes("standard-form--inline"));
|
|
39
|
+
wrapper.destroy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("多 layout 组合", () => {
|
|
43
|
+
const wrapper = shallowMount(InflyForm, {
|
|
44
|
+
propsData: {
|
|
45
|
+
formData: {},
|
|
46
|
+
layout: ["inline", "compact"],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const cls = wrapper.vm.layoutClass;
|
|
50
|
+
assert.ok(cls.includes("standard-form--inline"));
|
|
51
|
+
assert.ok(cls.includes("standard-form--compact"));
|
|
52
|
+
wrapper.destroy();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("按钮", () => {
|
|
57
|
+
it("默认显示查询按钮,隐藏重置按钮", () => {
|
|
58
|
+
const wrapper = shallowMount(InflyForm, {
|
|
59
|
+
propsData: { formData: {} },
|
|
60
|
+
});
|
|
61
|
+
const optList = wrapper.vm.formOptBtnList;
|
|
62
|
+
// 默认 hideSearchBtn=false(显示查询),hideResetBtn=true(隐藏重置)
|
|
63
|
+
const queryBtn = optList.find((b) => b.label === "查询");
|
|
64
|
+
const resetBtn = optList.find((b) => b.label === "重置");
|
|
65
|
+
assert.equal(queryBtn.isHide, false);
|
|
66
|
+
assert.equal(resetBtn.isHide, true);
|
|
67
|
+
wrapper.destroy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("hideSearchBtn=true 时隐藏查询按钮", () => {
|
|
71
|
+
const wrapper = shallowMount(InflyForm, {
|
|
72
|
+
propsData: {
|
|
73
|
+
formData: {},
|
|
74
|
+
hideSearchBtn: true,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const queryBtn = wrapper.vm.formOptBtnList.find((b) => b.label === "查询");
|
|
78
|
+
assert.equal(queryBtn.isHide, true);
|
|
79
|
+
wrapper.destroy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("hideResetBtn=false 时显示重置按钮", () => {
|
|
83
|
+
const wrapper = shallowMount(InflyForm, {
|
|
84
|
+
propsData: {
|
|
85
|
+
formData: {},
|
|
86
|
+
hideResetBtn: false,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const resetBtn = wrapper.vm.formOptBtnList.find((b) => b.label === "重置");
|
|
90
|
+
assert.equal(resetBtn.isHide, false);
|
|
91
|
+
wrapper.destroy();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("btnList 渲染外部按钮", () => {
|
|
95
|
+
const btnList = [{ name: "导出", label: "导出" }];
|
|
96
|
+
const wrapper = shallowMount(InflyForm, {
|
|
97
|
+
propsData: {
|
|
98
|
+
formData: {},
|
|
99
|
+
btnList,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
assert.equal(wrapper.vm.visibleBtnList.length, 1);
|
|
103
|
+
assert.equal(wrapper.vm.visibleBtnList[0].name, "导出");
|
|
104
|
+
wrapper.destroy();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("optBtnList 追加操作按钮", () => {
|
|
108
|
+
const optBtnList = [{ name: "批量操作", label: "批量操作" }];
|
|
109
|
+
const wrapper = shallowMount(InflyForm, {
|
|
110
|
+
propsData: {
|
|
111
|
+
formData: {},
|
|
112
|
+
optBtnList,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
assert.ok(wrapper.vm.formOptBtnList.length >= 3); // 查询+重置+optBtnList
|
|
116
|
+
wrapper.destroy();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("筛选列表", () => {
|
|
121
|
+
it("filterList 过滤 isHide=true 项", () => {
|
|
122
|
+
const filterList = [
|
|
123
|
+
{ label: "姓名", name: "name", type: "text" },
|
|
124
|
+
{ label: "隐藏项", name: "secret", type: "text", isHide: true },
|
|
125
|
+
];
|
|
126
|
+
const wrapper = shallowMount(InflyForm, {
|
|
127
|
+
propsData: { formData: {}, filterList },
|
|
128
|
+
});
|
|
129
|
+
// visibleFilterList 不包含隐藏项
|
|
130
|
+
const names = wrapper.vm.visibleFilterList.map((f) => f.name);
|
|
131
|
+
assert.ok(names.includes("name"));
|
|
132
|
+
assert.ok(!names.includes("secret"));
|
|
133
|
+
wrapper.destroy();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("filterList isHide 支持函数", () => {
|
|
137
|
+
const filterList = [
|
|
138
|
+
{ label: "姓名", name: "name", type: "text" },
|
|
139
|
+
{
|
|
140
|
+
label: "条件项",
|
|
141
|
+
name: "conditional",
|
|
142
|
+
type: "text",
|
|
143
|
+
isHide: (formData) => formData.showSecret !== true,
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
const wrapper = shallowMount(InflyForm, {
|
|
147
|
+
propsData: {
|
|
148
|
+
formData: { showSecret: true },
|
|
149
|
+
filterList,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
// showSecret=true 时条件项不隐藏
|
|
153
|
+
const names = wrapper.vm.visibleFilterList.map((f) => f.name);
|
|
154
|
+
assert.ok(names.includes("conditional"));
|
|
155
|
+
wrapper.destroy();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("labelRender 不归入事件,保留在属性层", () => {
|
|
159
|
+
const labelRender = (value, formData) => `自定义 ${formData.name}`;
|
|
160
|
+
const filterList = [{ label: "姓名", name: "name", type: "text", labelRender }];
|
|
161
|
+
const wrapper = shallowMount(InflyForm, {
|
|
162
|
+
propsData: { formData: {}, filterList },
|
|
163
|
+
});
|
|
164
|
+
const item = wrapper.vm.visibleFilterList[0];
|
|
165
|
+
assert.equal(item.labelRender, labelRender);
|
|
166
|
+
assert.equal(item.__events__.labelRender, undefined);
|
|
167
|
+
wrapper.destroy();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("配置 labelRender 时传入 label 插槽", () => {
|
|
171
|
+
const labelRender = () => "自定义 label";
|
|
172
|
+
const filterList = [{ label: "姓名", name: "name", type: "text", labelRender }];
|
|
173
|
+
const wrapper = shallowMount(InflyForm, {
|
|
174
|
+
propsData: { formData: {}, filterList },
|
|
175
|
+
});
|
|
176
|
+
const formItem = wrapper.find("el-form-item-stub");
|
|
177
|
+
// VTU stub 不渲染插槽内容,断言插槽已正确传递
|
|
178
|
+
assert.ok(Array.isArray(formItem.vm.$slots.label) && formItem.vm.$slots.label.length > 0);
|
|
179
|
+
wrapper.destroy();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("labelRender 支持 VNode 对象直传(JSX 元素)", () => {
|
|
183
|
+
const Vue = createLocalVue();
|
|
184
|
+
const vnode = new Vue().$createElement("span", "自定义 label");
|
|
185
|
+
const filterList = [{ label: "姓名", name: "name", type: "text", labelRender: vnode }];
|
|
186
|
+
const wrapper = shallowMount(InflyForm, {
|
|
187
|
+
propsData: { formData: {}, filterList },
|
|
188
|
+
});
|
|
189
|
+
const item = wrapper.vm.visibleFilterList[0];
|
|
190
|
+
assert.equal(item.labelRender, vnode);
|
|
191
|
+
assert.equal(item.__events__.labelRender, undefined);
|
|
192
|
+
wrapper.destroy();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("未配置 labelRender 时渲染 label 文本,无 label 插槽", () => {
|
|
196
|
+
const filterList = [{ label: "姓名", name: "name", type: "text" }];
|
|
197
|
+
const wrapper = shallowMount(InflyForm, {
|
|
198
|
+
propsData: { formData: {}, filterList },
|
|
199
|
+
});
|
|
200
|
+
const formItem = wrapper.find("el-form-item-stub");
|
|
201
|
+
assert.ok(!formItem.vm.$slots.label);
|
|
202
|
+
assert.equal(formItem.props().label, "姓名");
|
|
203
|
+
wrapper.destroy();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("无 name 时使用 prop 作为回退", () => {
|
|
207
|
+
const filterList = [{ label: "姓名", prop: "name", type: "text" }];
|
|
208
|
+
const wrapper = shallowMount(InflyForm, {
|
|
209
|
+
propsData: { formData: {}, filterList },
|
|
210
|
+
});
|
|
211
|
+
assert.equal(wrapper.vm.visibleFilterList[0].name, "name");
|
|
212
|
+
wrapper.destroy();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("自定义空值显示 emptyStr", () => {
|
|
216
|
+
const wrapper = shallowMount(InflyForm, {
|
|
217
|
+
propsData: {
|
|
218
|
+
formData: { name: "" },
|
|
219
|
+
emptyStr: "暂无数据",
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
assert.equal(wrapper.props().emptyStr, "暂无数据");
|
|
223
|
+
wrapper.destroy();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("表单方法", () => {
|
|
228
|
+
it("validate 方法存在", () => {
|
|
229
|
+
const wrapper = shallowMount(InflyForm, {
|
|
230
|
+
propsData: { formData: {} },
|
|
231
|
+
});
|
|
232
|
+
assert.equal(typeof wrapper.vm.validate, "function");
|
|
233
|
+
wrapper.destroy();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("getFormInstance 方法存在", () => {
|
|
237
|
+
const wrapper = shallowMount(InflyForm, {
|
|
238
|
+
propsData: { formData: {}, formRef: "myForm" },
|
|
239
|
+
});
|
|
240
|
+
assert.equal(typeof wrapper.vm.getFormInstance, "function");
|
|
241
|
+
wrapper.destroy();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("clearValidate 方法存在", () => {
|
|
245
|
+
const wrapper = shallowMount(InflyForm, {
|
|
246
|
+
propsData: { formData: {} },
|
|
247
|
+
});
|
|
248
|
+
assert.equal(typeof wrapper.vm.clearValidate, "function");
|
|
249
|
+
wrapper.destroy();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe("编辑模式", () => {
|
|
254
|
+
it("isEdit prop 控制编辑模式", () => {
|
|
255
|
+
const wrapper = shallowMount(InflyForm, {
|
|
256
|
+
propsData: {
|
|
257
|
+
formData: {},
|
|
258
|
+
isEdit: false,
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
assert.equal(wrapper.vm.computedEdit, false);
|
|
262
|
+
wrapper.destroy();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("isEdit=true 时进入编辑模式", () => {
|
|
266
|
+
const wrapper = shallowMount(InflyForm, {
|
|
267
|
+
propsData: {
|
|
268
|
+
formData: {},
|
|
269
|
+
isEdit: true,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
assert.equal(wrapper.vm.computedEdit, true);
|
|
273
|
+
wrapper.destroy();
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("InflyFormRenderCell", () => {
|
|
278
|
+
function getRenderCell() {
|
|
279
|
+
const wrapper = shallowMount(InflyForm, { propsData: { formData: {} } });
|
|
280
|
+
const RenderCell = wrapper.vm.$options.components.InflyFormRenderCell;
|
|
281
|
+
wrapper.destroy();
|
|
282
|
+
return RenderCell;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
it("renderFn 为函数且返回 VNode 时渲染该 VNode", () => {
|
|
286
|
+
const RenderCell = getRenderCell();
|
|
287
|
+
const h = new (createLocalVue())().$createElement;
|
|
288
|
+
const cell = shallowMount(RenderCell, {
|
|
289
|
+
propsData: { renderFn: () => h("b", "加粗文本") },
|
|
290
|
+
});
|
|
291
|
+
assert.ok(cell.find("b").exists());
|
|
292
|
+
assert.equal(cell.text(), "加粗文本");
|
|
293
|
+
cell.destroy();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("renderFn 为 VNode 对象时原样渲染(labelRender JSX 直传)", () => {
|
|
297
|
+
const RenderCell = getRenderCell();
|
|
298
|
+
const h = new (createLocalVue())().$createElement;
|
|
299
|
+
const vnode = h("span", "自定义 label");
|
|
300
|
+
const cell = shallowMount(RenderCell, {
|
|
301
|
+
propsData: { renderFn: vnode },
|
|
302
|
+
});
|
|
303
|
+
assert.ok(cell.find("span").exists());
|
|
304
|
+
assert.equal(cell.text(), "自定义 label");
|
|
305
|
+
cell.destroy();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("renderFn 为函数且返回字符串时包裹 containerTag", () => {
|
|
309
|
+
const RenderCell = getRenderCell();
|
|
310
|
+
const cell = shallowMount(RenderCell, {
|
|
311
|
+
propsData: { renderFn: () => "纯文本", containerTag: "span" },
|
|
312
|
+
});
|
|
313
|
+
assert.ok(cell.find("span").exists());
|
|
314
|
+
assert.equal(cell.text(), "纯文本");
|
|
315
|
+
cell.destroy();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("事件", () => {
|
|
320
|
+
it("resetFormData 触发 reset-form 事件", () => {
|
|
321
|
+
const wrapper = shallowMount(InflyForm, {
|
|
322
|
+
propsData: { formData: { name: "test" } },
|
|
323
|
+
});
|
|
324
|
+
wrapper.vm.resetFormData();
|
|
325
|
+
assert.ok(wrapper.emitted("reset-form"));
|
|
326
|
+
wrapper.destroy();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|