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,121 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Traversal', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/traversal')
6
+ })
7
+
8
+ it('.children() - get child DOM elements', () => {
9
+ // https://on.cypress.io/children
10
+ cy.get('.traversal-breadcrumb')
11
+ .children('.active')
12
+ .should('contain', 'Data')
13
+ })
14
+
15
+ it('.closest() - get closest ancestor DOM element', () => {
16
+ // https://on.cypress.io/closest
17
+ cy.get('.traversal-badge')
18
+ .closest('ul')
19
+ .should('have.class', 'list-group')
20
+ })
21
+
22
+ it('.eq() - get a DOM element at a specific index', () => {
23
+ // https://on.cypress.io/eq
24
+ cy.get('.traversal-list>li')
25
+ .eq(1).should('contain', 'siamese')
26
+ })
27
+
28
+ it('.filter() - get DOM elements that match the selector', () => {
29
+ // https://on.cypress.io/filter
30
+ cy.get('.traversal-nav>li')
31
+ .filter('.active').should('contain', 'About')
32
+ })
33
+
34
+ it('.find() - get descendant DOM elements of the selector', () => {
35
+ // https://on.cypress.io/find
36
+ cy.get('.traversal-pagination')
37
+ .find('li').find('a')
38
+ .should('have.length', 7)
39
+ })
40
+
41
+ it('.first() - get first DOM element', () => {
42
+ // https://on.cypress.io/first
43
+ cy.get('.traversal-table td')
44
+ .first().should('contain', '1')
45
+ })
46
+
47
+ it('.last() - get last DOM element', () => {
48
+ // https://on.cypress.io/last
49
+ cy.get('.traversal-buttons .btn')
50
+ .last().should('contain', 'Submit')
51
+ })
52
+
53
+ it('.next() - get next sibling DOM element', () => {
54
+ // https://on.cypress.io/next
55
+ cy.get('.traversal-ul')
56
+ .contains('apples').next().should('contain', 'oranges')
57
+ })
58
+
59
+ it('.nextAll() - get all next sibling DOM elements', () => {
60
+ // https://on.cypress.io/nextall
61
+ cy.get('.traversal-next-all')
62
+ .contains('oranges')
63
+ .nextAll().should('have.length', 3)
64
+ })
65
+
66
+ it('.nextUntil() - get next sibling DOM elements until next el', () => {
67
+ // https://on.cypress.io/nextuntil
68
+ cy.get('#veggies')
69
+ .nextUntil('#nuts').should('have.length', 3)
70
+ })
71
+
72
+ it('.not() - remove DOM elements from set of DOM elements', () => {
73
+ // https://on.cypress.io/not
74
+ cy.get('.traversal-disabled .btn')
75
+ .not('[disabled]').should('not.contain', 'Disabled')
76
+ })
77
+
78
+ it('.parent() - get parent DOM element from DOM elements', () => {
79
+ // https://on.cypress.io/parent
80
+ cy.get('.traversal-mark')
81
+ .parent().should('contain', 'Morbi leo risus')
82
+ })
83
+
84
+ it('.parents() - get parent DOM elements from DOM elements', () => {
85
+ // https://on.cypress.io/parents
86
+ cy.get('.traversal-cite')
87
+ .parents().should('match', 'blockquote')
88
+ })
89
+
90
+ it('.parentsUntil() - get parent DOM elements from DOM elements until el', () => {
91
+ // https://on.cypress.io/parentsuntil
92
+ cy.get('.clothes-nav')
93
+ .find('.active')
94
+ .parentsUntil('.clothes-nav')
95
+ .should('have.length', 2)
96
+ })
97
+
98
+ it('.prev() - get previous sibling DOM element', () => {
99
+ // https://on.cypress.io/prev
100
+ cy.get('.birds').find('.active')
101
+ .prev().should('contain', 'Lorikeets')
102
+ })
103
+
104
+ it('.prevAll() - get all previous sibling DOM elements', () => {
105
+ // https://on.cypress.io/prevall
106
+ cy.get('.fruits-list').find('.third')
107
+ .prevAll().should('have.length', 2)
108
+ })
109
+
110
+ it('.prevUntil() - get all previous sibling DOM elements until el', () => {
111
+ // https://on.cypress.io/prevuntil
112
+ cy.get('.foods-list').find('#nuts')
113
+ .prevUntil('#veggies').should('have.length', 3)
114
+ })
115
+
116
+ it('.siblings() - get all sibling DOM elements', () => {
117
+ // https://on.cypress.io/siblings
118
+ cy.get('.traversal-pills .active')
119
+ .siblings().should('have.length', 2)
120
+ })
121
+ })
@@ -0,0 +1,107 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Utilities', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/utilities')
6
+ })
7
+
8
+ it('Cypress._ - call a lodash method', () => {
9
+ // https://on.cypress.io/_
10
+ cy.request('https://jsonplaceholder.cypress.io/users')
11
+ .then((response) => {
12
+ let ids = Cypress._.chain(response.body).map('id').take(3).value()
13
+
14
+ expect(ids).to.deep.eq([1, 2, 3])
15
+ })
16
+ })
17
+
18
+ it('Cypress.$ - call a jQuery method', () => {
19
+ // https://on.cypress.io/$
20
+ let $li = Cypress.$('.utility-jquery li:first')
21
+
22
+ cy.wrap($li).should('not.have.class', 'active')
23
+ cy.wrap($li).click()
24
+ cy.wrap($li).should('have.class', 'active')
25
+ })
26
+
27
+ it('Cypress.Blob - blob utilities and base64 string conversion', () => {
28
+ // https://on.cypress.io/blob
29
+ cy.get('.utility-blob').then(($div) => {
30
+ // https://github.com/nolanlawson/blob-util#imgSrcToDataURL
31
+ // get the dataUrl string for the javascript-logo
32
+ return Cypress.Blob.imgSrcToDataURL('https://example.cypress.io/assets/img/javascript-logo.png', undefined, 'anonymous')
33
+ .then((dataUrl) => {
34
+ // create an <img> element and set its src to the dataUrl
35
+ let img = Cypress.$('<img />', { src: dataUrl })
36
+
37
+ // need to explicitly return cy here since we are initially returning
38
+ // the Cypress.Blob.imgSrcToDataURL promise to our test
39
+ // append the image
40
+ $div.append(img)
41
+
42
+ cy.get('.utility-blob img').click()
43
+ cy.get('.utility-blob img').should('have.attr', 'src', dataUrl)
44
+ })
45
+ })
46
+ })
47
+
48
+ it('Cypress.minimatch - test out glob patterns against strings', () => {
49
+ // https://on.cypress.io/minimatch
50
+ let matching = Cypress.minimatch('/users/1/comments', '/users/*/comments', {
51
+ matchBase: true,
52
+ })
53
+
54
+ expect(matching, 'matching wildcard').to.be.true
55
+
56
+ matching = Cypress.minimatch('/users/1/comments/2', '/users/*/comments', {
57
+ matchBase: true,
58
+ })
59
+
60
+ expect(matching, 'comments').to.be.false
61
+
62
+ // ** matches against all downstream path segments
63
+ matching = Cypress.minimatch('/foo/bar/baz/123/quux?a=b&c=2', '/foo/**', {
64
+ matchBase: true,
65
+ })
66
+
67
+ expect(matching, 'comments').to.be.true
68
+
69
+ // whereas * matches only the next path segment
70
+
71
+ matching = Cypress.minimatch('/foo/bar/baz/123/quux?a=b&c=2', '/foo/*', {
72
+ matchBase: false,
73
+ })
74
+
75
+ expect(matching, 'comments').to.be.false
76
+ })
77
+
78
+ it('Cypress.Promise - instantiate a bluebird promise', () => {
79
+ // https://on.cypress.io/promise
80
+ let waited = false
81
+
82
+ /**
83
+ * @return Bluebird<string>
84
+ */
85
+ function waitOneSecond () {
86
+ // return a promise that resolves after 1 second
87
+ return new Cypress.Promise((resolve, reject) => {
88
+ setTimeout(() => {
89
+ // set waited to true
90
+ waited = true
91
+
92
+ // resolve with 'foo' string
93
+ resolve('foo')
94
+ }, 1000)
95
+ })
96
+ }
97
+
98
+ cy.then(() => {
99
+ // return a promise to cy.then() that
100
+ // is awaited until it resolves
101
+ return waitOneSecond().then((str) => {
102
+ expect(str).to.eq('foo')
103
+ expect(waited).to.be.true
104
+ })
105
+ })
106
+ })
107
+ })
@@ -0,0 +1,58 @@
1
+ /// <reference types="cypress" />
2
+ context('Viewport', () => {
3
+ beforeEach(() => {
4
+ cy.visit('https://example.cypress.io/commands/viewport')
5
+ })
6
+
7
+ it('cy.viewport() - set the viewport size and dimension', () => {
8
+ // https://on.cypress.io/viewport
9
+
10
+ cy.get('#navbar').should('be.visible')
11
+ cy.viewport(320, 480)
12
+
13
+ // the navbar should have collapse since our screen is smaller
14
+ cy.get('#navbar').should('not.be.visible')
15
+ cy.get('.navbar-toggle').should('be.visible').click()
16
+ cy.get('.nav').find('a').should('be.visible')
17
+
18
+ // lets see what our app looks like on a super large screen
19
+ cy.viewport(2999, 2999)
20
+
21
+ // cy.viewport() accepts a set of preset sizes
22
+ // to easily set the screen to a device's width and height
23
+
24
+ // We added a cy.wait() between each viewport change so you can see
25
+ // the change otherwise it is a little too fast to see :)
26
+
27
+ cy.viewport('macbook-15')
28
+ cy.wait(200)
29
+ cy.viewport('macbook-13')
30
+ cy.wait(200)
31
+ cy.viewport('macbook-11')
32
+ cy.wait(200)
33
+ cy.viewport('ipad-2')
34
+ cy.wait(200)
35
+ cy.viewport('ipad-mini')
36
+ cy.wait(200)
37
+ cy.viewport('iphone-6+')
38
+ cy.wait(200)
39
+ cy.viewport('iphone-6')
40
+ cy.wait(200)
41
+ cy.viewport('iphone-5')
42
+ cy.wait(200)
43
+ cy.viewport('iphone-4')
44
+ cy.wait(200)
45
+ cy.viewport('iphone-3')
46
+ cy.wait(200)
47
+
48
+ // cy.viewport() accepts an orientation for all presets
49
+ // the default orientation is 'portrait'
50
+ cy.viewport('ipad-2', 'portrait')
51
+ cy.wait(200)
52
+ cy.viewport('iphone-4', 'landscape')
53
+ cy.wait(200)
54
+
55
+ // The viewport will be reset back to the default dimensions
56
+ // in between tests (the default can be set in cypress.config.{js|ts})
57
+ })
58
+ })
@@ -0,0 +1,30 @@
1
+ /// <reference types="cypress" />
2
+ context('Waiting', () => {
3
+ beforeEach(() => {
4
+ cy.visit('https://example.cypress.io/commands/waiting')
5
+ })
6
+ // BE CAREFUL of adding unnecessary wait times.
7
+ // https://on.cypress.io/best-practices#Unnecessary-Waiting
8
+
9
+ // https://on.cypress.io/wait
10
+ it('cy.wait() - wait for a specific amount of time', () => {
11
+ cy.get('.wait-input1').type('Wait 1000ms after typing')
12
+ cy.wait(1000)
13
+ cy.get('.wait-input2').type('Wait 1000ms after typing')
14
+ cy.wait(1000)
15
+ cy.get('.wait-input3').type('Wait 1000ms after typing')
16
+ cy.wait(1000)
17
+ })
18
+
19
+ it('cy.wait() - wait for a specific route', () => {
20
+ // Listen to GET to comments/1
21
+ cy.intercept('GET', '**/comments/*').as('getComment')
22
+
23
+ // we have code that gets a comment when
24
+ // the button is clicked in scripts.js
25
+ cy.get('.network-btn').click()
26
+
27
+ // wait for GET comments/1
28
+ cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])
29
+ })
30
+ })
@@ -0,0 +1,22 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Window', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/window')
6
+ })
7
+
8
+ it('cy.window() - get the global window object', () => {
9
+ // https://on.cypress.io/window
10
+ cy.window().should('have.property', 'top')
11
+ })
12
+
13
+ it('cy.document() - get the document object', () => {
14
+ // https://on.cypress.io/document
15
+ cy.document().should('have.property', 'charset').and('eq', 'UTF-8')
16
+ })
17
+
18
+ it('cy.title() - get the title', () => {
19
+ // https://on.cypress.io/title
20
+ cy.title().should('include', 'Kitchen Sink')
21
+ })
22
+ })
@@ -0,0 +1,127 @@
1
+ import slotsToData, { type SlotsToDataReturn, type SlotsToDataReturnItem } from '../../packages/Tool/slotsToData/slotsToData'
2
+
3
+ type VNodeType = { name: string } | symbol
4
+ interface VNodeLike {
5
+ type: VNodeType
6
+ props?: Record<string, unknown>
7
+ children?: VNodeLike[]
8
+ }
9
+
10
+ const createNode = (name: string, props: Record<string, unknown> = {}, children: VNodeLike[] = []): VNodeLike => ({
11
+ type: { name },
12
+ props,
13
+ children
14
+ })
15
+
16
+ describe('工具函数 slotsToData', () => {
17
+ it('默认插槽解析', () => {
18
+ const slots = {
19
+ default: () => [
20
+ createNode('ElDiv', { a: 1 }),
21
+ createNode('ElSpan', { b: 2 })
22
+ ]
23
+ }
24
+ const res: SlotsToDataReturn = slotsToData(slots)
25
+ expect(res).to.have.length(2)
26
+ expect(res[0].name).to.equal('ElDiv')
27
+ expect(res[0].props).to.deep.equal({ a: 1 })
28
+ expect(res[0].children).to.deep.equal([])
29
+ expect(res[1].name).to.equal('ElSpan')
30
+ })
31
+
32
+ it('指定插槽名 inlineBtn', () => {
33
+ const slots = {
34
+ inlineBtn: () => [
35
+ createNode('ElButton', { type: 'primary' })
36
+ ]
37
+ }
38
+ const res: SlotsToDataReturn = slotsToData(slots, { name: 'inlineBtn' })
39
+ expect(res).to.have.length(1)
40
+ expect(res[0].name).to.equal('ElButton')
41
+ expect(res[0].props).to.deep.equal({ type: 'primary' })
42
+ })
43
+
44
+ it('跳过注释节点 isJumpFgt=true', () => {
45
+ const slots = {
46
+ default: () => [
47
+ { type: Symbol('fgt') as symbol, props: {}, children: [] },
48
+ createNode('ElTag', { effect: 'light' })
49
+ ]
50
+ }
51
+ const res = slotsToData(slots)
52
+ expect(res).to.have.length(1)
53
+ expect(res[0].name).to.equal('ElTag')
54
+ })
55
+
56
+ it('不跳过注释节点 isJumpFgt=false', () => {
57
+ const comment: VNodeLike = { type: Symbol('fgt'), props: {}, children: [] }
58
+ const slots = {
59
+ default: () => [comment]
60
+ }
61
+ const res = slotsToData(slots, { isJumpFgt: false })
62
+ expect(res).to.have.length(1)
63
+ expect(res[0].name).to.equal(undefined)
64
+ expect(res[0].children).to.deep.equal([])
65
+ })
66
+
67
+ it('递归解析 children', () => {
68
+ const slots = {
69
+ default: () => [
70
+ createNode('ElDiv', {}, [
71
+ createNode('ElSpan', { text: 'A' }),
72
+ createNode('ElSpan', { text: 'B' })
73
+ ])
74
+ ]
75
+ }
76
+ const res = slotsToData(slots)
77
+ expect(res).to.have.length(1)
78
+ expect(res[0].children).to.have.length(2)
79
+ expect(res[0].children[0].name).to.equal('ElSpan')
80
+ expect(res[0].children[0].props).to.deep.equal({ text: 'A' })
81
+ })
82
+
83
+ it('限制递归最大深度 maxDepth=1', () => {
84
+ const slots = {
85
+ default: () => [
86
+ createNode('ElDiv', {}, [
87
+ createNode('ElSpan', { text: 'A' })
88
+ ])
89
+ ]
90
+ }
91
+ const res = slotsToData(slots, { maxDepth: 1 })
92
+ expect(res).to.have.length(1)
93
+ expect(res[0].children).to.deep.equal([])
94
+ })
95
+
96
+ it('插槽函数抛错时返回空数组', () => {
97
+ const slots = {
98
+ default: () => {
99
+ throw new Error('boom')
100
+ }
101
+ }
102
+ const res = slotsToData(slots)
103
+ expect(res).to.deep.equal([])
104
+ })
105
+
106
+ it('不存在的插槽名返回空数组', () => {
107
+ const slots = {
108
+ default: () => [createNode('ElDiv')]
109
+ }
110
+ const res = slotsToData(slots, { name: 'submitBtn' })
111
+ expect(res).to.deep.equal([])
112
+ })
113
+
114
+ it('props 与 children 字段完整性', () => {
115
+ const slots = {
116
+ default: () => [
117
+ createNode('ElRow', { gutter: 12 }, [
118
+ createNode('ElCol', { span: 6 })
119
+ ])
120
+ ]
121
+ }
122
+ const res: SlotsToDataReturn = slotsToData(slots)
123
+ const first: SlotsToDataReturnItem = res[0]
124
+ expect(first.props).to.deep.equal({ gutter: 12 })
125
+ expect(first.children[0].props).to.deep.equal({ span: 6 })
126
+ })
127
+ })
@@ -0,0 +1,79 @@
1
+ import uniqueByKey from '../../packages/Tool/uniqueByKey/uniqueByKey'
2
+
3
+ interface StrItem { id: string; name: string }
4
+ interface NumItem { id: number; name: string }
5
+ interface OptItem { id?: string; name: string }
6
+ interface BoolItem { active: boolean; label: string }
7
+ interface ObjKeyItem { key: { v: number }; id: number }
8
+
9
+ describe('工具函数 uniqueByKey', () => {
10
+ it('字符串键去重并保持首次出现顺序', () => {
11
+ const arr: StrItem[] = [
12
+ { id: 'a', name: 'A1' },
13
+ { id: 'b', name: 'B1' },
14
+ { id: 'a', name: 'A2' },
15
+ { id: 'c', name: 'C1' },
16
+ { id: 'b', name: 'B2' }
17
+ ]
18
+ const res = uniqueByKey(arr, 'id')
19
+ expect(res.map(i => i.id)).to.deep.equal(['a', 'b', 'c'])
20
+ expect(res[0].name).to.equal('A1')
21
+ expect(res[1].name).to.equal('B1')
22
+ expect(res[2].name).to.equal('C1')
23
+ })
24
+
25
+ it('数字键去重', () => {
26
+ const arr: NumItem[] = [
27
+ { id: 1, name: 'N1' },
28
+ { id: 2, name: 'N2' },
29
+ { id: 1, name: 'N1-dup' },
30
+ { id: 3, name: 'N3' }
31
+ ]
32
+ const res = uniqueByKey(arr, 'id')
33
+ expect(res.map(i => i.id)).to.deep.equal([1, 2, 3])
34
+ })
35
+
36
+ it('空数组返回空数组', () => {
37
+ const arr: StrItem[] = []
38
+ const res = uniqueByKey(arr, 'id')
39
+ expect(res).to.deep.equal([])
40
+ })
41
+
42
+ it('可选键值为 undefined 的处理,仅保留首个 undefined', () => {
43
+ const arr: OptItem[] = [
44
+ { name: 'X' },
45
+ { name: 'Y' },
46
+ { id: '1', name: 'Z1' },
47
+ { id: '1', name: 'Z2' }
48
+ ]
49
+ const res = uniqueByKey(arr, 'id')
50
+ expect(res.length).to.equal(2)
51
+ expect(res[0].id).to.equal(undefined)
52
+ expect(res[0].name).to.equal('X')
53
+ expect(res[1].id).to.equal('1')
54
+ expect(res[1].name).to.equal('Z1')
55
+ })
56
+
57
+ it('布尔键去重', () => {
58
+ const arr: BoolItem[] = [
59
+ { active: true, label: 'A' },
60
+ { active: false, label: 'B' },
61
+ { active: true, label: 'A-dup' }
62
+ ]
63
+ const res = uniqueByKey(arr, 'active')
64
+ expect(res.map(i => i.active)).to.deep.equal([true, false])
65
+ })
66
+
67
+ it('对象键按引用去重(同引用合并,不同引用保留)', () => {
68
+ const same = { v: 1 }
69
+ const arr: ObjKeyItem[] = [
70
+ { key: same, id: 1 },
71
+ { key: same, id: 2 },
72
+ { key: { v: 1 }, id: 3 }
73
+ ]
74
+ const res = uniqueByKey(arr, 'key')
75
+ expect(res.length).to.equal(2)
76
+ expect(res[0].id).to.equal(1)
77
+ expect(res[1].id).to.equal(3)
78
+ })
79
+ })
@@ -20,6 +20,10 @@ import './commands'
20
20
  // require('./commands')
