br-dionysus 1.17.7 → 1.18.0

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.
Files changed (82) hide show
  1. package/README.md +73 -24
  2. package/attributes.json +1 -1
  3. package/cypress/component/MSelect.cy.ts +0 -1
  4. package/cypress/component/MSelectTable.cy.ts +538 -0
  5. package/cypress/component/MSelectV2.cy.ts +0 -1
  6. package/cypress/component/MTable.cy.ts +123 -0
  7. package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
  8. package/cypress/e2e/2-advanced-examples/actions.cy.js +321 -0
  9. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
  10. package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
  11. package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
  12. package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
  13. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +184 -0
  14. package/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
  15. package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
  16. package/cypress/e2e/2-advanced-examples/misc.cy.js +98 -0
  17. package/cypress/e2e/2-advanced-examples/navigation.cy.js +55 -0
  18. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
  19. package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
  20. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +204 -0
  21. package/cypress/e2e/2-advanced-examples/storage.cy.js +117 -0
  22. package/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
  23. package/cypress/e2e/2-advanced-examples/utilities.cy.js +107 -0
  24. package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
  25. package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
  26. package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
  27. package/cypress/e2e/toolSlotsToData.cy.ts +127 -0
  28. package/cypress/e2e/toolUniqueByKey.cy.ts +79 -0
  29. package/cypress/support/component.ts +20 -1
  30. package/cypress.config.ts +1 -0
  31. package/dist/br-dionysus.es.js +5872 -5696
  32. package/dist/br-dionysus.umd.js +6 -5
  33. package/dist/cypress/component/MInputNumber.cy.d.ts +0 -0
  34. package/dist/cypress/component/MSelect.cy.d.ts +1 -0
  35. package/dist/cypress/component/MSelectTable.cy.d.ts +1 -0
  36. package/dist/cypress/component/MSelectV2.cy.d.ts +1 -0
  37. package/dist/cypress/component/MTable.cy.d.ts +1 -0
  38. package/dist/cypress/e2e/spec.cy.d.ts +0 -0
  39. package/dist/cypress/e2e/toolCheckType.cy.d.ts +1 -0
  40. package/dist/cypress/e2e/toolCompareStructures.cy.d.ts +1 -0
  41. package/dist/cypress/e2e/toolCreateHash.cy.d.ts +1 -0
  42. package/dist/cypress/e2e/toolMoneyFormat.cy.d.ts +1 -0
  43. package/dist/cypress/e2e/toolSlotsToData.cy.d.ts +1 -0
  44. package/dist/cypress/e2e/toolUniqueByKey.cy.d.ts +1 -0
  45. package/dist/cypress/support/commands.d.ts +0 -0
  46. package/dist/cypress/support/component.d.ts +9 -0
  47. package/dist/cypress/support/e2e.d.ts +0 -0
  48. package/dist/index.css +1 -1
  49. package/dist/packages/Hook/usePackageConfig/usePackageConfig.d.ts +2 -0
  50. package/dist/packages/MTable/src/MTable.vue.d.ts +49 -15
  51. package/dist/packages/MTable/src/token.d.ts +13 -0
  52. package/dist/packages/MTableColumn/src/MTableColumn.vue.d.ts +9 -14
  53. package/dist/packages/Tool/globalEvents/globalEvents.d.ts +26 -0
  54. package/dist/packages/index.d.ts +2 -0
  55. package/package.json +2 -2
  56. package/packages/Hook/usePackageConfig/usePackageConfig.ts +6 -4
  57. package/packages/Hook/useZIndex/useGlobalZIndex.ts +1 -1
  58. package/packages/MDialog/src/MDialog.vue +8 -8
  59. package/packages/MSelectTable/docs/README.md +1 -0
  60. package/packages/MSelectTable/src/MSelectTable.vue +6 -6
  61. package/packages/MTable/docs/DemoTest4.vue +0 -1
  62. package/packages/MTable/docs/DemoTest6.vue +122 -0
  63. package/packages/MTable/docs/DemoTest7.vue +138 -0
  64. package/packages/MTable/docs/README.md +10 -10
  65. package/packages/MTable/docs/demo.vue +10 -2
  66. package/packages/MTable/src/MBatchEdit.vue +1 -0
  67. package/packages/MTable/src/MTable.vue +254 -38
  68. package/packages/MTable/src/token.ts +14 -1
  69. package/packages/MTableColumn/docs/README.md +1 -0
  70. package/packages/MTableColumn/src/MTableColumn.vue +98 -24
  71. package/packages/Tool/globalEvents/README.md +23 -0
  72. package/packages/Tool/globalEvents/globalEvents.ts +79 -0
  73. package/packages/index.ts +2 -0
  74. package/packages/typings/global.d.ts +6 -2
  75. package/tags.json +1 -1
  76. package/tsconfig.json +3 -1
  77. package/web-types.json +1 -1
  78. package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/345/215/225/351/200/211/345/212/237/350/203/275 (failed).png +0 -0
  79. package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/345/237/272/347/241/200/345/212/237/350/203/275 (failed).png +0 -0
  80. package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/345/244/232/351/200/211/345/212/237/350/203/275 (failed).png +0 -0
  81. package/cypress/screenshots/MSelectTable.cy.ts//344/270/213/346/213/211/350/241/250/346/240/274/351/200/211/346/213/251/345/231/250/347/273/204/344/273/266MSelectTable -- /346/265/213/350/257/225/350/277/234/347/250/213/346/220/234/347/264/242/345/212/237/350/203/275 (failed).png +0 -0
  82. package/src/global.d.ts +0 -5
