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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
| import { describe, expect, it } from 'vitest';
|
| import { buildDynamicModelOpenData, parseTargetDynamicModelConfig, validateDynamicModelActionOptions } from '../helpers/dynamicModelActions';
|
| const formData = JSON.stringify({
| popupType: 'fullScreen',
| fullScreenWidth: '100%',
| fields: [{ __config__: { jnpfKey: 'input' }, __vModel__: 'applyType' }],
| });
|
| const columnData = JSON.stringify({
| type: 1,
| useFormPermission: true,
| });
|
| describe('dynamicModelActions', () => {
| it('requires modelId for every open action', () => {
| expect(() => validateDynamicModelActionOptions('add', {} as any)).toThrow('缺少模型 id');
| });
|
| it('requires id for edit and detail actions', () => {
| expect(() => validateDynamicModelActionOptions('edit', { modelId: 'target' })).toThrow('缺少数据 id');
| expect(() => validateDynamicModelActionOptions('detail', { modelId: 'target' })).toThrow('缺少数据 id');
| });
|
| it('parses target config and rejects data interface model', () => {
| expect(() => parseTargetDynamicModelConfig({ webType: 4, formData })).toThrow('不支持打开数据接口类型');
|
| const parsed = parseTargetDynamicModelConfig({
| columnData,
| formData,
| fullName: '成品请验单',
| webType: 2,
| });
|
| expect(parsed.formConf.popupType).toBe('fullScreen');
| expect(parsed.columnData.useFormPermission).toBe(true);
| expect(parsed.fullName).toBe('成品请验单');
| });
|
| it('builds native form init data with params for add', () => {
| const onSuccess = () => {};
| const target = parseTargetDynamicModelConfig({
| columnData,
| formData,
| fullName: '成品请验单',
| webType: 2,
| });
|
| const data = buildDynamicModelOpenData('add', {
| context: {
| isDataManage: false,
| isPreview: false,
| },
| options: {
| modelId: 'target-model',
| onSuccess,
| params: { applyType: '成品' },
| },
| target,
| });
|
| expect(data).toMatchObject({
| allList: [],
| formData: { applyType: '成品' },
| id: '',
| isDataManage: false,
| isPreview: false,
| menuId: '',
| modelId: 'target-model',
| onSuccess,
| showMoreBtn: true,
| title: '成品请验单',
| useFormPermission: false,
| });
| });
|
| it('builds native detail init data and enables form permission only with target menuId', () => {
| const target = parseTargetDynamicModelConfig({
| columnData,
| formData,
| fullName: '成品请验单',
| webType: 2,
| });
|
| const data = buildDynamicModelOpenData('detail', {
| context: {
| isDataManage: false,
| isPreview: false,
| },
| options: {
| id: 'real-id',
| menuId: 'target-menu',
| modelId: 'target-model',
| title: '自定义详情标题',
| },
| target,
| });
|
| expect(data).toMatchObject({
| formConf: { popupType: 'fullScreen' },
| hideExtra: false,
| id: 'real-id',
| menuId: 'target-menu',
| modelId: 'target-model',
| title: '自定义详情标题',
| useFormPermission: true,
| });
| });
|
| it('leaves the detail title empty when openDetail does not provide a custom title', () => {
| const target = parseTargetDynamicModelConfig({
| columnData,
| formData,
| fullName: '成品请验单',
| webType: 2,
| });
|
| const data = buildDynamicModelOpenData('detail', {
| context: {},
| options: {
| id: 'real-id',
| modelId: 'target-model',
| },
| target,
| });
|
| expect(data.title).toBe('');
| });
|
| it('disables more navigation for cross-model edit without target list context', () => {
| const target = parseTargetDynamicModelConfig({
| columnData,
| formData,
| fullName: '成品请验单',
| webType: 2,
| });
|
| const data = buildDynamicModelOpenData('edit', {
| context: {
| isDataManage: false,
| isPreview: false,
| },
| options: {
| id: 'real-id',
| modelId: 'target-model',
| },
| target,
| });
|
| expect(data).toMatchObject({
| allList: [],
| id: 'real-id',
| modelId: 'target-model',
| showMoreBtn: false,
| });
| });
|
| it('uses success alias as native form submit callback', () => {
| const success = () => {};
| const target = parseTargetDynamicModelConfig({
| columnData,
| formData,
| fullName: '成品请验单',
| webType: 2,
| });
|
| const data = buildDynamicModelOpenData('edit', {
| context: {
| isDataManage: false,
| isPreview: false,
| },
| options: {
| id: 'real-id',
| modelId: 'target-model',
| success,
| },
| target,
| });
|
| expect(data).toMatchObject({
| id: 'real-id',
| modelId: 'target-model',
| onSuccess: success,
| });
| });
| });
|
|