21
21
 
22
22
  import { mount } from 'cypress/vue'
23
+ import ElementPlus from 'element-plus'
24
+ import 'element-plus/dist/index.css'
25
+ import * as ElementPlusIconsVue from '@element-plus/icons-vue'
26
+ import dionysus from '../../packages'
23
27
 
24
28
  // Augment the Cypress namespace to include type definitions for
25
29
  // your custom command.
@@ -33,7 +37,22 @@ declare global {
33
37
  }
34
38
  }
35
39
 
36
- Cypress.Commands.add('mount', mount)
40
+ Cypress.Commands.add('mount', (component, options = {}) => {
41
+ options.global = options.global || {}
42
+ options.global.plugins = options.global.plugins || []
43
+ options.global.components = options.global.components || {}
44
+
45
+ // 注册 ElementPlus
46
+ options.global.plugins.push(ElementPlus)
47
+ options.global.plugins.push(dionysus)
48
+
49
+ // 注册所有图标组件
50
+ for (const [key, icon] of Object.entries(ElementPlusIconsVue)) {
51
+ options.global.components[key] = icon
52
+ }
53
+
54
+ return mount(component, options)
55
+ })
37
56
 
38
57
  // Example use:
39
58
  // cy.mount(MyComponent)
package/cypress.config.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { defineConfig } from 'cypress'
2
2
 
3
3
  export default defineConfig({
4
+ projectId: 'gtk9e8',
4
5
  e2e: {
5
6
  setupNodeEvents (on, config) {
6
7
  // implement node event listeners here