@@ -0,0 +1,538 @@
1
+ import { MSelectTable } from '../../packages'
2
+
3
+ describe('下拉表格选择器组件<MSelectTable />', () => {
4
+ const options: Option[] = [
5
+ { label: '这是选项一', value: 'a' },
6
+ { label: '这是选项二', value: 'b' },
7
+ { label: '这是选项三', value: 'c' }
8
+ ]
9
+ const tableTitle: TableTitle[] = [
10
+ { prop: 'label', label: '名称', minWidth: 100 },
11
+ { prop: 'value', label: '编码', minWidth: 100 }
12
+ ]
13
+
14
+ it('单选并触发 selected 事件', () => {
15
+ const selectedSpy = cy.spy().as('selectedSpy')
16
+
17
+ cy.mount(MSelectTable as any, {
18
+ global: { plugins: [] },
19
+ props: {
20
+ multiple: false,
21
+ options,
22
+ tableTitle,
23
+ onSelected: selectedSpy
24
+ }
25
+ })
26
+
27
+ cy.get('.el-input__wrapper').click()
28
+ cy.get('.br-m-table-box .el-table__body tr').eq(0).click()
29
+ cy.get('@selectedSpy').should('have.been.calledWith', 'a')
30
+ })
31
+
32
+ it('单选情况下的 name 参数的生效', () => {
33
+ cy.mount(MSelectTable as any, {
34
+ global: { plugins: [] },
35
+ props: {
36
+ multiple: false,
37
+ modelValue: 'a',
38
+ name: '自定义名称A',
39
+ options,
40
+ tableTitle
41
+ }
42
+ })
43
+
44
+ cy.get('.el-input__wrapper').click()
45
+ cy.get('.el-input__inner').should('have.value', '自定义名称A')
46
+ })
47
+
48
+ it('多选情况下的 name 参数的生效', () => {
49
+ cy.mount(MSelectTable as any, {
50
+ global: { plugins: [] },
51
+ props: {
52
+ multiple: true,
53
+ modelValue: ['a', 'b'],
54
+ name: ['标签A', '标签B'],
55
+ options,
56
+ tableTitle
57
+ }
58
+ })
59
+
60
+ cy.get('.el-input-tag__wrapper').click()
61
+ cy.get('.el-input-tag__wrapper .el-tag').eq(0).should('contain.text', '标签A')
62
+ cy.get('.el-input-tag__wrapper .el-tag').eq(1).should('contain.text', '标签B')
63
+ })
64
+
65
+ it('单选情况下的 辅助插槽', () => {
66
+ cy.mount(MSelectTable as any, {
67
+ global: { plugins: [] },
68
+ props: {
69
+ multiple: false,
70
+ options,
71
+ tableTitle
72
+ },
73
+ slots: {
74
+ auxiliary: '<span class="aux-slot">辅助内容-单选</span>'
75
+ }
76
+ })
77
+
78
+ cy.get('.el-input__wrapper').click()
79
+ cy.get('.br-m-table-box .head-box .aux-slot').should('contain.text', '辅助内容-单选')
80
+ })
81
+
82
+ it('多选情况下的 辅助插槽', () => {
83
+ cy.mount(MSelectTable as any, {
84
+ global: { plugins: [] },
85
+ props: {
86
+ multiple: true,
87
+ options,
88
+ tableTitle
89
+ },
90
+ slots: {
91
+ auxiliary: '<div class="aux-slot">辅助内容-多选</div>'
92
+ }
93
+ })
94
+
95
+ cy.get('.el-input-tag__wrapper').click()
96
+ cy.get('.br-m-table-box .head-box .aux-slot').should('contain.text', '辅助内容-多选')
97
+ })
98
+
99
+ // it('多选情况下输入内容后回车进行创建条目', () => {
100
+ // })
101
+
102
+ it('多选并显示确认按钮并确认触发 selectMultiple 事件', () => {
103
+ const selectMultipleSpy = cy.spy().as('selectMultipleSpy')
104
+
105
+ cy.mount(MSelectTable as any, {
106
+ global: { plugins: [] },
107
+ props: {
108
+ multiple: true,
109
+ isAffirmBtn: true,
110
+ options,
111
+ tableTitle,
112
+ onSelectMultiple: selectMultipleSpy
113
+ }
114
+ })
115
+
116
+ cy.get('.el-input-tag__wrapper').click()
117
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
118
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(1).click()
119
+ cy.get('.br-m-table-box .head-box .el-button').click()
120
+
121
+ cy.get('@selectMultipleSpy').should('have.been.calledWith', ['a', 'b'])
122
+ })
123
+
124
+ it('远程搜索触发 remoteMethod 调用', () => {
125
+ const remoteSpy = cy.spy().as('remoteSpy')
126
+
127
+ cy.mount(MSelectTable as any, {
128
+ global: { plugins: [] },
129
+ props: {
130
+ multiple: false,
131
+ remote: true,
132
+ remoteMethod: remoteSpy,
133
+ options,
134
+ tableTitle
135
+ }
136
+ })
137
+
138
+ cy.get('.el-input__wrapper').click()
139
+ cy.get('.el-input__inner').type('二')
140
+ cy.get('@remoteSpy').should((spy: any) => {
141
+ const arg = spy.args[spy.args.length - 1][0]
142
+ expect(arg).to.equal('二')
143
+ })
144
+ })
145
+
146
+ it('单选清空触发 clear 事件', () => {
147
+ const clearSpy = cy.spy().as('clearSpy')
148
+
149
+ cy.mount(MSelectTable as any, {
150
+ global: { plugins: [] },
151
+ props: {
152
+ multiple: false,
153
+ modelValue: 'a',
154
+ name: '名称A',
155
+ options,
156
+ tableTitle,
157
+ onClear: clearSpy
158
+ }
159
+ })
160
+
161
+ cy.get('.el-input__wrapper').click()
162
+ cy.get('.el-input__clear').click()
163
+ cy.get('@clearSpy').should('have.been.called')
164
+ })
165
+
166
+ it('修改默认的 label 和 value', () => {
167
+ const opts = [
168
+ { text: '第一项', code: 'x1' },
169
+ { text: '第二项', code: 'x2' },
170
+ { text: '第三项', code: 'x3' }
171
+ ]
172
+ const titles = [
173
+ { prop: 'text', label: '名称', minWidth: 100 },
174
+ { prop: 'code', label: '编码', minWidth: 100 }
175
+ ]
176
+
177
+ const singleSpy = cy.spy().as('singleSpy')
178
+ cy.mount(MSelectTable as any, {
179
+ global: { plugins: [] },
180
+ props: {
181
+ multiple: false,
182
+ options: opts,
183
+ tableTitle: titles,
184
+ keywords: { label: 'text', value: 'code' },
185
+ onSelected: singleSpy
186
+ }
187
+ })
188
+ cy.get('.el-input__wrapper').click()
189
+ cy.get('.br-m-table-box .el-table__body tr').eq(0).click()
190
+ cy.get('@singleSpy').should('have.been.calledWith', 'x1')
191
+ cy.get('.el-input__inner').should('have.value', '第一项')
192
+
193
+ const multiSpy = cy.spy().as('multiSpy')
194
+ cy.mount(MSelectTable as any, {
195
+ global: { plugins: [] },
196
+ props: {
197
+ multiple: true,
198
+ isAffirmBtn: true,
199
+ options: opts,
200
+ tableTitle: titles,
201
+ keywords: { label: 'text', value: 'code' },
202
+ onSelectMultiple: multiSpy
203
+ }
204
+ })
205
+ cy.get('.el-input-tag__wrapper').click()
206
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
207
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(1).click()
208
+ cy.get('.br-m-table-box .head-box .el-button').click()
209
+ cy.get('@multiSpy').should('have.been.calledWith', ['x1', 'x2'])
210
+ })
211
+
212
+ it('占位符 placeholder 展示', () => {
213
+ cy.mount(MSelectTable as any, {
214
+ global: { plugins: [] },
215
+ props: {
216
+ multiple: false,
217
+ placeholder: '请输入内容',
218
+ options,
219
+ tableTitle
220
+ }
221
+ })
222
+ cy.get('.el-input__wrapper').click()
223
+ cy.get('.el-input__inner').should('have.attr', 'placeholder', '请输入内容')
224
+ })
225
+
226
+ it('禁用态 disabled 不可交互', () => {
227
+ cy.mount(MSelectTable as any, {
228
+ global: { plugins: [] },
229
+ props: {
230
+ multiple: true,
231
+ disabled: true,
232
+ options,
233
+ tableTitle
234
+ }
235
+ })
236
+ cy.get('.el-input-tag__wrapper').click()
237
+ cy.get('.br-m-table-box').should('not.be.visible')
238
+ })
239
+
240
+ it('尺寸 size=large 样式生效', () => {
241
+ cy.mount(MSelectTable as any, {
242
+ global: { plugins: [] },
243
+ props: {
244
+ multiple: false,
245
+ size: 'large',
246
+ options,
247
+ tableTitle
248
+ }
249
+ })
250
+ cy.get('.el-input').should('have.class', 'el-input--large')
251
+ })
252
+
253
+ it('尺寸 size=small 样式生效', () => {
254
+ cy.mount(MSelectTable as any, {
255
+ global: { plugins: [] },
256
+ props: {
257
+ multiple: false,
258
+ size: 'small',
259
+ options,
260
+ tableTitle
261
+ }
262
+ })
263
+ cy.get('.el-input').should('have.class', 'el-input--small')
264
+ })
265
+
266
+ it('渲染 options 与 tableTitle 列头', () => {
267
+ cy.mount(MSelectTable as any, {
268
+ global: { plugins: [] },
269
+ props: {
270
+ multiple: false,
271
+ options,
272
+ tableTitle
273
+ }
274
+ })
275
+ cy.get('.el-input__wrapper').click()
276
+ cy.get('.br-m-table-box .el-table__header th').eq(0).should('contain.text', '名称')
277
+ cy.get('.br-m-table-box .el-table__header th').eq(1).should('contain.text', '编码')
278
+ cy.get('.br-m-table-box .el-table__body tr').should('have.length', options.length)
279
+ })
280
+
281
+ it('total 显示分页器', () => {
282
+ cy.mount(MSelectTable as any, {
283
+ global: { plugins: [] },
284
+ props: { multiple: false, total: 10, options, tableTitle }
285
+ })
286
+ cy.get('.el-input__wrapper').click()
287
+ cy.get('.m-page .el-pagination').should('be.visible')
288
+ })
289
+
290
+ // it('自定义 filterMethod 与 filterable 配合', () => {
291
+ // const filterSpy = cy.spy().as('filterSpy')
292
+ // cy.mount(MSelectTable as any, {
293
+ // global: { plugins: [ElementPlus] },
294
+ // props: { multiple: false, filterable: true, filterMethod: filterSpy, options, tableTitle }
295
+ // })
296
+ // cy.get('.el-input__wrapper').click()
297
+ // cy.get('.el-input__inner').type('二')
298
+ // cy.get('@filterSpy').should((spy: any) => {
299
+ // const args = spy.args[spy.args.length - 1]
300
+ // expect(args[0]).to.equal('二')
301
+ // expect(args[1]).to.have.property('currentPage')
302
+ // expect(args[1]).to.have.property('pageSize')
303
+ // })
304
+ // })
305
+
306
+ // it('开启 filterable 本地关键字筛选', () => {
307
+ // cy.mount(MSelectTable as any, {
308
+ // global: { plugins: [ElementPlus] },
309
+ // props: { multiple: false, filterable: true, options, tableTitle }
310
+ // })
311
+ // cy.get('.el-input__wrapper').click()
312
+ // cy.get('.el-input__inner').type('二')
313
+ // cy.get('.br-m-table-box .el-table__body tr').should('have.length', 1)
314
+ // cy.get('.br-m-table-box .el-table__body tr').eq(0).should('contain.text', '这是选项二')
315
+ // })
316
+
317
+ it('remote 与 remoteMethod 组合远程搜索', () => {
318
+ const remoteSpy = cy.spy().as('remoteSpyAll')
319
+ cy.mount(MSelectTable as any, {
320
+ global: { plugins: [] },
321
+ props: { multiple: true, remote: true, filterable: true, remoteMethod: remoteSpy, options, tableTitle }
322
+ })
323
+ cy.get('.el-input-tag__wrapper').click()
324
+ cy.get('.el-input-tag__wrapper input').type('三')
325
+ cy.get('@remoteSpyAll').should((spy: any) => {
326
+ const args = spy.args[spy.args.length - 1]
327
+ expect(args[0]).to.equal('三')
328
+ expect(args[1]).to.have.property('currentPage')
329
+ })
330
+ })
331
+
332
+ it('reserveSelection 翻页多选保留', () => {
333
+ const toPageSpy = cy.spy().as('toPageSpy')
334
+ cy.mount(MSelectTable as any, {
335
+ global: { plugins: [] },
336
+ props: { multiple: true, reserveSelection: true, total: 10, options, tableTitle, onToPage: toPageSpy }
337
+ })
338
+ cy.get('.el-input-tag__wrapper').click()
339
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
340
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(1).click()
341
+ cy.get('.m-page .btn-next').click({ force: true })
342
+ cy.get('@toPageSpy').should('have.been.called')
343
+ cy.get('.m-page .btn-prev').click({ force: true })
344
+ cy.get('.br-m-table-box .el-table__body .el-checkbox.is-checked').should('have.length', 2)
345
+ })
346
+
347
+ it('tableHeight 指定表格高度', () => {
348
+ cy.mount(MSelectTable as any, {
349
+ global: { plugins: [] },
350
+ props: { multiple: false, tableHeight: 300, options, tableTitle }
351
+ })
352
+ cy.get('.el-input__wrapper').click()
353
+ cy.get('.br-m-table-box .el-table').should('have.attr', 'style').and('include', 'height')
354
+ })
355
+
356
+ it('isAffirmBtn 有确认按钮时 selected 不触发', () => {
357
+ const sel = cy.spy().as('sel')
358
+ const mul = cy.spy().as('mul')
359
+ cy.mount(MSelectTable as any, {
360
+ global: { plugins: [] },
361
+ props: { multiple: true, isAffirmBtn: true, options, tableTitle, onSelected: sel, onSelectMultiple: mul }
362
+ })
363
+ cy.get('.el-input-tag__wrapper').click()
364
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
365
+ cy.get('@sel').should('not.have.been.called')
366
+ cy.get('.br-m-table-box .head-box .el-button').click()
367
+ cy.get('@mul').should('have.been.called')
368
+ })
369
+
370
+ it('scrollbarAlwaysOn 常显滚动条', () => {
371
+ cy.mount(MSelectTable as any, {
372
+ global: { plugins: [] },
373
+ props: { multiple: false, scrollbarAlwaysOn: true, tableHeight: 100, options, tableTitle }
374
+ })
375
+ cy.get('.el-input__wrapper').click()
376
+ cy.get('.br-m-table-box .el-table__body-wrapper').should('have.css', 'overflow')
377
+ })
378
+
379
+ it('allowCreate 允许创建条目', () => {
380
+ const mul = cy.spy().as('mulCreate')
381
+ cy.mount(MSelectTable as any, {
382
+ global: { plugins: [] },
383
+ props: { multiple: true, allowCreate: true, isAffirmBtn: true, options, tableTitle, onSelectMultiple: mul }
384
+ })
385
+ cy.get('.el-input-tag__wrapper').click()
386
+ cy.get('.el-input-tag__wrapper input').type('新建项{enter}')
387
+ cy.get('.br-m-table-box .el-table__body').should('contain.text', '新建项')
388
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').last().click()
389
+ cy.get('.br-m-table-box .head-box .el-button').click()
390
+ cy.get('@mulCreate').should((spy: any) => {
391
+ const args = spy.args[spy.args.length - 1][0]
392
+ expect(args).to.include('新建项')
393
+ })
394
+ })
395
+
396
+ it('popupWidth 弹窗宽度配置', () => {
397
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: false, popupWidth: 600, options, tableTitle } })
398
+ cy.get('.el-input__wrapper').click()
399
+ cy.get('.br-m-table-box').should('have.attr', 'style').and('include', 'width: 600px')
400
+ })
401
+
402
+ it('border 开启表格边框', () => {
403
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: false, border: true, options, tableTitle } })
404
+ cy.get('.el-input__wrapper').click()
405
+ cy.get('.br-m-table-box .el-table').should('have.class', 'el-table--border')
406
+ })
407
+
408
+ it('事件 selected 单选返回值与行数据', () => {
409
+ const spySel = cy.spy().as('spySel')
410
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: false, options, tableTitle, onSelected: spySel } })
411
+ cy.get('.el-input__wrapper').click()
412
+ cy.get('.br-m-table-box .el-table__body tr').eq(1).click()
413
+ cy.get('@spySel').should((spy: any) => {
414
+ const args = spy.args[spy.args.length - 1]
415
+ expect(args[0]).to.equal('b')
416
+ expect(args[1]).to.have.property('label', '这是选项二')
417
+ expect(args[1]).to.have.property('value', 'b')
418
+ })
419
+ })
420
+
421
+ it('事件 selected 多选返回值与行数据集合', () => {
422
+ const spySelMul = cy.spy().as('spySelMul')
423
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: true, options, tableTitle, onSelected: spySelMul } })
424
+ cy.get('.el-input-tag__wrapper').click()
425
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
426
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(2).click()
427
+ cy.get('@spySelMul').should((spy: any) => {
428
+ const args = spy.args[spy.args.length - 1]
429
+ expect(args[0]).to.include.members(['a', 'c'])
430
+ expect(args[1]).to.have.length(2)
431
+ })
432
+ })
433
+
434
+ it('事件 toPage 未使用 filterMethod 时触发', () => {
435
+ const tp = cy.spy().as('tp')
436
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: false, total: 10, options, tableTitle, onToPage: tp } })
437
+ cy.get('.el-input__wrapper').click()
438
+ cy.get('.m-page .btn-next').click({ force: true })
439
+ cy.get('@tp').should('have.been.called')
440
+ })
441
+
442
+ it('事件 selectMultiple 确认按钮回调', () => {
443
+ const mul = cy.spy().as('mulEvt')
444
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: true, isAffirmBtn: true, options, tableTitle, onSelectMultiple: mul } })
445
+ cy.get('.el-input-tag__wrapper').click()
446
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
447
+ cy.get('.br-m-table-box .head-box .el-button').click()
448
+ cy.get('@mulEvt').should('have.been.calledWith', ['a'])
449
+ })
450
+
451
+ it('事件 clear 清空时触发', () => {
452
+ const clr = cy.spy().as('clr')
453
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { modelValue: 'a', name: '名称A', options, tableTitle, onClear: clr } })
454
+ cy.get('.el-input__inner').click()
455
+ cy.get('.el-input__suffix .el-icon').click()
456
+ cy.get('@clr').should('have.been.called')
457
+ })
458
+
459
+ it('事件 removeTag 多选删除 tag 时触发', () => {
460
+ const rm = cy.spy().as('rm')
461
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: true, modelValue: ['a', 'b'], name: ['标签A', '标签B'], options, tableTitle, onRemoveTag: rm } })
462
+ cy.get('.el-input-tag__wrapper').click()
463
+ cy.get('.el-input-tag__wrapper .el-tag .el-tag__close').eq(0).click({ force: true })
464
+ cy.get('@rm').should('have.been.called')
465
+ })
466
+
467
+ it('事件 selectChange 勾选变更时触发', () => {
468
+ const sc = cy.spy().as('sc')
469
+ cy.mount(MSelectTable as any, { global: { plugins: [] }, props: { multiple: true, options, tableTitle, onSelectChange: sc } })
470
+ cy.get('.el-input-tag__wrapper').click()
471
+ cy.get('.br-m-table-box .el-table__body .el-checkbox').eq(0).click()
472
+ cy.get('@sc').should('have.been.called')
473
+ })
474
+
475
+ // it('方法 defaultBackFillValue 多选翻页默认反填', () => {
476
+ // const Wrapper = defineComponent({
477
+ // setup: () => {
478
+ // const compRef = ref<InstanceType<typeof MSelectTable> | null>(null)
479
+ // onMounted(() => {
480
+ // ;(window as unknown as { __mst?: InstanceType<typeof MSelectTable> }).__mst = compRef.value as InstanceType<typeof MSelectTable>
481
+ // })
482
+ // return () => h(MSelectTable as any, { ref: compRef, multiple: true, reserveSelection: true, modelValue: ['b'], options, tableTitle })
483
+ // }
484
+ // })
485
+ // cy.mount(Wrapper as any, { global: { plugins: [ElementPlus] } })
486
+ // cy.window().then((win) => {
487
+ // win.__mst?.focus()
488
+ // win.__mst?.defaultBackFillValue()
489
+ // })
490
+ // cy.get('.br-m-table-box .el-table__body tr').contains('这是选项二').parent().find('.el-checkbox').should('have.class', 'is-checked')
491
+ // })
492
+ //
493
+ // it('方法 clear 手动清空', () => {
494
+ // const Wrapper = defineComponent({
495
+ // setup: () => {
496
+ // const compRef = ref<InstanceType<typeof MSelectTable> | null>(null)
497
+ // onMounted(() => {
498
+ // ;(window as unknown as { __mst?: InstanceType<typeof MSelectTable> }).__mst = compRef.value as InstanceType<typeof MSelectTable>
499
+ // })
500
+ // return () => h(MSelectTable as any, { ref: compRef, multiple: true, modelValue: ['a', 'b'], name: ['标签A', '标签B'], options, tableTitle })
501
+ // }
502
+ // })
503
+ // cy.mount(Wrapper as any, { global: { plugins: [ElementPlus] } })
504
+ // cy.window().then((win) => {
505
+ // win.__mst?.focus()
506
+ // win.__mst?.clear()
507
+ // })
508
+ // cy.get('.br-m-table-box .el-table__body .el-checkbox.is-checked').should('have.length', 0)
509
+ // cy.get('.el-input-tag__wrapper .el-tag').should('have.length', 0)
510
+ // })
511
+ //
512
+ // it('方法 focus 手动聚焦下拉框', () => {
513
+ // const Wrapper = defineComponent({
514
+ // setup: () => {
515
+ // const compRef = ref<InstanceType<typeof MSelectTable> | null>(null)
516
+ // onMounted(() => {
517
+ // ;(window as unknown as { __mst?: InstanceType<typeof MSelectTable> }).__mst = compRef.value as InstanceType<typeof MSelectTable>
518
+ // })
519
+ // return () => h(MSelectTable as any, { ref: compRef, multiple: false, options, tableTitle })
520
+ // }
521
+ // })
522
+ // cy.mount(Wrapper as any, { global: { plugins: [ElementPlus] } })
523
+ // cy.window().then((win) => {
524
+ // win.__mst?.focus()
525
+ // })
526
+ // cy.get('.br-m-table-box').should('be.visible')
527
+ // })
528
+
529
+ it('插槽 auxiliary 表头辅助信息渲染', () => {
530
+ cy.mount(MSelectTable as any, {
531
+ global: { plugins: [] },
532
+ props: { multiple: true, options, tableTitle },
533
+ slots: { auxiliary: '<span class="aux-slot">辅助信息</span>' }
534
+ })
535
+ cy.get('.el-input-tag__wrapper').click()
536
+ cy.get('.br-m-table-box .head-box .aux-slot').should('contain.text', '辅助信息')
537
+ })
538
+ })
@@ -1,7 +1,6 @@
1
1
  import { mount } from 'cypress/vue'
