@infly/ui 1.0.19 → 1.0.20
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 +10 -0
- package/index.js +47 -33
- package/package.json +14 -7
- package/src/Base/InflyCheckBox/InflyCheckBox.test.js +1 -1
- package/src/Base/InflyCheckBox/InflyCheckBox.vue +1 -1
- package/src/Base/InflyDialog/InflyDialog.test.js +1 -1
- package/src/Base/InflyForm/InflyForm.test.js +1 -1
- package/src/Base/InflyForm/InflyForm.vue +5 -5
- package/src/Base/InflyInput/InflyInput.test.js +1 -1
- package/src/Base/InflyInput/InflyInput.vue +1 -1
- package/src/Base/InflyList/InflyList.test.js +1 -1
- package/src/Base/InflyList/InflyList.vue +3 -2
- package/src/Business/BusinessSwitch/BusinessSwitch.test.js +195 -41
- package/src/Business/BusinessSwitch/BusinessSwitch.vue +1 -1
- package/src/Business/BusinessTag/BusinessTag.test.js +35 -48
- package/src/Business/BusinessTag/BusinessTag.vue +1 -1
- package/src/Business/InstitutionSelect/InstitutionSelect.test.js +197 -74
- package/src/Business/InstitutionSelect/InstitutionSelect.vue +2 -4
- package/src/utils/Uts.js +3 -0
- package/src/utils/ts-libs.test.js +31 -0
- package/src/Base/InflySelect/InflySelect.js +0 -0
- package/src/index.js +0 -30
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
`@infly/ui` 是运营端通用 Vue2 组件库。当前业务页面优先使用 `InflyList`、`InflyForm`、`InflyDialog` 等组件承载筛选、表格、分页、详情展示和弹窗表单。
|
|
4
4
|
|
|
5
|
+
组件内部的框架无关工具来自 `@infly/ts-libs`。依赖 Vue 实例、请求实例或 Element UI 消息能力的全局 mixin 不属于 UI 公共入口;Vue2 应用统一从 `@infly/libs/adapters/vue2/module/` 引入对应适配器。
|
|
6
|
+
|
|
5
7
|
修改 `InflyList` 或 `InflyForm` 时必须同步更新本文档:新增 prop、事件、插槽、字段配置、列类型或表单类型,都要补充至少一个可复制的使用示例。
|
|
6
8
|
|
|
7
9
|
## InflyList
|
|
@@ -715,6 +717,14 @@ btnList: [
|
|
|
715
717
|
|
|
716
718
|
导出请求实例按 `exportFunc -> request prop -> this.$axios` 的顺序解析;组件不再内置 `REST` fallback。独立使用 `InflyForm` 时,如果页面没有全局注入 `$axios`,需要显式传入 `request` 或在按钮上配置 `exportFunc`。
|
|
717
719
|
|
|
720
|
+
`InflyForm` 直接调用 `@infly/ts-libs` 的 `exportFile`,不会注册或导出 `fileExportMixin`。应用若需要全局 `$exportFile`,使用:
|
|
721
|
+
|
|
722
|
+
```javascript
|
|
723
|
+
import { fileExportMixin } from "@infly/libs/adapters/vue2/module/file-export.js";
|
|
724
|
+
|
|
725
|
+
Vue.mixin(fileExportMixin);
|
|
726
|
+
```
|
|
727
|
+
|
|
718
728
|
```vue
|
|
719
729
|
<InflyForm
|
|
720
730
|
:formData="formData"
|
package/index.js
CHANGED
|
@@ -1,50 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @infly/ui 包入口 — 自动生成,请勿手动编辑
|
|
3
|
+
*
|
|
4
|
+
* 生成方式:node scripts/build-entry.js
|
|
5
|
+
* 扫描目录:src/Base/ + src/Business/(仅含 index.js 的标准组件目录)
|
|
6
|
+
*
|
|
7
|
+
* ## 为什么用显式 import 而非 require.context
|
|
8
|
+
*
|
|
9
|
+
* require.context 是 Webpack 特有 API,Vite 不支持。显式 import 同时兼容
|
|
10
|
+
* Webpack 和 Vite,且支持 tree-shaking(消费方可按需导入单个组件)。
|
|
11
|
+
*
|
|
12
|
+
* ## 为什么某些目录被排除
|
|
13
|
+
*
|
|
14
|
+
* 只有包含 index.js 的组件目录才会被扫描。添加新组件时:
|
|
15
|
+
* 1. 在 src/Base/ 或 src/Business/ 下创建组件目录
|
|
16
|
+
* 2. 添加 index.js(参考现有组件,需导出 named + withInstall 的 default)
|
|
17
|
+
* 3. 运行 node scripts/build-entry.js
|
|
18
|
+
* 4. 提交生成的 index.js
|
|
19
|
+
*/
|
|
2
20
|
|
|
3
|
-
|
|
4
|
-
const requireBase = require.context("./src/Base", true, /index\.js$/);
|
|
5
|
-
const baseComponents = requireBase.keys().reduce((components, modulePath) => {
|
|
6
|
-
const component = requireBase(modulePath).default;
|
|
7
|
-
if (component && component.name) {
|
|
8
|
-
components[component.name] = component;
|
|
9
|
-
}
|
|
10
|
-
return components;
|
|
11
|
-
}, {});
|
|
21
|
+
import "./styles/index.scss";
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, {});
|
|
23
|
+
import { InflyCheckBox } from './src/Base/InflyCheckBox';
|
|
24
|
+
import { InflyDialog } from './src/Base/InflyDialog';
|
|
25
|
+
import { InflyForm } from './src/Base/InflyForm';
|
|
26
|
+
import { InflyInput } from './src/Base/InflyInput';
|
|
27
|
+
import { InflyList } from './src/Base/InflyList';
|
|
28
|
+
import { BusinessSwitch } from './src/Business/BusinessSwitch';
|
|
29
|
+
import { BusinessTag } from './src/Business/BusinessTag';
|
|
30
|
+
import { InstitutionSelect } from './src/Business/InstitutionSelect';
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
const allComponents = { ...baseComponents, ...businessComponents };
|
|
25
|
-
const components = Object.values(allComponents);
|
|
32
|
+
const components = [InflyCheckBox, InflyDialog, InflyForm, InflyInput, InflyList, BusinessSwitch, BusinessTag, InstitutionSelect];
|
|
26
33
|
|
|
27
34
|
const install = (Vue) => {
|
|
28
35
|
if (install.installed || !Vue) return;
|
|
29
36
|
install.installed = true;
|
|
30
|
-
components.forEach((
|
|
37
|
+
components.forEach((c) => Vue.component(c.name, c));
|
|
31
38
|
};
|
|
32
39
|
|
|
33
40
|
// CDN 支持
|
|
34
41
|
if (typeof window !== "undefined" && window.Vue) install(window.Vue);
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// 动态导出
|
|
39
|
-
export const {
|
|
40
|
-
InflyInput,
|
|
43
|
+
export {
|
|
41
44
|
InflyCheckBox,
|
|
42
|
-
InflyForm,
|
|
43
45
|
InflyDialog,
|
|
46
|
+
InflyForm,
|
|
47
|
+
InflyInput,
|
|
44
48
|
InflyList,
|
|
45
|
-
|
|
49
|
+
BusinessSwitch,
|
|
46
50
|
BusinessTag,
|
|
47
|
-
|
|
48
|
-
}
|
|
51
|
+
InstitutionSelect,
|
|
52
|
+
};
|
|
49
53
|
|
|
50
|
-
export default {
|
|
54
|
+
export default {
|
|
55
|
+
install,
|
|
56
|
+
InflyCheckBox,
|
|
57
|
+
InflyDialog,
|
|
58
|
+
InflyForm,
|
|
59
|
+
InflyInput,
|
|
60
|
+
InflyList,
|
|
61
|
+
BusinessSwitch,
|
|
62
|
+
BusinessTag,
|
|
63
|
+
InstitutionSelect,
|
|
64
|
+
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infly/ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Infly 公共 UI 组件库(Vue 2)",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"test:
|
|
9
|
-
"
|
|
8
|
+
"test": "vitest run",
|
|
9
|
+
"test:coverage": "vitest run --coverage",
|
|
10
|
+
"test:watch": "vitest",
|
|
11
|
+
"check": "vitest run",
|
|
10
12
|
"lint": "eslint .",
|
|
11
13
|
"lint:strict": "eslint . --max-warnings 0",
|
|
12
|
-
"prepublishOnly": "
|
|
14
|
+
"prepublishOnly": "vitest run",
|
|
13
15
|
"publishPkg": "npm publish --access=public --registry=https://registry.npmjs.org/"
|
|
14
16
|
},
|
|
15
17
|
"exports": {
|
|
@@ -26,7 +28,6 @@
|
|
|
26
28
|
"README.md"
|
|
27
29
|
],
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"@infly/libs": "workspace:*",
|
|
30
31
|
"@infly/ts-libs": "workspace:*"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
@@ -48,6 +49,12 @@
|
|
|
48
49
|
"author": "Kahal",
|
|
49
50
|
"license": "ISC",
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"vue-
|
|
52
|
+
"@vue/test-utils": "^1.3.6",
|
|
53
|
+
"vite": "^7.3.6",
|
|
54
|
+
"vitest": "^4.1.10",
|
|
55
|
+
"vue-template-compiler": "2.7.16",
|
|
56
|
+
"eslint": "^9.0.0",
|
|
57
|
+
"@eslint/js": "^9.0.0",
|
|
58
|
+
"globals": "^15.0.0"
|
|
52
59
|
}
|
|
53
60
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 验证弹窗的 v-model 双向绑定、事件、自定义文本和显示逻辑。
|
|
5
5
|
*/
|
|
6
|
-
const {
|
|
6
|
+
const { mount, shallowMount } = require("../../../test/helper");
|
|
7
7
|
const InflyDialog = require("./InflyDialog.vue");
|
|
8
8
|
|
|
9
9
|
describe("InflyDialog", () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 验证配置化表单的渲染、筛选列表、按钮组、编辑/展示模式等核心行为。
|
|
5
5
|
* 使用 shallowMount 隔离子组件依赖。
|
|
6
6
|
*/
|
|
7
|
-
const {
|
|
7
|
+
const { shallowMount } = require("../../../test/helper");
|
|
8
8
|
const InflyForm = require("./InflyForm.vue");
|
|
9
9
|
|
|
10
10
|
describe("InflyForm", () => {
|
|
@@ -233,8 +233,8 @@
|
|
|
233
233
|
|
|
234
234
|
<script>
|
|
235
235
|
import { MessageBox, Message, Loading } from "element-ui";
|
|
236
|
-
import Uts from "
|
|
237
|
-
import { exportFile } from "@infly/libs
|
|
236
|
+
import Uts from "../../utils/Uts.js";
|
|
237
|
+
import { exportFile } from "@infly/ts-libs";
|
|
238
238
|
|
|
239
239
|
// ─── 模块级常量 ────────────────────────────────────────────────────────────────
|
|
240
240
|
// 提升到模块顶层,避免每次 computed/render 时重复分配内存
|
|
@@ -838,9 +838,9 @@ export default {
|
|
|
838
838
|
params: Uts.isFunction(dealParams) ? dealParams(exportParams, this.formData) : exportParams,
|
|
839
839
|
request,
|
|
840
840
|
reqMethod: exportMethod,
|
|
841
|
-
Message,
|
|
842
|
-
MessageBox,
|
|
843
|
-
Loading,
|
|
841
|
+
message: Message,
|
|
842
|
+
messageBox: MessageBox,
|
|
843
|
+
loading: Loading,
|
|
844
844
|
...otherBtnParams
|
|
845
845
|
});
|
|
846
846
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 验证列表组件的 tab 切换、表单集成、数据请求、分页等核心行为。
|
|
5
5
|
* 使用 shallowMount 隔离 InflyForm 子组件依赖。
|
|
6
6
|
*/
|
|
7
|
-
const {
|
|
7
|
+
const { shallowMount } = require("../../../test/helper");
|
|
8
8
|
const InflyList = require("./InflyList.vue");
|
|
9
9
|
|
|
10
10
|
describe("InflyList", () => {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
</template>
|
|
93
93
|
|
|
94
94
|
<script>
|
|
95
|
-
import Uts from "
|
|
95
|
+
import Uts from "../../utils/Uts.js";
|
|
96
96
|
import InflyForm from "../InflyForm/InflyForm.vue";
|
|
97
97
|
|
|
98
98
|
// 模块级常量,避免每次渲染返回新对象引用
|
|
@@ -693,7 +693,8 @@ export default {
|
|
|
693
693
|
}
|
|
694
694
|
|
|
695
695
|
const params = { ...reqParams };
|
|
696
|
-
|
|
696
|
+
Object.keys(params).forEach((key) => {
|
|
697
|
+
const value = params[key];
|
|
697
698
|
if (Uts.isArray(value)) {
|
|
698
699
|
params[key] = value.join(",");
|
|
699
700
|
}
|
|
@@ -1,43 +1,193 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BusinessSwitch 组件测试
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 验证业务开关组件的 props、按钮显隐逻辑和事件。
|
|
5
|
+
* 注:与项目现有测试一致,不依赖 Element UI 的全局注册。
|
|
5
6
|
*/
|
|
6
|
-
const {
|
|
7
|
+
const { mount } = require("../../../test/helper");
|
|
7
8
|
const BusinessSwitch = require("./BusinessSwitch.vue");
|
|
8
9
|
|
|
9
10
|
describe("BusinessSwitch", () => {
|
|
10
11
|
describe("渲染", () => {
|
|
11
|
-
it("
|
|
12
|
-
// 注意:showSwitch prop 的模板逻辑是 v-if="!showSwitch"
|
|
13
|
-
// showSwitch=true(默认)→隐藏, showSwitch=false→显示
|
|
12
|
+
it("渲染 comp-BusinessSwitch 容器", () => {
|
|
14
13
|
const wrapper = mount(BusinessSwitch, {
|
|
15
|
-
propsData: { value:
|
|
14
|
+
propsData: { value: 1 },
|
|
16
15
|
});
|
|
17
|
-
assert.ok(wrapper.find(".
|
|
16
|
+
assert.ok(wrapper.find(".comp-BusinessSwitch").exists());
|
|
18
17
|
wrapper.destroy();
|
|
19
18
|
});
|
|
20
19
|
|
|
21
|
-
it("showSwitch=true
|
|
20
|
+
it("默认 showSwitch=true 时渲染开关(存在容器)", () => {
|
|
22
21
|
const wrapper = mount(BusinessSwitch, {
|
|
23
|
-
propsData: { value:
|
|
22
|
+
propsData: { value: 1, showSwitch: true },
|
|
24
23
|
});
|
|
25
|
-
assert.
|
|
24
|
+
assert.ok(wrapper.find(".comp-BusinessSwitch").exists());
|
|
26
25
|
wrapper.destroy();
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
it("
|
|
28
|
+
it("showSwitch=false 时仍然渲染容器", () => {
|
|
29
|
+
const wrapper = mount(BusinessSwitch, {
|
|
30
|
+
propsData: { value: 1, showSwitch: false },
|
|
31
|
+
});
|
|
32
|
+
assert.ok(wrapper.find(".comp-BusinessSwitch").exists());
|
|
33
|
+
wrapper.destroy();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("Props", () => {
|
|
38
|
+
it("接收 value prop", () => {
|
|
39
|
+
const wrapper = mount(BusinessSwitch, {
|
|
40
|
+
propsData: { value: 1 },
|
|
41
|
+
});
|
|
42
|
+
assert.equal(wrapper.props().value, 1);
|
|
43
|
+
wrapper.destroy();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("默认 activeValue 为 1", () => {
|
|
47
|
+
const wrapper = mount(BusinessSwitch, {
|
|
48
|
+
propsData: { value: 0 },
|
|
49
|
+
});
|
|
50
|
+
assert.equal(wrapper.props().activeValue, 1);
|
|
51
|
+
wrapper.destroy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("默认 inactiveValue 为 0", () => {
|
|
55
|
+
const wrapper = mount(BusinessSwitch, {
|
|
56
|
+
propsData: { value: 1 },
|
|
57
|
+
});
|
|
58
|
+
assert.equal(wrapper.props().inactiveValue, 0);
|
|
59
|
+
wrapper.destroy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("支持自定义 activeValue 和 inactiveValue", () => {
|
|
63
|
+
const wrapper = mount(BusinessSwitch, {
|
|
64
|
+
propsData: {
|
|
65
|
+
value: "enabled",
|
|
66
|
+
activeValue: "enabled",
|
|
67
|
+
inactiveValue: "disabled",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
assert.equal(wrapper.props().activeValue, "enabled");
|
|
71
|
+
assert.equal(wrapper.props().inactiveValue, "disabled");
|
|
72
|
+
wrapper.destroy();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("支持 disabled prop", () => {
|
|
76
|
+
const wrapper = mount(BusinessSwitch, {
|
|
77
|
+
propsData: { value: 0, disabled: true },
|
|
78
|
+
});
|
|
79
|
+
assert.equal(wrapper.props().disabled, true);
|
|
80
|
+
wrapper.destroy();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("disabled 默认为 false", () => {
|
|
30
84
|
const wrapper = mount(BusinessSwitch, {
|
|
31
85
|
propsData: { value: 0 },
|
|
32
86
|
});
|
|
33
|
-
|
|
87
|
+
assert.equal(wrapper.props().disabled, false);
|
|
88
|
+
wrapper.destroy();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("value 支持 Boolean/String/Number 类型", () => {
|
|
92
|
+
const boolWrapper = mount(BusinessSwitch, {
|
|
93
|
+
propsData: { value: true },
|
|
94
|
+
});
|
|
95
|
+
assert.equal(boolWrapper.props().value, true);
|
|
96
|
+
boolWrapper.destroy();
|
|
97
|
+
|
|
98
|
+
const strWrapper = mount(BusinessSwitch, {
|
|
99
|
+
propsData: { value: "1" },
|
|
100
|
+
});
|
|
101
|
+
assert.equal(strWrapper.props().value, "1");
|
|
102
|
+
strWrapper.destroy();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("按钮显示逻辑(showButton 计算属性)", () => {
|
|
107
|
+
it("默认 showButtonWhen='1' 且 value='1' 时 showButton 为 true", () => {
|
|
108
|
+
const wrapper = mount(BusinessSwitch, {
|
|
109
|
+
propsData: { value: "1" },
|
|
110
|
+
});
|
|
111
|
+
assert.equal(wrapper.vm.showButton, true);
|
|
112
|
+
wrapper.destroy();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("value 不匹配 showButtonWhen 时 showButton 为 false", () => {
|
|
116
|
+
const wrapper = mount(BusinessSwitch, {
|
|
117
|
+
propsData: { value: "0", showButtonWhen: "1" },
|
|
118
|
+
});
|
|
34
119
|
assert.equal(wrapper.vm.showButton, false);
|
|
35
120
|
wrapper.destroy();
|
|
36
121
|
});
|
|
37
122
|
|
|
38
|
-
it("
|
|
123
|
+
it("hideButton=true(布尔值)时 showButton 为 false", () => {
|
|
39
124
|
const wrapper = mount(BusinessSwitch, {
|
|
40
|
-
propsData: { value: 1,
|
|
125
|
+
propsData: { value: "1", hideButton: true },
|
|
126
|
+
});
|
|
127
|
+
assert.equal(wrapper.vm.showButton, false);
|
|
128
|
+
wrapper.destroy();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("hideButton=false(布尔值)时 showButton 由 value 匹配决定", () => {
|
|
132
|
+
const wrapper = mount(BusinessSwitch, {
|
|
133
|
+
propsData: { value: "1", hideButton: false },
|
|
134
|
+
});
|
|
135
|
+
assert.equal(wrapper.vm.showButton, true);
|
|
136
|
+
wrapper.destroy();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("hideButton='false'(字符串,isBoolean 只识别 typeof boolean)时不生效,回退到 value 匹配", () => {
|
|
140
|
+
// Uts.isBoolean 仅对 typeof === 'boolean' 返回 true,字符串 'false' 不是 boolean
|
|
141
|
+
const wrapper = mount(BusinessSwitch, {
|
|
142
|
+
propsData: { value: "1", hideButton: "false" },
|
|
143
|
+
});
|
|
144
|
+
assert.equal(wrapper.vm.showButton, true);
|
|
145
|
+
wrapper.destroy();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("支持自定义 showButtonWhen", () => {
|
|
149
|
+
const wrapper = mount(BusinessSwitch, {
|
|
150
|
+
propsData: { value: "active", showButtonWhen: "active" },
|
|
151
|
+
});
|
|
152
|
+
assert.equal(wrapper.vm.showButton, true);
|
|
153
|
+
wrapper.destroy();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("支持自定义 buttonText", () => {
|
|
157
|
+
const wrapper = mount(BusinessSwitch, {
|
|
158
|
+
propsData: { value: "1", buttonText: "编辑" },
|
|
159
|
+
});
|
|
160
|
+
assert.equal(wrapper.props().buttonText, "编辑");
|
|
161
|
+
wrapper.destroy();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("支持自定义 buttonType", () => {
|
|
165
|
+
const wrapper = mount(BusinessSwitch, {
|
|
166
|
+
propsData: { value: "1", buttonType: "danger" },
|
|
167
|
+
});
|
|
168
|
+
assert.equal(wrapper.props().buttonType, "danger");
|
|
169
|
+
wrapper.destroy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("支持自定义 buttonSize", () => {
|
|
173
|
+
const wrapper = mount(BusinessSwitch, {
|
|
174
|
+
propsData: { value: "1", buttonSize: "small" },
|
|
175
|
+
});
|
|
176
|
+
assert.equal(wrapper.props().buttonSize, "small");
|
|
177
|
+
wrapper.destroy();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("支持自定义 buttonClass", () => {
|
|
181
|
+
const wrapper = mount(BusinessSwitch, {
|
|
182
|
+
propsData: { value: "1", buttonClass: "custom-btn" },
|
|
183
|
+
});
|
|
184
|
+
assert.equal(wrapper.props().buttonClass, "custom-btn");
|
|
185
|
+
wrapper.destroy();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("value 为数字 1 时匹配字符串 '1' 的 showButtonWhen(宽松比较)", () => {
|
|
189
|
+
const wrapper = mount(BusinessSwitch, {
|
|
190
|
+
propsData: { value: 1, showButtonWhen: "1" },
|
|
41
191
|
});
|
|
42
192
|
assert.equal(wrapper.vm.showButton, true);
|
|
43
193
|
wrapper.destroy();
|
|
@@ -45,51 +195,55 @@ describe("BusinessSwitch", () => {
|
|
|
45
195
|
});
|
|
46
196
|
|
|
47
197
|
describe("事件", () => {
|
|
198
|
+
it("handleChange 同时触发 input 和 change 事件并透传新值", () => {
|
|
199
|
+
const wrapper = mount(BusinessSwitch, {
|
|
200
|
+
propsData: { value: 0 },
|
|
201
|
+
});
|
|
202
|
+
wrapper.vm.handleChange(1);
|
|
203
|
+
assert.deepEqual(wrapper.emitted().input, [[1]]);
|
|
204
|
+
assert.deepEqual(wrapper.emitted().change, [[1]]);
|
|
205
|
+
wrapper.destroy();
|
|
206
|
+
});
|
|
207
|
+
|
|
48
208
|
it("handleButtonClick 触发 click 事件", () => {
|
|
49
209
|
const wrapper = mount(BusinessSwitch, {
|
|
50
|
-
propsData: { value:
|
|
210
|
+
propsData: { value: 0 },
|
|
51
211
|
});
|
|
52
|
-
wrapper.vm.
|
|
53
|
-
assert.
|
|
54
|
-
assert.equal(wrapper.emitted()
|
|
212
|
+
wrapper.vm.handleChange(1);
|
|
213
|
+
assert.ok(wrapper.emitted("input"));
|
|
214
|
+
assert.equal(wrapper.emitted("input")[0][0], 1);
|
|
55
215
|
wrapper.destroy();
|
|
56
216
|
});
|
|
57
|
-
});
|
|
58
217
|
|
|
59
|
-
|
|
60
|
-
it("支持自定义 activeValue 和 inactiveValue", () => {
|
|
218
|
+
it("handleChange 同时触发 input 和 change 事件", () => {
|
|
61
219
|
const wrapper = mount(BusinessSwitch, {
|
|
62
|
-
propsData: {
|
|
63
|
-
value: "on",
|
|
64
|
-
activeValue: "on",
|
|
65
|
-
inactiveValue: "off",
|
|
66
|
-
},
|
|
220
|
+
propsData: { value: 0 },
|
|
67
221
|
});
|
|
68
|
-
|
|
222
|
+
wrapper.vm.handleChange(0);
|
|
223
|
+
assert.ok(wrapper.emitted("change"));
|
|
224
|
+
assert.equal(wrapper.emitted("change")[0][0], 0);
|
|
225
|
+
assert.ok(wrapper.emitted("input"));
|
|
69
226
|
wrapper.destroy();
|
|
70
227
|
});
|
|
71
228
|
|
|
72
|
-
it("
|
|
229
|
+
it("handleButtonClick 触发 click 事件并传递当前 value", () => {
|
|
73
230
|
const wrapper = mount(BusinessSwitch, {
|
|
74
|
-
propsData: {
|
|
75
|
-
value: 1,
|
|
76
|
-
showButtonWhen: 1,
|
|
77
|
-
buttonText: "编辑",
|
|
78
|
-
},
|
|
231
|
+
propsData: { value: "1" },
|
|
79
232
|
});
|
|
80
|
-
|
|
233
|
+
wrapper.vm.handleButtonClick();
|
|
234
|
+
assert.ok(wrapper.emitted("click"));
|
|
235
|
+
assert.equal(wrapper.emitted("click")[0][0], "1");
|
|
81
236
|
wrapper.destroy();
|
|
82
237
|
});
|
|
238
|
+
});
|
|
83
239
|
|
|
84
|
-
|
|
240
|
+
describe("inheritAttrs", () => {
|
|
241
|
+
it("透传 $attrs 到根元素", () => {
|
|
85
242
|
const wrapper = mount(BusinessSwitch, {
|
|
86
|
-
propsData: {
|
|
87
|
-
|
|
88
|
-
showButtonWhen: 1,
|
|
89
|
-
hideButton: true,
|
|
90
|
-
},
|
|
243
|
+
propsData: { value: 0 },
|
|
244
|
+
attrs: { "data-test-id": "business-switch" },
|
|
91
245
|
});
|
|
92
|
-
assert.
|
|
246
|
+
assert.ok(wrapper.find(".comp-BusinessSwitch").exists());
|
|
93
247
|
wrapper.destroy();
|
|
94
248
|
});
|
|
95
249
|
});
|
|
@@ -1,82 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BusinessTag 组件测试
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 验证业务标签组件的标签类型解析、文本解析和自定义 prop 映射。
|
|
5
|
+
* 注:与项目现有测试一致,通过 vm 访问计算属性而非检查 Element UI DOM 类。
|
|
5
6
|
*/
|
|
6
|
-
const {
|
|
7
|
+
const { mount } = require("../../../test/helper");
|
|
7
8
|
const BusinessTag = require("./BusinessTag.vue");
|
|
8
9
|
|
|
9
10
|
const MOCK_OPTIONS = [
|
|
10
|
-
{ name: "
|
|
11
|
-
{ name: "
|
|
12
|
-
{ name: "
|
|
11
|
+
{ name: "启用", value: "1", tagType: "success" },
|
|
12
|
+
{ name: "禁用", value: "0", tagType: "danger" },
|
|
13
|
+
{ name: "审核中", value: "2", tagType: "warning" },
|
|
13
14
|
];
|
|
14
15
|
|
|
15
16
|
describe("BusinessTag", () => {
|
|
16
17
|
describe("渲染", () => {
|
|
17
|
-
it("
|
|
18
|
+
it("渲染成功(不抛异常)", () => {
|
|
18
19
|
const wrapper = mount(BusinessTag, {
|
|
19
|
-
propsData: {
|
|
20
|
+
propsData: { value: "1", options: MOCK_OPTIONS },
|
|
20
21
|
});
|
|
21
|
-
assert.ok(wrapper.
|
|
22
|
-
wrapper.destroy();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("value 不在 options 中时显示原始 value", () => {
|
|
26
|
-
const wrapper = mount(BusinessTag, {
|
|
27
|
-
propsData: { options: MOCK_OPTIONS, value: 99 },
|
|
28
|
-
});
|
|
29
|
-
assert.ok(wrapper.text().includes("99"));
|
|
30
|
-
wrapper.destroy();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("根据 value 计算 tagType", () => {
|
|
34
|
-
const wrapper = mount(BusinessTag, {
|
|
35
|
-
propsData: { options: MOCK_OPTIONS, value: 2 },
|
|
36
|
-
});
|
|
37
|
-
const elTag = wrapper.find(".el-tag");
|
|
38
|
-
assert.ok(elTag.exists());
|
|
39
|
-
assert.ok(elTag.classes().includes("el-tag--danger"));
|
|
22
|
+
assert.ok(wrapper.exists());
|
|
40
23
|
wrapper.destroy();
|
|
41
24
|
});
|
|
42
25
|
|
|
43
|
-
it("
|
|
26
|
+
it("支持自定义 tagTypeProp", () => {
|
|
44
27
|
const wrapper = mount(BusinessTag, {
|
|
45
28
|
propsData: {
|
|
46
|
-
options:
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
options: [
|
|
30
|
+
{ label: "已支付", id: 1, status: "success" },
|
|
31
|
+
{ label: "待支付", id: 2, status: "warning" },
|
|
32
|
+
],
|
|
33
|
+
value: 2,
|
|
34
|
+
valueProp: "id",
|
|
35
|
+
nameProp: "label",
|
|
36
|
+
tagTypeProp: "status",
|
|
49
37
|
},
|
|
50
38
|
});
|
|
51
|
-
|
|
52
|
-
assert.
|
|
39
|
+
assert.equal(wrapper.vm.tagType, "warning");
|
|
40
|
+
assert.equal(wrapper.vm.tagTypeText, "待支付");
|
|
53
41
|
wrapper.destroy();
|
|
54
42
|
});
|
|
55
43
|
});
|
|
56
44
|
|
|
57
|
-
describe("
|
|
58
|
-
it("
|
|
59
|
-
const customOptions = [
|
|
60
|
-
{ label: "选项A", key: "a" },
|
|
61
|
-
{ label: "选项B", key: "b" },
|
|
62
|
-
];
|
|
45
|
+
describe("边界行为", () => {
|
|
46
|
+
it("空 options 时回退到默认类型和原始值", () => {
|
|
63
47
|
const wrapper = mount(BusinessTag, {
|
|
64
|
-
propsData: {
|
|
65
|
-
options: customOptions,
|
|
66
|
-
value: "b",
|
|
67
|
-
valueProp: "key",
|
|
68
|
-
nameProp: "label",
|
|
69
|
-
},
|
|
48
|
+
propsData: { options: [], value: "未知状态" },
|
|
70
49
|
});
|
|
71
|
-
assert.
|
|
50
|
+
assert.equal(wrapper.vm.tagType, "info");
|
|
51
|
+
assert.equal(wrapper.vm.tagTypeText, "未知状态");
|
|
72
52
|
wrapper.destroy();
|
|
73
53
|
});
|
|
74
54
|
|
|
75
|
-
it("
|
|
55
|
+
it("数字 0 能匹配选项而不被当作空值", () => {
|
|
76
56
|
const wrapper = mount(BusinessTag, {
|
|
77
|
-
propsData: {
|
|
57
|
+
propsData: {
|
|
58
|
+
options: [
|
|
59
|
+
{ name: "有效", value: 1, tagType: "success" },
|
|
60
|
+
{ name: "无效", value: 0, tagType: "danger" },
|
|
61
|
+
],
|
|
62
|
+
value: 0,
|
|
63
|
+
},
|
|
78
64
|
});
|
|
79
|
-
assert.
|
|
65
|
+
assert.equal(wrapper.vm.tagType, "danger");
|
|
66
|
+
assert.equal(wrapper.vm.tagTypeText, "无效");
|
|
80
67
|
wrapper.destroy();
|
|
81
68
|
});
|
|
82
69
|
});
|
|
@@ -1,157 +1,280 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* InstitutionSelect 组件测试
|
|
3
3
|
*
|
|
4
|
-
* 验证机构选择器的渲染、单选/多选模式、props
|
|
5
|
-
*
|
|
4
|
+
* 验证机构选择器的渲染、单选/多选模式、props 和核心方法。
|
|
5
|
+
* 注:完整模态框交互测试需要更复杂的 vuex store + axios mock 基础设施。
|
|
6
6
|
*/
|
|
7
|
-
const {
|
|
7
|
+
const { mount, shallowMount } = require("../../../test/helper");
|
|
8
8
|
const InstitutionSelect = require("./InstitutionSelect.vue");
|
|
9
9
|
|
|
10
10
|
describe("InstitutionSelect", () => {
|
|
11
11
|
describe("渲染", () => {
|
|
12
|
-
it("
|
|
13
|
-
const wrapper =
|
|
12
|
+
it("默认渲染选择按钮", () => {
|
|
13
|
+
const wrapper = mount(InstitutionSelect, {
|
|
14
14
|
propsData: { value: "" },
|
|
15
15
|
});
|
|
16
16
|
assert.ok(wrapper.find(".comp-InstitutionSelect").exists());
|
|
17
|
+
assert.ok(wrapper.find(".institutions__btn-select").exists());
|
|
17
18
|
wrapper.destroy();
|
|
18
19
|
});
|
|
19
20
|
|
|
20
|
-
it("
|
|
21
|
-
const wrapper =
|
|
21
|
+
it("渲染提示文字", () => {
|
|
22
|
+
const wrapper = mount(InstitutionSelect, {
|
|
22
23
|
propsData: { value: "" },
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
-
assert.equal(wrapper.props().showSelectBtn, true);
|
|
25
|
+
assert.ok(wrapper.find(".text-info").exists());
|
|
26
26
|
wrapper.destroy();
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it("
|
|
30
|
-
const wrapper =
|
|
31
|
-
propsData: {
|
|
32
|
-
value: "",
|
|
33
|
-
showSelectBtn: false,
|
|
34
|
-
},
|
|
29
|
+
it("不渲染已选标签列表(单选模式默认)", () => {
|
|
30
|
+
const wrapper = mount(InstitutionSelect, {
|
|
31
|
+
propsData: { value: "" },
|
|
35
32
|
});
|
|
36
|
-
assert.equal(wrapper.props().showSelectBtn,
|
|
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());
|
|
37
36
|
wrapper.destroy();
|
|
38
37
|
});
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
describe("Props", () => {
|
|
42
|
-
it("
|
|
43
|
-
const wrapper =
|
|
44
|
-
propsData: { value: "
|
|
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 },
|
|
45
77
|
});
|
|
46
|
-
assert.
|
|
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());
|
|
47
87
|
wrapper.destroy();
|
|
48
88
|
});
|
|
49
89
|
|
|
50
90
|
it("支持自定义 IdKey", () => {
|
|
51
|
-
const wrapper =
|
|
52
|
-
propsData: {
|
|
53
|
-
value: "",
|
|
54
|
-
IdKey: "org_id",
|
|
55
|
-
},
|
|
91
|
+
const wrapper = mount(InstitutionSelect, {
|
|
92
|
+
propsData: { value: "", IdKey: "orgId" },
|
|
56
93
|
});
|
|
57
|
-
assert.equal(wrapper.props().IdKey, "
|
|
94
|
+
assert.equal(wrapper.props().IdKey, "orgId");
|
|
58
95
|
wrapper.destroy();
|
|
59
96
|
});
|
|
60
97
|
|
|
61
|
-
it("
|
|
62
|
-
const wrapper =
|
|
63
|
-
propsData: {
|
|
64
|
-
value: "",
|
|
65
|
-
btnText: "选择机构",
|
|
66
|
-
},
|
|
98
|
+
it("支持 maxSelectCount", () => {
|
|
99
|
+
const wrapper = mount(InstitutionSelect, {
|
|
100
|
+
propsData: { value: [], showTableSelect: true, maxSelectCount: 5 },
|
|
67
101
|
});
|
|
68
|
-
assert.equal(wrapper.props().
|
|
102
|
+
assert.equal(wrapper.props().maxSelectCount, 5);
|
|
69
103
|
wrapper.destroy();
|
|
70
104
|
});
|
|
105
|
+
});
|
|
71
106
|
|
|
72
|
-
|
|
73
|
-
|
|
107
|
+
describe("单选模式", () => {
|
|
108
|
+
it("有值时显示已选机构名称和删除图标", () => {
|
|
109
|
+
const wrapper = mount(InstitutionSelect, {
|
|
74
110
|
propsData: {
|
|
75
|
-
value:
|
|
76
|
-
|
|
111
|
+
value: "123",
|
|
112
|
+
formData: { level_name: "测试机构" },
|
|
113
|
+
levelNameKey: "level_name",
|
|
77
114
|
},
|
|
78
115
|
});
|
|
79
|
-
assert.
|
|
116
|
+
assert.ok(wrapper.find(".btn--delete").exists());
|
|
80
117
|
wrapper.destroy();
|
|
81
118
|
});
|
|
82
119
|
|
|
83
|
-
it("
|
|
84
|
-
const wrapper =
|
|
85
|
-
propsData: { value: "
|
|
120
|
+
it("无值时不显示删除图标", () => {
|
|
121
|
+
const wrapper = mount(InstitutionSelect, {
|
|
122
|
+
propsData: { value: "" },
|
|
86
123
|
});
|
|
87
|
-
|
|
88
|
-
assert.ok(wrapper.exists());
|
|
124
|
+
assert.ok(!wrapper.find(".btn--delete").exists());
|
|
89
125
|
wrapper.destroy();
|
|
90
126
|
});
|
|
91
127
|
|
|
92
|
-
it("
|
|
93
|
-
const wrapper =
|
|
128
|
+
it("点击删除触发 onDelete", async () => {
|
|
129
|
+
const wrapper = mount(InstitutionSelect, {
|
|
94
130
|
propsData: {
|
|
95
|
-
value:
|
|
96
|
-
|
|
131
|
+
value: "123",
|
|
132
|
+
formData: { level_name: "测试机构" },
|
|
133
|
+
levelNameKey: "level_name",
|
|
97
134
|
},
|
|
98
135
|
});
|
|
99
|
-
|
|
100
|
-
|
|
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"));
|
|
101
141
|
wrapper.destroy();
|
|
102
142
|
});
|
|
103
143
|
});
|
|
104
144
|
|
|
105
|
-
describe("
|
|
106
|
-
it("
|
|
107
|
-
const wrapper =
|
|
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, {
|
|
108
165
|
propsData: {
|
|
109
|
-
value: "",
|
|
110
|
-
|
|
166
|
+
value: [{ id: "1", level_name: "机构A" }, { id: "2", level_name: "机构B" }],
|
|
167
|
+
showTableSelect: true,
|
|
111
168
|
},
|
|
112
169
|
});
|
|
113
|
-
assert.ok(wrapper.exists());
|
|
170
|
+
assert.ok(wrapper.find(".selected-tags-wrap").exists());
|
|
114
171
|
wrapper.destroy();
|
|
115
172
|
});
|
|
116
173
|
});
|
|
117
174
|
|
|
118
|
-
describe("
|
|
119
|
-
it("
|
|
120
|
-
const wrapper =
|
|
175
|
+
describe("核心方法", () => {
|
|
176
|
+
it("levelNameRender 返回最细粒度的名称", () => {
|
|
177
|
+
const wrapper = mount(InstitutionSelect, {
|
|
121
178
|
propsData: { value: "" },
|
|
122
179
|
});
|
|
123
|
-
|
|
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支局");
|
|
124
187
|
wrapper.destroy();
|
|
125
188
|
});
|
|
126
189
|
|
|
127
|
-
it("
|
|
128
|
-
const wrapper =
|
|
190
|
+
it("levelNameRender 降级到上级名称", () => {
|
|
191
|
+
const wrapper = mount(InstitutionSelect, {
|
|
129
192
|
propsData: { value: "" },
|
|
130
193
|
});
|
|
131
|
-
|
|
132
|
-
|
|
194
|
+
const row = {
|
|
195
|
+
district_name: "XX区",
|
|
196
|
+
city_name: "XX市",
|
|
197
|
+
prov_name: "XX省",
|
|
198
|
+
};
|
|
199
|
+
assert.equal(wrapper.vm.levelNameRender(row), "XX区");
|
|
133
200
|
wrapper.destroy();
|
|
134
201
|
});
|
|
135
202
|
|
|
136
|
-
it("
|
|
137
|
-
const wrapper =
|
|
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, {
|
|
138
229
|
propsData: { value: "" },
|
|
139
230
|
});
|
|
140
|
-
wrapper.vm.
|
|
141
|
-
|
|
142
|
-
|
|
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"));
|
|
143
248
|
wrapper.destroy();
|
|
144
249
|
});
|
|
145
250
|
});
|
|
146
251
|
|
|
147
|
-
describe("
|
|
148
|
-
it("
|
|
252
|
+
describe("核心方法", () => {
|
|
253
|
+
it("levelNameRender 优先返回最细粒度名称并回退到 IdKey", () => {
|
|
149
254
|
const wrapper = shallowMount(InstitutionSelect, {
|
|
150
|
-
propsData: { value: "
|
|
255
|
+
propsData: { value: "", IdKey: "id" },
|
|
151
256
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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/");
|
|
155
278
|
wrapper.destroy();
|
|
156
279
|
});
|
|
157
280
|
});
|
|
@@ -166,9 +166,7 @@
|
|
|
166
166
|
|
|
167
167
|
<script>
|
|
168
168
|
import { mapGetters } from "vuex";
|
|
169
|
-
import Uts from "
|
|
170
|
-
|
|
171
|
-
const { reqModule: defaultReqModule = "admin" } = Uts.getEnv() || {};
|
|
169
|
+
import Uts from "../../utils/Uts.js";
|
|
172
170
|
|
|
173
171
|
export default {
|
|
174
172
|
name: "InstitutionSelect",
|
|
@@ -190,7 +188,7 @@ export default {
|
|
|
190
188
|
source: { type: String, default: "" },
|
|
191
189
|
activity_id: { type: String, default: "" }, //活动id-派发明细需要过滤对应的机构(支付宝/微信代金券)
|
|
192
190
|
cash_activity_id: { type: String, default: "" }, //活动id-派发明细需要过滤对应的机构(微邮惠礼包)
|
|
193
|
-
reqModule: { type: String, default:
|
|
191
|
+
reqModule: { type: String, default: "admin" },
|
|
194
192
|
reqUrl: { type: String, default: "" },
|
|
195
193
|
request: { type: Function, default: null },
|
|
196
194
|
levelTypes: { type: [String, Number], default: "" },
|
package/src/utils/Uts.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
describe("@infly/ui 的 @infly/ts-libs 适配层", () => {
|
|
6
|
+
it("提供组件现有 Uts 调用所需的纯函数与深拷贝", async () => {
|
|
7
|
+
const module = await import("./Uts.js");
|
|
8
|
+
const Uts = module.default;
|
|
9
|
+
|
|
10
|
+
expect(Uts.isFunction(() => {})).toBe(true);
|
|
11
|
+
expect(Uts.notEmptyArray([1])).toBe(true);
|
|
12
|
+
expect(Uts.getNestedValue({ user: { name: "Infly" } }, "user.name")).toBe("Infly");
|
|
13
|
+
|
|
14
|
+
const source = { nested: { value: 1 } };
|
|
15
|
+
const result = Uts.copyObj(source);
|
|
16
|
+
expect(result).toEqual(source);
|
|
17
|
+
expect(result.nested).not.toBe(source.nested);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("InflyForm 直接消费 ts-libs,UI 包不保存 Vue2 导出适配器", () => {
|
|
21
|
+
const formPath = path.resolve(
|
|
22
|
+
__dirname,
|
|
23
|
+
"../Base/InflyForm/InflyForm.vue",
|
|
24
|
+
);
|
|
25
|
+
const localExportPath = path.resolve(__dirname, "file-export.js");
|
|
26
|
+
const source = fs.readFileSync(formPath, "utf8");
|
|
27
|
+
|
|
28
|
+
expect(source).toContain('import { exportFile } from "@infly/ts-libs";');
|
|
29
|
+
expect(fs.existsSync(localExportPath)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
File without changes
|
package/src/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import BusinessSwitch from './Business/BusinessSwitch';
|
|
2
|
-
import BusinessTag from './Business/BusinessTag';
|
|
3
|
-
import InstitutionSelect from './Business/InstitutionSelect';
|
|
4
|
-
|
|
5
|
-
const install = (app) => {
|
|
6
|
-
if (install.installed) return;
|
|
7
|
-
install.installed = true;
|
|
8
|
-
app.component(BusinessSwitch.name, BusinessSwitch);
|
|
9
|
-
app.component(BusinessTag.name, BusinessTag);
|
|
10
|
-
app.component(InstitutionSelect.name, InstitutionSelect);
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
if (typeof window !== 'undefined' && window.Vue) {
|
|
15
|
-
install(window.Vue);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
BusinessSwitch,
|
|
20
|
-
BusinessTag,
|
|
21
|
-
InstitutionSelect,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default {
|
|
25
|
-
version: '1.0.0',
|
|
26
|
-
install,
|
|
27
|
-
BusinessSwitch,
|
|
28
|
-
BusinessTag,
|
|
29
|
-
InstitutionSelect
|
|
30
|
-
};
|