@infly/ui 1.0.30 → 1.0.31
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 +2 -2
- 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
|
@@ -1,281 +1,281 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* InstitutionSelect 组件测试
|
|
3
|
-
*
|
|
4
|
-
* 验证机构选择器的渲染、单选/多选模式、props 和核心方法。
|
|
5
|
-
* 注:完整模态框交互测试需要更复杂的 vuex store + axios mock 基础设施。
|
|
6
|
-
*/
|
|
7
|
-
const { mount, shallowMount } = require("../../../test/helper");
|
|
8
|
-
const InstitutionSelect = require("./InstitutionSelect.vue");
|
|
9
|
-
|
|
10
|
-
describe("InstitutionSelect", () => {
|
|
11
|
-
describe("渲染", () => {
|
|
12
|
-
it("默认渲染选择按钮", () => {
|
|
13
|
-
const wrapper = mount(InstitutionSelect, {
|
|
14
|
-
propsData: { value: "" },
|
|
15
|
-
});
|
|
16
|
-
assert.ok(wrapper.find(".comp-InstitutionSelect").exists());
|
|
17
|
-
assert.ok(wrapper.find(".institutions__btn-select").exists());
|
|
18
|
-
wrapper.destroy();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("渲染提示文字", () => {
|
|
22
|
-
const wrapper = mount(InstitutionSelect, {
|
|
23
|
-
propsData: { value: "" },
|
|
24
|
-
});
|
|
25
|
-
assert.ok(wrapper.find(".text-info").exists());
|
|
26
|
-
wrapper.destroy();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("不渲染已选标签列表(单选模式默认)", () => {
|
|
30
|
-
const wrapper = mount(InstitutionSelect, {
|
|
31
|
-
propsData: { value: "" },
|
|
32
|
-
});
|
|
33
|
-
assert.equal(wrapper.props().showSelectBtn, true);
|
|
34
|
-
assert.ok(wrapper.find(".institutions__btn-select").exists());
|
|
35
|
-
assert.ok(!wrapper.find(".selected-tags-wrap").exists());
|
|
36
|
-
wrapper.destroy();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("Props", () => {
|
|
41
|
-
it("支持自定义 btnText", () => {
|
|
42
|
-
const wrapper = mount(InstitutionSelect, {
|
|
43
|
-
propsData: { value: "", btnText: "选择机构" },
|
|
44
|
-
});
|
|
45
|
-
const btn = wrapper.find(".institutions__btn-select");
|
|
46
|
-
assert.equal(btn.text(), "选择机构");
|
|
47
|
-
wrapper.destroy();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("支持自定义 title", () => {
|
|
51
|
-
const wrapper = mount(InstitutionSelect, {
|
|
52
|
-
propsData: { value: "", title: "自定义标题" },
|
|
53
|
-
});
|
|
54
|
-
assert.equal(wrapper.props().title, "自定义标题");
|
|
55
|
-
wrapper.destroy();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("支持自定义 label", () => {
|
|
59
|
-
const wrapper = mount(InstitutionSelect, {
|
|
60
|
-
propsData: { value: "", label: "自定义标签" },
|
|
61
|
-
});
|
|
62
|
-
assert.equal(wrapper.props().label, "自定义标签");
|
|
63
|
-
wrapper.destroy();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("支持自定义 selectLevelTips", () => {
|
|
67
|
-
const wrapper = mount(InstitutionSelect, {
|
|
68
|
-
propsData: { value: "", selectLevelTips: "请选择机构" },
|
|
69
|
-
});
|
|
70
|
-
assert.equal(wrapper.props().selectLevelTips, "请选择机构");
|
|
71
|
-
wrapper.destroy();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("showSelectBtn=false 时隐藏选择按钮", () => {
|
|
75
|
-
const wrapper = mount(InstitutionSelect, {
|
|
76
|
-
propsData: { value: "", showSelectBtn: false },
|
|
77
|
-
});
|
|
78
|
-
assert.ok(!wrapper.find(".institutions__btn-select").exists());
|
|
79
|
-
wrapper.destroy();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("hideTips=true 时隐藏提示文字", () => {
|
|
83
|
-
const wrapper = mount(InstitutionSelect, {
|
|
84
|
-
propsData: { value: "", hideTips: true },
|
|
85
|
-
});
|
|
86
|
-
assert.ok(!wrapper.find(".text-info").exists());
|
|
87
|
-
wrapper.destroy();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("支持自定义 IdKey", () => {
|
|
91
|
-
const wrapper = mount(InstitutionSelect, {
|
|
92
|
-
propsData: { value: "", IdKey: "orgId" },
|
|
93
|
-
});
|
|
94
|
-
assert.equal(wrapper.props().IdKey, "orgId");
|
|
95
|
-
wrapper.destroy();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("支持 maxSelectCount", () => {
|
|
99
|
-
const wrapper = mount(InstitutionSelect, {
|
|
100
|
-
propsData: { value: [], showTableSelect: true, maxSelectCount: 5 },
|
|
101
|
-
});
|
|
102
|
-
assert.equal(wrapper.props().maxSelectCount, 5);
|
|
103
|
-
wrapper.destroy();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("单选模式", () => {
|
|
108
|
-
it("有值时显示已选机构名称和删除图标", () => {
|
|
109
|
-
const wrapper = mount(InstitutionSelect, {
|
|
110
|
-
propsData: {
|
|
111
|
-
value: "123",
|
|
112
|
-
formData: { level_name: "测试机构" },
|
|
113
|
-
levelNameKey: "level_name",
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
assert.ok(wrapper.find(".btn--delete").exists());
|
|
117
|
-
wrapper.destroy();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("无值时不显示删除图标", () => {
|
|
121
|
-
const wrapper = mount(InstitutionSelect, {
|
|
122
|
-
propsData: { value: "" },
|
|
123
|
-
});
|
|
124
|
-
assert.ok(!wrapper.find(".btn--delete").exists());
|
|
125
|
-
wrapper.destroy();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("点击删除触发 onDelete", async () => {
|
|
129
|
-
const wrapper = mount(InstitutionSelect, {
|
|
130
|
-
propsData: {
|
|
131
|
-
value: "123",
|
|
132
|
-
formData: { level_name: "测试机构" },
|
|
133
|
-
levelNameKey: "level_name",
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
wrapper.vm.onDelete();
|
|
137
|
-
await wrapper.vm.$nextTick();
|
|
138
|
-
assert.ok(wrapper.emitted("input"));
|
|
139
|
-
assert.equal(wrapper.emitted("input")[0][0], "");
|
|
140
|
-
assert.ok(wrapper.emitted("onDelete"));
|
|
141
|
-
wrapper.destroy();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("多选模式", () => {
|
|
146
|
-
it("showTableSelect=true 时显示已选数量提示", () => {
|
|
147
|
-
const wrapper = mount(InstitutionSelect, {
|
|
148
|
-
propsData: { value: [], showTableSelect: true, maxSelectCount: 10 },
|
|
149
|
-
});
|
|
150
|
-
assert.ok(wrapper.text().includes("已选"));
|
|
151
|
-
wrapper.destroy();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("maxSelectCount=0 时不显示数量限制", () => {
|
|
155
|
-
const wrapper = mount(InstitutionSelect, {
|
|
156
|
-
propsData: { value: [], showTableSelect: true, maxSelectCount: 0 },
|
|
157
|
-
});
|
|
158
|
-
// 0 表示不限制,不显示 "已选 X / Y"
|
|
159
|
-
assert.ok(!wrapper.text().includes("/"));
|
|
160
|
-
wrapper.destroy();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("有已选数据时渲染已选标签", () => {
|
|
164
|
-
const wrapper = mount(InstitutionSelect, {
|
|
165
|
-
propsData: {
|
|
166
|
-
value: [{ id: "1", level_name: "机构A" }, { id: "2", level_name: "机构B" }],
|
|
167
|
-
showTableSelect: true,
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
assert.ok(wrapper.find(".selected-tags-wrap").exists());
|
|
171
|
-
wrapper.destroy();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe("核心方法", () => {
|
|
176
|
-
it("levelNameRender 返回最细粒度的名称", () => {
|
|
177
|
-
const wrapper = mount(InstitutionSelect, {
|
|
178
|
-
propsData: { value: "" },
|
|
179
|
-
});
|
|
180
|
-
const row = {
|
|
181
|
-
branch_name: "XX支局",
|
|
182
|
-
district_name: "XX区",
|
|
183
|
-
city_name: "XX市",
|
|
184
|
-
prov_name: "XX省",
|
|
185
|
-
};
|
|
186
|
-
assert.equal(wrapper.vm.levelNameRender(row), "XX支局");
|
|
187
|
-
wrapper.destroy();
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("levelNameRender 降级到上级名称", () => {
|
|
191
|
-
const wrapper = mount(InstitutionSelect, {
|
|
192
|
-
propsData: { value: "" },
|
|
193
|
-
});
|
|
194
|
-
const row = {
|
|
195
|
-
district_name: "XX区",
|
|
196
|
-
city_name: "XX市",
|
|
197
|
-
prov_name: "XX省",
|
|
198
|
-
};
|
|
199
|
-
assert.equal(wrapper.vm.levelNameRender(row), "XX区");
|
|
200
|
-
wrapper.destroy();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("levelNameRender 全部缺失时返回 IdKey 值", () => {
|
|
204
|
-
const wrapper = mount(InstitutionSelect, {
|
|
205
|
-
propsData: { value: "", IdKey: "id" },
|
|
206
|
-
});
|
|
207
|
-
assert.equal(wrapper.vm.levelNameRender({ id: "999" }), "999");
|
|
208
|
-
wrapper.destroy();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("resolveReqUrl 返回默认 URL", () => {
|
|
212
|
-
const wrapper = mount(InstitutionSelect, {
|
|
213
|
-
propsData: { value: "" },
|
|
214
|
-
});
|
|
215
|
-
assert.equal(wrapper.vm.resolveReqUrl(), "/admin/level/");
|
|
216
|
-
wrapper.destroy();
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("resolveReqUrl 支持自定义 reqUrl", () => {
|
|
220
|
-
const wrapper = mount(InstitutionSelect, {
|
|
221
|
-
propsData: { value: "", reqUrl: "/custom/api/" },
|
|
222
|
-
});
|
|
223
|
-
assert.equal(wrapper.vm.resolveReqUrl(), "/custom/api/");
|
|
224
|
-
wrapper.destroy();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("resolveRequest 返回 null(无 axios 注入时)", () => {
|
|
228
|
-
const wrapper = mount(InstitutionSelect, {
|
|
229
|
-
propsData: { value: "" },
|
|
230
|
-
});
|
|
231
|
-
assert.equal(wrapper.vm.resolveRequest(), null);
|
|
232
|
-
wrapper.destroy();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("多选模式渲染已选标签和数量限制", () => {
|
|
236
|
-
const wrapper = shallowMount(InstitutionSelect, {
|
|
237
|
-
propsData: {
|
|
238
|
-
value: [
|
|
239
|
-
{ id: "1", level_name: "机构A" },
|
|
240
|
-
{ id: "2", level_name: "机构B" },
|
|
241
|
-
],
|
|
242
|
-
showTableSelect: true,
|
|
243
|
-
maxSelectCount: 5,
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
assert.equal(wrapper.find(".selected-tags-wrap").exists(), true);
|
|
247
|
-
assert.ok(wrapper.text().includes("已选 2 / 5"));
|
|
248
|
-
wrapper.destroy();
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
describe("核心方法", () => {
|
|
253
|
-
it("levelNameRender 优先返回最细粒度名称并回退到 IdKey", () => {
|
|
254
|
-
const wrapper = shallowMount(InstitutionSelect, {
|
|
255
|
-
propsData: { value: "", IdKey: "id" },
|
|
256
|
-
});
|
|
257
|
-
assert.equal(
|
|
258
|
-
wrapper.vm.levelNameRender({
|
|
259
|
-
branch_name: "XX支局",
|
|
260
|
-
district_name: "XX区",
|
|
261
|
-
city_name: "XX市",
|
|
262
|
-
prov_name: "XX省",
|
|
263
|
-
id: "123",
|
|
264
|
-
}),
|
|
265
|
-
"XX支局",
|
|
266
|
-
);
|
|
267
|
-
assert.equal(wrapper.vm.levelNameRender({ id: "999" }), "999");
|
|
268
|
-
wrapper.destroy();
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("resolveReqUrl 使用默认地址并支持显式覆盖", async () => {
|
|
272
|
-
const wrapper = shallowMount(InstitutionSelect, {
|
|
273
|
-
propsData: { value: "" },
|
|
274
|
-
});
|
|
275
|
-
assert.equal(wrapper.vm.resolveReqUrl(), "/admin/level/");
|
|
276
|
-
await wrapper.setProps({ reqUrl: "/custom/api/" });
|
|
277
|
-
assert.equal(wrapper.vm.resolveReqUrl(), "/custom/api/");
|
|
278
|
-
wrapper.destroy();
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* InstitutionSelect 组件测试
|
|
3
|
+
*
|
|
4
|
+
* 验证机构选择器的渲染、单选/多选模式、props 和核心方法。
|
|
5
|
+
* 注:完整模态框交互测试需要更复杂的 vuex store + axios mock 基础设施。
|
|
6
|
+
*/
|
|
7
|
+
const { mount, shallowMount } = require("../../../test/helper");
|
|
8
|
+
const InstitutionSelect = require("./InstitutionSelect.vue");
|
|
9
|
+
|
|
10
|
+
describe("InstitutionSelect", () => {
|
|
11
|
+
describe("渲染", () => {
|
|
12
|
+
it("默认渲染选择按钮", () => {
|
|
13
|
+
const wrapper = mount(InstitutionSelect, {
|
|
14
|
+
propsData: { value: "" },
|
|
15
|
+
});
|
|
16
|
+
assert.ok(wrapper.find(".comp-InstitutionSelect").exists());
|
|
17
|
+
assert.ok(wrapper.find(".institutions__btn-select").exists());
|
|
18
|
+
wrapper.destroy();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("渲染提示文字", () => {
|
|
22
|
+
const wrapper = mount(InstitutionSelect, {
|
|
23
|
+
propsData: { value: "" },
|
|
24
|
+
});
|
|
25
|
+
assert.ok(wrapper.find(".text-info").exists());
|
|
26
|
+
wrapper.destroy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("不渲染已选标签列表(单选模式默认)", () => {
|
|
30
|
+
const wrapper = mount(InstitutionSelect, {
|
|
31
|
+
propsData: { value: "" },
|
|
32
|
+
});
|
|
33
|
+
assert.equal(wrapper.props().showSelectBtn, true);
|
|
34
|
+
assert.ok(wrapper.find(".institutions__btn-select").exists());
|
|
35
|
+
assert.ok(!wrapper.find(".selected-tags-wrap").exists());
|
|
36
|
+
wrapper.destroy();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("Props", () => {
|
|
41
|
+
it("支持自定义 btnText", () => {
|
|
42
|
+
const wrapper = mount(InstitutionSelect, {
|
|
43
|
+
propsData: { value: "", btnText: "选择机构" },
|
|
44
|
+
});
|
|
45
|
+
const btn = wrapper.find(".institutions__btn-select");
|
|
46
|
+
assert.equal(btn.text(), "选择机构");
|
|
47
|
+
wrapper.destroy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("支持自定义 title", () => {
|
|
51
|
+
const wrapper = mount(InstitutionSelect, {
|
|
52
|
+
propsData: { value: "", title: "自定义标题" },
|
|
53
|
+
});
|
|
54
|
+
assert.equal(wrapper.props().title, "自定义标题");
|
|
55
|
+
wrapper.destroy();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("支持自定义 label", () => {
|
|
59
|
+
const wrapper = mount(InstitutionSelect, {
|
|
60
|
+
propsData: { value: "", label: "自定义标签" },
|
|
61
|
+
});
|
|
62
|
+
assert.equal(wrapper.props().label, "自定义标签");
|
|
63
|
+
wrapper.destroy();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("支持自定义 selectLevelTips", () => {
|
|
67
|
+
const wrapper = mount(InstitutionSelect, {
|
|
68
|
+
propsData: { value: "", selectLevelTips: "请选择机构" },
|
|
69
|
+
});
|
|
70
|
+
assert.equal(wrapper.props().selectLevelTips, "请选择机构");
|
|
71
|
+
wrapper.destroy();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("showSelectBtn=false 时隐藏选择按钮", () => {
|
|
75
|
+
const wrapper = mount(InstitutionSelect, {
|
|
76
|
+
propsData: { value: "", showSelectBtn: false },
|
|
77
|
+
});
|
|
78
|
+
assert.ok(!wrapper.find(".institutions__btn-select").exists());
|
|
79
|
+
wrapper.destroy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("hideTips=true 时隐藏提示文字", () => {
|
|
83
|
+
const wrapper = mount(InstitutionSelect, {
|
|
84
|
+
propsData: { value: "", hideTips: true },
|
|
85
|
+
});
|
|
86
|
+
assert.ok(!wrapper.find(".text-info").exists());
|
|
87
|
+
wrapper.destroy();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("支持自定义 IdKey", () => {
|
|
91
|
+
const wrapper = mount(InstitutionSelect, {
|
|
92
|
+
propsData: { value: "", IdKey: "orgId" },
|
|
93
|
+
});
|
|
94
|
+
assert.equal(wrapper.props().IdKey, "orgId");
|
|
95
|
+
wrapper.destroy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("支持 maxSelectCount", () => {
|
|
99
|
+
const wrapper = mount(InstitutionSelect, {
|
|
100
|
+
propsData: { value: [], showTableSelect: true, maxSelectCount: 5 },
|
|
101
|
+
});
|
|
102
|
+
assert.equal(wrapper.props().maxSelectCount, 5);
|
|
103
|
+
wrapper.destroy();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("单选模式", () => {
|
|
108
|
+
it("有值时显示已选机构名称和删除图标", () => {
|
|
109
|
+
const wrapper = mount(InstitutionSelect, {
|
|
110
|
+
propsData: {
|
|
111
|
+
value: "123",
|
|
112
|
+
formData: { level_name: "测试机构" },
|
|
113
|
+
levelNameKey: "level_name",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
assert.ok(wrapper.find(".btn--delete").exists());
|
|
117
|
+
wrapper.destroy();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("无值时不显示删除图标", () => {
|
|
121
|
+
const wrapper = mount(InstitutionSelect, {
|
|
122
|
+
propsData: { value: "" },
|
|
123
|
+
});
|
|
124
|
+
assert.ok(!wrapper.find(".btn--delete").exists());
|
|
125
|
+
wrapper.destroy();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("点击删除触发 onDelete", async () => {
|
|
129
|
+
const wrapper = mount(InstitutionSelect, {
|
|
130
|
+
propsData: {
|
|
131
|
+
value: "123",
|
|
132
|
+
formData: { level_name: "测试机构" },
|
|
133
|
+
levelNameKey: "level_name",
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
wrapper.vm.onDelete();
|
|
137
|
+
await wrapper.vm.$nextTick();
|
|
138
|
+
assert.ok(wrapper.emitted("input"));
|
|
139
|
+
assert.equal(wrapper.emitted("input")[0][0], "");
|
|
140
|
+
assert.ok(wrapper.emitted("onDelete"));
|
|
141
|
+
wrapper.destroy();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("多选模式", () => {
|
|
146
|
+
it("showTableSelect=true 时显示已选数量提示", () => {
|
|
147
|
+
const wrapper = mount(InstitutionSelect, {
|
|
148
|
+
propsData: { value: [], showTableSelect: true, maxSelectCount: 10 },
|
|
149
|
+
});
|
|
150
|
+
assert.ok(wrapper.text().includes("已选"));
|
|
151
|
+
wrapper.destroy();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("maxSelectCount=0 时不显示数量限制", () => {
|
|
155
|
+
const wrapper = mount(InstitutionSelect, {
|
|
156
|
+
propsData: { value: [], showTableSelect: true, maxSelectCount: 0 },
|
|
157
|
+
});
|
|
158
|
+
// 0 表示不限制,不显示 "已选 X / Y"
|
|
159
|
+
assert.ok(!wrapper.text().includes("/"));
|
|
160
|
+
wrapper.destroy();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("有已选数据时渲染已选标签", () => {
|
|
164
|
+
const wrapper = mount(InstitutionSelect, {
|
|
165
|
+
propsData: {
|
|
166
|
+
value: [{ id: "1", level_name: "机构A" }, { id: "2", level_name: "机构B" }],
|
|
167
|
+
showTableSelect: true,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
assert.ok(wrapper.find(".selected-tags-wrap").exists());
|
|
171
|
+
wrapper.destroy();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("核心方法", () => {
|
|
176
|
+
it("levelNameRender 返回最细粒度的名称", () => {
|
|
177
|
+
const wrapper = mount(InstitutionSelect, {
|
|
178
|
+
propsData: { value: "" },
|
|
179
|
+
});
|
|
180
|
+
const row = {
|
|
181
|
+
branch_name: "XX支局",
|
|
182
|
+
district_name: "XX区",
|
|
183
|
+
city_name: "XX市",
|
|
184
|
+
prov_name: "XX省",
|
|
185
|
+
};
|
|
186
|
+
assert.equal(wrapper.vm.levelNameRender(row), "XX支局");
|
|
187
|
+
wrapper.destroy();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("levelNameRender 降级到上级名称", () => {
|
|
191
|
+
const wrapper = mount(InstitutionSelect, {
|
|
192
|
+
propsData: { value: "" },
|
|
193
|
+
});
|
|
194
|
+
const row = {
|
|
195
|
+
district_name: "XX区",
|
|
196
|
+
city_name: "XX市",
|
|
197
|
+
prov_name: "XX省",
|
|
198
|
+
};
|
|
199
|
+
assert.equal(wrapper.vm.levelNameRender(row), "XX区");
|
|
200
|
+
wrapper.destroy();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("levelNameRender 全部缺失时返回 IdKey 值", () => {
|
|
204
|
+
const wrapper = mount(InstitutionSelect, {
|
|
205
|
+
propsData: { value: "", IdKey: "id" },
|
|
206
|
+
});
|
|
207
|
+
assert.equal(wrapper.vm.levelNameRender({ id: "999" }), "999");
|
|
208
|
+
wrapper.destroy();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("resolveReqUrl 返回默认 URL", () => {
|
|
212
|
+
const wrapper = mount(InstitutionSelect, {
|
|
213
|
+
propsData: { value: "" },
|
|
214
|
+
});
|
|
215
|
+
assert.equal(wrapper.vm.resolveReqUrl(), "/admin/level/");
|
|
216
|
+
wrapper.destroy();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("resolveReqUrl 支持自定义 reqUrl", () => {
|
|
220
|
+
const wrapper = mount(InstitutionSelect, {
|
|
221
|
+
propsData: { value: "", reqUrl: "/custom/api/" },
|
|
222
|
+
});
|
|
223
|
+
assert.equal(wrapper.vm.resolveReqUrl(), "/custom/api/");
|
|
224
|
+
wrapper.destroy();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("resolveRequest 返回 null(无 axios 注入时)", () => {
|
|
228
|
+
const wrapper = mount(InstitutionSelect, {
|
|
229
|
+
propsData: { value: "" },
|
|
230
|
+
});
|
|
231
|
+
assert.equal(wrapper.vm.resolveRequest(), null);
|
|
232
|
+
wrapper.destroy();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("多选模式渲染已选标签和数量限制", () => {
|
|
236
|
+
const wrapper = shallowMount(InstitutionSelect, {
|
|
237
|
+
propsData: {
|
|
238
|
+
value: [
|
|
239
|
+
{ id: "1", level_name: "机构A" },
|
|
240
|
+
{ id: "2", level_name: "机构B" },
|
|
241
|
+
],
|
|
242
|
+
showTableSelect: true,
|
|
243
|
+
maxSelectCount: 5,
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
assert.equal(wrapper.find(".selected-tags-wrap").exists(), true);
|
|
247
|
+
assert.ok(wrapper.text().includes("已选 2 / 5"));
|
|
248
|
+
wrapper.destroy();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe("核心方法", () => {
|
|
253
|
+
it("levelNameRender 优先返回最细粒度名称并回退到 IdKey", () => {
|
|
254
|
+
const wrapper = shallowMount(InstitutionSelect, {
|
|
255
|
+
propsData: { value: "", IdKey: "id" },
|
|
256
|
+
});
|
|
257
|
+
assert.equal(
|
|
258
|
+
wrapper.vm.levelNameRender({
|
|
259
|
+
branch_name: "XX支局",
|
|
260
|
+
district_name: "XX区",
|
|
261
|
+
city_name: "XX市",
|
|
262
|
+
prov_name: "XX省",
|
|
263
|
+
id: "123",
|
|
264
|
+
}),
|
|
265
|
+
"XX支局",
|
|
266
|
+
);
|
|
267
|
+
assert.equal(wrapper.vm.levelNameRender({ id: "999" }), "999");
|
|
268
|
+
wrapper.destroy();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("resolveReqUrl 使用默认地址并支持显式覆盖", async () => {
|
|
272
|
+
const wrapper = shallowMount(InstitutionSelect, {
|
|
273
|
+
propsData: { value: "" },
|
|
274
|
+
});
|
|
275
|
+
assert.equal(wrapper.vm.resolveReqUrl(), "/admin/level/");
|
|
276
|
+
await wrapper.setProps({ reqUrl: "/custom/api/" });
|
|
277
|
+
assert.equal(wrapper.vm.resolveReqUrl(), "/custom/api/");
|
|
278
|
+
wrapper.destroy();
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|