2
2
  import { MSelectV2 } from '../../packages'
3
3
  import { ElSelect, ElCheckbox, ElOption } from 'element-plus'
4
- import 'element-plus/dist/index.css'
5
4
 
6
5
  Cypress.Commands.add('mount' as any, (component: any, options: any = {}) => {
7
6
  options.global = options.global || {}
@@ -0,0 +1,123 @@
1
+ import dionysus, { MTable, MTableColumn } from '../../packages'
2
+ import { defineComponent, ref, h, nextTick } from 'vue'
3
+
4
+ type Row = { id: number; sn: number; date: string; name: string; address: string; tag: string; qty: number }
5
+
6
+ const rows: Row[] = [
7
+ { id: 1, sn: 1, date: '2023-01-01', name: 'Tom1', address: 'LA', tag: 'Home', qty: 10 },
8
+ { id: 2, sn: 2, date: '2023-01-02', name: 'Tom2', address: 'LA', tag: 'Office', qty: 20 },
9
+ { id: 3, sn: 3, date: '2023-01-03', name: 'Tom3', address: 'SF', tag: 'Home', qty: 30 }
10
+ ]
11
+
12
+ type Handlers = {
13
+ onSelection?: (val: string) => void,
14
+ onConfig?: (val: Record<string, { show: boolean; sort: number }>) => void,
15
+ onExpand?: (row: unknown, expandedRows: unknown[]) => void,
16
+ onCopyData?: (val: any) => void,
17
+ onPasteData?: (val: any, tableData: any) => void
18
+ }
19
+
20
+ const Wrapper = defineComponent({
21
+ props: {
22
+ variant: { type: String, required: true },
23
+ handlers: { type: Object as () => Handlers, required: false, default: () => ({}) }
24
+ },
25
+ setup: (props, { expose }) => {
26
+ const mTableRef = ref()
27
+ expose({ mTableRef })
28
+ const filtersValue = ref<Record<string, Array<string | number>>>({})
29
+ const selectionCell = ref<string>('')
30
+ const tableConfig = ref<Record<string, { show: boolean; sort: number; headerAlign?: 'left' | 'center' | 'right' }>>({
31
+ name: { show: true, sort: 1 },
32
+ address: { show: true, sort: 2 }
33
+ })
34
+ if (props.variant === 'tableConfig') {
35
+ nextTick(() => { tableConfig.value = { name: { show: true, sort: 2 }, address: { show: false, sort: 1 } } })
36
+ }
37
+ const renderCols = () => {
38
+ if (props.variant === 'basic') {
39
+ return [h(MTableColumn as any, { prop: 'name', label: '名称', minWidth: 80 }), h(MTableColumn as any, { prop: 'address', label: '地址', minWidth: 80 })]
40
+ }
41
+ if (props.variant === 'filter') {
42
+ return [h(MTableColumn as any, {
43
+ prop: 'tag',
44
+ label: '标签',
45
+ filters: [{ text: 'Home', value: 'Home' }, { text: 'Office', value: 'Office' }],
46
+ filtersValue: filtersValue.value,
47
+ 'onUpdate:filtersValue': (val: Record<string, Array<string | number>>) => { filtersValue.value = val }
48
+ })]
49
+ }
50
+ if (props.variant === 'expand') {
51
+ return [h(MTableColumn as any, { prop: 'sn', label: '序号', minWidth: 80 }), h(MTableColumn as any, { prop: 'name', label: '名称', minWidth: 80 })]
52
+ }
53
+ if (props.variant === 'selection') {
54
+ return [h(MTableColumn as any, { prop: 'name', label: '名称', minWidth: 80 }), h(MTableColumn as any, { prop: 'address', label: '地址', minWidth: 80 })]
55
+ }
56
+ if (props.variant === 'tableConfig') {
57
+ return [h(MTableColumn as any, { prop: 'name', label: '名称', minWidth: 80 }), h(MTableColumn as any, { prop: 'address', label: '地址', minWidth: 80 })]
58
+ }
59
+ return []
60
+ }
61
+ return () => h(MTable as any, {
62
+ data: rows,
63
+ filtersValue: props.variant === 'filter' ? filtersValue.value : undefined,
64
+ rowKey: props.variant === 'expand' ? 'id' : undefined,
65
+ expandProp: props.variant === 'expand' ? 'sn' : undefined,
66
+ selectionCell: props.variant === 'selection' ? selectionCell.value : undefined,
67
+ 'onUpdate:selectionCell': props.variant === 'selection' ? (val: string) => { selectionCell.value = val; props.handlers?.onSelection?.(val) } : undefined,
68
+ tableConfig: props.variant === 'tableConfig' ? tableConfig.value : undefined,
69
+ 'onUpdate:tableConfig': props.variant === 'tableConfig' ? (val: Record<string, { show: boolean; sort: number }>) => { props.handlers?.onConfig?.(val) } : undefined,
70
+ onPrivateExpandChange: props.variant === 'expand' ? (row: unknown, expandedRows: unknown[]) => { props.handlers?.onExpand?.(row, expandedRows) } : undefined,
71
+ onCopyData: (val: any) => { props.handlers?.onCopyData?.(val) },
72
+ onPasteData: (val: any, tableData: any) => { props.handlers?.onPasteData?.(val, tableData) },
73
+ ref: mTableRef
74
+ }, { default: () => renderCols() })
75
+ }
76
+ })
77
+
78
+ describe('表格组件<MTable />', () => {
79
+ it('基础渲染列头与行', () => {
80
+ cy.mount(Wrapper as any, { global: { plugins: [dionysus], components: {} }, props: { variant: 'basic' } })
81
+ cy.get('.br-m-table-box .el-table__header th').eq(0).should('contain.text', '名称')
82
+ cy.get('.br-m-table-box .el-table__header th').eq(1).should('contain.text', '地址')
83
+ cy.get('.br-m-table-box .el-table__body tr').should('have.length', rows.length)
84
+ })
85
+ it('筛选过滤显示 Home', () => {
86
+ cy.mount(Wrapper as any, { global: { plugins: [dionysus], components: {} }, props: { variant: 'filter' } })
87
+ cy.get('.br-m-table-box .el-table__header th').contains('标签').parent().find('.u-icon').click({ force: true })
88
+ cy.get('.m-filter-box .u-checkbox-group .el-checkbox').contains('Home').click({ force: true })
89
+ cy.get('.m-filter-box .u-btn-gp .el-button').contains('筛选').click({ force: true })
90
+ cy.get('.br-m-table-box .el-table__body tr').should('have.length', 2)
91
+ })
92
+ it('展开列并触发 privateExpandChange', () => {
93
+ const spy = cy.spy().as('expandSpy')
94
+ cy.mount(Wrapper as any, { global: { plugins: [dionysus], components: {} }, props: { variant: 'expand', handlers: { onExpand: spy } } })
95
+ cy.get('.br-m-table-box .el-table__body tr').eq(0).find('.u-my-table-column-icon').click({ force: true })
96
+ cy.get('@expandSpy').should('have.been.called')
97
+ })
98
+ it('单元格选中', () => {
99
+ const selSpy = cy.spy().as('selUpdate')
100
+ cy.mount(Wrapper as any, { global: { plugins: [dionysus], components: {} }, props: { variant: 'selection', handlers: { onSelection: selSpy } } })
101
+ cy.get('.br-m-table-box .el-table__body tr').eq(1).find('td').eq(0).click()
102
+ cy.get('@selUpdate').should('have.been.calledWith', 'name')
103
+ cy.get('.br-m-table-box .el-table__body tr').eq(1).find('td').eq(0).should('have.attr', 'style').and('include', 'background-color')
104
+ })
105
+ it('更新 tableConfig 触发事件', () => {
106
+ const configSpy = cy.spy().as('configSpy')
107
+ cy.mount(Wrapper as any, { global: { plugins: [dionysus], components: {} }, props: { variant: 'tableConfig', handlers: { onConfig: configSpy } } })
108
+ cy.get('@configSpy').should('have.been.called')
109
+ })
110
+ it('暴露方法 getTableTitle', () => {
111
+ cy.mount(Wrapper as any, { global: { plugins: [dionysus], components: {} }, props: { variant: 'basic' } })
112
+ .then(({ wrapper }) => {
113
+ const mTable = wrapper.vm.mTableRef
114
+ expect(mTable).to.not.equal(undefined)
115
+ const titles = mTable.getTableTitle()
116
+ expect(titles).to.have.length(2)
117
+ expect(titles[0].label).to.equal('名称')
118
+ expect(titles[0].prop).to.equal('name')
119
+ expect(titles[1].label).to.equal('地址')
120
+ expect(titles[1].prop).to.equal('address')
121
+ })
122
+ })
123
+ })