br-dionysus 1.7.6 → 1.7.8

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 (86) hide show
  1. package/README.md +85 -20
  2. package/attributes.json +1 -1
  3. package/build/doc.config.ts +1 -1
  4. package/build/lib.config.ts +1 -1
  5. package/cypress/component/MInputNumber.cy.ts +38 -0
  6. package/cypress/component/MSelect.cy.ts +46 -0
  7. package/cypress/component/MSelectV2.cy.ts +46 -0
  8. package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
  9. package/cypress/e2e/2-advanced-examples/actions.cy.js +321 -0
  10. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
  11. package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
  12. package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
  13. package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
  14. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +185 -0
  15. package/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
  16. package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
  17. package/cypress/e2e/2-advanced-examples/misc.cy.js +90 -0
  18. package/cypress/e2e/2-advanced-examples/navigation.cy.js +55 -0
  19. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
  20. package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
  21. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +204 -0
  22. package/cypress/e2e/2-advanced-examples/storage.cy.js +117 -0
  23. package/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
  24. package/cypress/e2e/2-advanced-examples/utilities.cy.js +107 -0
  25. package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
  26. package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
  27. package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
  28. package/cypress/e2e/spec.cy.ts +5 -0
  29. package/cypress/e2e/toolCheckType.cy.ts +37 -0
  30. package/cypress/e2e/toolCompareStructures.cy.ts +19 -0
  31. package/cypress/e2e/toolCreateHash.cy.ts +7 -0
  32. package/cypress/e2e/toolMoneyFormat.cy.ts +46 -0
  33. package/cypress/fixtures/example.json +5 -0
  34. package/cypress/support/commands.ts +37 -0
  35. package/cypress/support/component-index.html +12 -0
  36. package/cypress/support/component.ts +39 -0
  37. package/cypress/support/e2e.ts +20 -0
  38. package/cypress/types.d.ts +1 -0
  39. package/cypress.config.ts +16 -0
  40. package/dist/br-dionysus.es.js +2781 -2739
  41. package/dist/br-dionysus.umd.js +7 -7
  42. package/dist/cypress.config.d.ts +3 -0
  43. package/dist/index.css +1 -1
  44. package/dist/packages/MDialog/src/MDialog.vue.d.ts +1 -1
  45. package/dist/packages/MInputNumber/src/MInputNumber.vue.d.ts +1 -1
  46. package/dist/packages/MSelectTable/src/MSelectTable.vue.d.ts +3 -3
  47. package/dist/packages/MSelectTableV1/src/MSelectTableV1.vue.d.ts +2 -2
  48. package/dist/packages/MSelectV2/src/MSelectV2.vue.d.ts +8 -2
  49. package/dist/packages/SkinConfig/src/SkinConfig.vue.d.ts +1 -1
  50. package/dist/packages/Tool/checkType/checkType.d.ts +7 -0
  51. package/dist/packages/Tool/compareStructures/compareStructures.d.ts +10 -0
  52. package/dist/packages/Tool/createHash/createHash.d.ts +7 -0
  53. package/dist/packages/index.d.ts +6 -2
  54. package/dist/vite.config.d.ts +2 -0
  55. package/package.json +7 -3
  56. package/packages/Hook/useRemainingSpace/README.md +17 -7
  57. package/packages/Hook/useRemainingSpace/demo.vue +38 -0
  58. package/packages/Hook/useRemainingSpace/useRemainingSpace.ts +7 -2
  59. package/packages/Hook/useTableConfig/demo.vue +1 -1
  60. package/packages/MDialog/src/MDialog.vue +2 -8
  61. package/packages/MInline/src/MInline.vue +1 -11
  62. package/packages/MInputNumber/src/MInputNumber.vue +3 -5
  63. package/packages/MSelectTable/src/MSelectTable.vue +3 -0
  64. package/packages/MSelectV2/docs/demo.vue +1 -1
  65. package/packages/MSelectV2/src/MSelectV2.vue +10 -6
  66. package/packages/MTable/src/MTable.vue +2 -2
  67. package/packages/MTableColumn/src/MTableColumn.vue +51 -8
  68. package/packages/MTableColumnSet/src/MTableColumnSet.vue +1 -1
  69. package/packages/SkinConfig/src/SkinConfig.vue +2 -1
  70. package/packages/SkinConfig/src/useSkin.ts +5 -2
  71. package/packages/Tool/checkType/README.md +17 -0
  72. package/packages/Tool/checkType/checkType.ts +14 -0
  73. package/packages/Tool/compareStructures/README.md +16 -0
  74. package/packages/Tool/createHash/README.md +7 -0
  75. package/packages/Tool/moneyFormat/README.md +13 -12
  76. package/packages/Tool/moneyFormat/moneyFormat.ts +35 -2
  77. package/packages/index.ts +8 -2
  78. package/packages/list.json +10 -4
  79. package/src/cypress-augmentation.d.ts +9 -0
  80. package/src/router.ts +5 -0
  81. package/tags.json +1 -1
  82. package/{build/base.config.ts → vite.config.ts} +3 -3
  83. package/web-types.json +1 -1
  84. package/tool/checkType.ts +0 -15
  85. /package/{tool → packages/Tool/compareStructures}/compareStructures.ts +0 -0
  86. /package/{tool → packages/Tool/createHash}/createHash.ts +0 -0
@@ -0,0 +1,321 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Actions', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/actions')
6
+ })
7
+
8
+ // https://on.cypress.io/interacting-with-elements
9
+
10
+ it('.type() - type into a DOM element', () => {
11
+ // https://on.cypress.io/type
12
+ cy.get('.action-email').type('fake@email.com')
13
+ cy.get('.action-email').should('have.value', 'fake@email.com')
14
+
15
+ // .type() with special character sequences
16
+ cy.get('.action-email').type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
17
+ cy.get('.action-email').type('{del}{selectall}{backspace}')
18
+
19
+ // .type() with key modifiers
20
+ cy.get('.action-email').type('{alt}{option}') //these are equivalent
21
+ cy.get('.action-email').type('{ctrl}{control}') //these are equivalent
22
+ cy.get('.action-email').type('{meta}{command}{cmd}') //these are equivalent
23
+ cy.get('.action-email').type('{shift}')
24
+
25
+ // Delay each keypress by 0.1 sec
26
+ cy.get('.action-email').type('slow.typing@email.com', { delay: 100 })
27
+ cy.get('.action-email').should('have.value', 'slow.typing@email.com')
28
+
29
+ cy.get('.action-disabled')
30
+ // Ignore error checking prior to type
31
+ // like whether the input is visible or disabled
32
+ .type('disabled error checking', { force: true })
33
+ cy.get('.action-disabled').should('have.value', 'disabled error checking')
34
+ })
35
+
36
+ it('.focus() - focus on a DOM element', () => {
37
+ // https://on.cypress.io/focus
38
+ cy.get('.action-focus').focus()
39
+ cy.get('.action-focus').should('have.class', 'focus')
40
+ .prev().should('have.attr', 'style', 'color: orange;')
41
+ })
42
+
43
+ it('.blur() - blur off a DOM element', () => {
44
+ // https://on.cypress.io/blur
45
+ cy.get('.action-blur').type('About to blur')
46
+ cy.get('.action-blur').blur()
47
+ cy.get('.action-blur').should('have.class', 'error')
48
+ .prev().should('have.attr', 'style', 'color: red;')
49
+ })
50
+
51
+ it('.clear() - clears an input or textarea element', () => {
52
+ // https://on.cypress.io/clear
53
+ cy.get('.action-clear').type('Clear this text')
54
+ cy.get('.action-clear').should('have.value', 'Clear this text')
55
+ cy.get('.action-clear').clear()
56
+ cy.get('.action-clear').should('have.value', '')
57
+ })
58
+
59
+ it('.submit() - submit a form', () => {
60
+ // https://on.cypress.io/submit
61
+ cy.get('.action-form')
62
+ .find('[type="text"]').type('HALFOFF')
63
+
64
+ cy.get('.action-form').submit()
65
+ cy.get('.action-form').next().should('contain', 'Your form has been submitted!')
66
+ })
67
+
68
+ it('.click() - click on a DOM element', () => {
69
+ // https://on.cypress.io/click
70
+ cy.get('.action-btn').click()
71
+
72
+ // You can click on 9 specific positions of an element:
73
+ // -----------------------------------
74
+ // | topLeft top topRight |
75
+ // | |
76
+ // | |
77
+ // | |
78
+ // | left center right |
79
+ // | |
80
+ // | |
81
+ // | |
82
+ // | bottomLeft bottom bottomRight |
83
+ // -----------------------------------
84
+
85
+ // clicking in the center of the element is the default
86
+ cy.get('#action-canvas').click()
87
+
88
+ cy.get('#action-canvas').click('topLeft')
89
+ cy.get('#action-canvas').click('top')
90
+ cy.get('#action-canvas').click('topRight')
91
+ cy.get('#action-canvas').click('left')
92
+ cy.get('#action-canvas').click('right')
93
+ cy.get('#action-canvas').click('bottomLeft')
94
+ cy.get('#action-canvas').click('bottom')
95
+ cy.get('#action-canvas').click('bottomRight')
96
+
97
+ // .click() accepts an x and y coordinate
98
+ // that controls where the click occurs :)
99
+
100
+ cy.get('#action-canvas')
101
+ cy.get('#action-canvas').click(80, 75) // click 80px on x coord and 75px on y coord
102
+ cy.get('#action-canvas').click(170, 75)
103
+ cy.get('#action-canvas').click(80, 165)
104
+ cy.get('#action-canvas').click(100, 185)
105
+ cy.get('#action-canvas').click(125, 190)
106
+ cy.get('#action-canvas').click(150, 185)
107
+ cy.get('#action-canvas').click(170, 165)
108
+
109
+ // click multiple elements by passing multiple: true
110
+ cy.get('.action-labels>.label').click({ multiple: true })
111
+
112
+ // Ignore error checking prior to clicking
113
+ cy.get('.action-opacity>.btn').click({ force: true })
114
+ })
115
+
116
+ it('.dblclick() - double click on a DOM element', () => {
117
+ // https://on.cypress.io/dblclick
118
+
119
+ // Our app has a listener on 'dblclick' event in our 'scripts.js'
120
+ // that hides the div and shows an input on double click
121
+ cy.get('.action-div').dblclick()
122
+ cy.get('.action-div').should('not.be.visible')
123
+ cy.get('.action-input-hidden').should('be.visible')
124
+ })
125
+
126
+ it('.rightclick() - right click on a DOM element', () => {
127
+ // https://on.cypress.io/rightclick
128
+
129
+ // Our app has a listener on 'contextmenu' event in our 'scripts.js'
130
+ // that hides the div and shows an input on right click
131
+ cy.get('.rightclick-action-div').rightclick()
132
+ cy.get('.rightclick-action-div').should('not.be.visible')
133
+ cy.get('.rightclick-action-input-hidden').should('be.visible')
134
+ })
135
+
136
+ it('.check() - check a checkbox or radio element', () => {
137
+ // https://on.cypress.io/check
138
+
139
+ // By default, .check() will check all
140
+ // matching checkbox or radio elements in succession, one after another
141
+ cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').check()
142
+ cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').should('be.checked')
143
+
144
+ cy.get('.action-radios [type="radio"]').not('[disabled]').check()
145
+ cy.get('.action-radios [type="radio"]').not('[disabled]').should('be.checked')
146
+
147
+ // .check() accepts a value argument
148
+ cy.get('.action-radios [type="radio"]').check('radio1')
149
+ cy.get('.action-radios [type="radio"]').should('be.checked')
150
+
151
+ // .check() accepts an array of values
152
+ cy.get('.action-multiple-checkboxes [type="checkbox"]').check(['checkbox1', 'checkbox2'])
153
+ cy.get('.action-multiple-checkboxes [type="checkbox"]').should('be.checked')
154
+
155
+ // Ignore error checking prior to checking
156
+ cy.get('.action-checkboxes [disabled]').check({ force: true })
157
+ cy.get('.action-checkboxes [disabled]').should('be.checked')
158
+
159
+ cy.get('.action-radios [type="radio"]').check('radio3', { force: true })
160
+ cy.get('.action-radios [type="radio"]').should('be.checked')
161
+ })
162
+
163
+ it('.uncheck() - uncheck a checkbox element', () => {
164
+ // https://on.cypress.io/uncheck
165
+
166
+ // By default, .uncheck() will uncheck all matching
167
+ // checkbox elements in succession, one after another
168
+ cy.get('.action-check [type="checkbox"]')
169
+ .not('[disabled]')
170
+ .uncheck()
171
+ cy.get('.action-check [type="checkbox"]')
172
+ .not('[disabled]')
173
+ .should('not.be.checked')
174
+
175
+ // .uncheck() accepts a value argument
176
+ cy.get('.action-check [type="checkbox"]')
177
+ .check('checkbox1')
178
+ cy.get('.action-check [type="checkbox"]')
179
+ .uncheck('checkbox1')
180
+ cy.get('.action-check [type="checkbox"][value="checkbox1"]')
181
+ .should('not.be.checked')
182
+
183
+ // .uncheck() accepts an array of values
184
+ cy.get('.action-check [type="checkbox"]')
185
+ .check(['checkbox1', 'checkbox3'])
186
+ cy.get('.action-check [type="checkbox"]')
187
+ .uncheck(['checkbox1', 'checkbox3'])
188
+ cy.get('.action-check [type="checkbox"][value="checkbox1"]')
189
+ .should('not.be.checked')
190
+ cy.get('.action-check [type="checkbox"][value="checkbox3"]')
191
+ .should('not.be.checked')
192
+
193
+ // Ignore error checking prior to unchecking
194
+ cy.get('.action-check [disabled]').uncheck({ force: true })
195
+ cy.get('.action-check [disabled]').should('not.be.checked')
196
+ })
197
+
198
+ it('.select() - select an option in a <select> element', () => {
199
+ // https://on.cypress.io/select
200
+
201
+ // at first, no option should be selected
202
+ cy.get('.action-select')
203
+ .should('have.value', '--Select a fruit--')
204
+
205
+ // Select option(s) with matching text content
206
+ cy.get('.action-select').select('apples')
207
+ // confirm the apples were selected
208
+ // note that each value starts with "fr-" in our HTML
209
+ cy.get('.action-select').should('have.value', 'fr-apples')
210
+
211
+ cy.get('.action-select-multiple')
212
+ .select(['apples', 'oranges', 'bananas'])
213
+ cy.get('.action-select-multiple')
214
+ // when getting multiple values, invoke "val" method first
215
+ .invoke('val')
216
+ .should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
217
+
218
+ // Select option(s) with matching value
219
+ cy.get('.action-select').select('fr-bananas')
220
+ cy.get('.action-select')
221
+ // can attach an assertion right away to the element
222
+ .should('have.value', 'fr-bananas')
223
+
224
+ cy.get('.action-select-multiple')
225
+ .select(['fr-apples', 'fr-oranges', 'fr-bananas'])
226
+ cy.get('.action-select-multiple')
227
+ .invoke('val')
228
+ .should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
229
+
230
+ // assert the selected values include oranges
231
+ cy.get('.action-select-multiple')
232
+ .invoke('val').should('include', 'fr-oranges')
233
+ })
234
+
235
+ it('.scrollIntoView() - scroll an element into view', () => {
236
+ // https://on.cypress.io/scrollintoview
237
+
238
+ // normally all of these buttons are hidden,
239
+ // because they're not within
240
+ // the viewable area of their parent
241
+ // (we need to scroll to see them)
242
+ cy.get('#scroll-horizontal button')
243
+ .should('not.be.visible')
244
+
245
+ // scroll the button into view, as if the user had scrolled
246
+ cy.get('#scroll-horizontal button').scrollIntoView()
247
+ cy.get('#scroll-horizontal button')
248
+ .should('be.visible')
249
+
250
+ cy.get('#scroll-vertical button')
251
+ .should('not.be.visible')
252
+
253
+ // Cypress handles the scroll direction needed
254
+ cy.get('#scroll-vertical button').scrollIntoView()
255
+ cy.get('#scroll-vertical button')
256
+ .should('be.visible')
257
+
258
+ cy.get('#scroll-both button')
259
+ .should('not.be.visible')
260
+
261
+ // Cypress knows to scroll to the right and down
262
+ cy.get('#scroll-both button').scrollIntoView()
263
+ cy.get('#scroll-both button')
264
+ .should('be.visible')
265
+ })
266
+
267
+ it('.trigger() - trigger an event on a DOM element', () => {
268
+ // https://on.cypress.io/trigger
269
+
270
+ // To interact with a range input (slider)
271
+ // we need to set its value & trigger the
272
+ // event to signal it changed
273
+
274
+ // Here, we invoke jQuery's val() method to set
275
+ // the value and trigger the 'change' event
276
+ cy.get('.trigger-input-range')
277
+ .invoke('val', 25)
278
+ cy.get('.trigger-input-range')
279
+ .trigger('change')
280
+ cy.get('.trigger-input-range')
281
+ .get('input[type=range]').siblings('p')
282
+ .should('have.text', '25')
283
+ })
284
+
285
+ it('cy.scrollTo() - scroll the window or element to a position', () => {
286
+ // https://on.cypress.io/scrollto
287
+
288
+ // You can scroll to 9 specific positions of an element:
289
+ // -----------------------------------
290
+ // | topLeft top topRight |
291
+ // | |
292
+ // | |
293
+ // | |
294
+ // | left center right |
295
+ // | |
296
+ // | |
297
+ // | |
298
+ // | bottomLeft bottom bottomRight |
299
+ // -----------------------------------
300
+
301
+ // if you chain .scrollTo() off of cy, we will
302
+ // scroll the entire window
303
+ cy.scrollTo('bottom')
304
+
305
+ cy.get('#scrollable-horizontal').scrollTo('right')
306
+
307
+ // or you can scroll to a specific coordinate:
308
+ // (x axis, y axis) in pixels
309
+ cy.get('#scrollable-vertical').scrollTo(250, 250)
310
+
311
+ // or you can scroll to a specific percentage
312
+ // of the (width, height) of the element
313
+ cy.get('#scrollable-both').scrollTo('75%', '25%')
314
+
315
+ // control the easing of the scroll (default is 'swing')
316
+ cy.get('#scrollable-vertical').scrollTo('center', { easing: 'linear' })
317
+
318
+ // control the duration of the scroll (in ms)
319
+ cy.get('#scrollable-both').scrollTo('center', { duration: 2000 })
320
+ })
321
+ })
@@ -0,0 +1,39 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Aliasing', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/aliasing')
6
+ })
7
+
8
+ it('.as() - alias a DOM element for later use', () => {
9
+ // https://on.cypress.io/as
10
+
11
+ // Alias a DOM element for use later
12
+ // We don't have to traverse to the element
13
+ // later in our code, we reference it with @
14
+
15
+ cy.get('.as-table').find('tbody>tr')
16
+ .first().find('td').first()
17
+ .find('button').as('firstBtn')
18
+
19
+ // when we reference the alias, we place an
20
+ // @ in front of its name
21
+ cy.get('@firstBtn').click()
22
+
23
+ cy.get('@firstBtn')
24
+ .should('have.class', 'btn-success')
25
+ .and('contain', 'Changed')
26
+ })
27
+
28
+ it('.as() - alias a route for later use', () => {
29
+ // Alias the route to wait for its response
30
+ cy.intercept('GET', '**/comments/*').as('getComment')
31
+
32
+ // we have code that gets a comment when
33
+ // the button is clicked in scripts.js
34
+ cy.get('.network-btn').click()
35
+
36
+ // https://on.cypress.io/wait
37
+ cy.wait('@getComment').its('response.statusCode').should('eq', 200)
38
+ })
39
+ })
@@ -0,0 +1,176 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Assertions', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/assertions')
6
+ })
7
+
8
+ describe('Implicit Assertions', () => {
9
+ it('.should() - make an assertion about the current subject', () => {
10
+ // https://on.cypress.io/should
11
+ cy.get('.assertion-table')
12
+ .find('tbody tr:last')
13
+ .should('have.class', 'success')
14
+ .find('td')
15
+ .first()
16
+ // checking the text of the <td> element in various ways
17
+ .should('have.text', 'Column content')
18
+ .should('contain', 'Column content')
19
+ .should('have.html', 'Column content')
20
+ // chai-jquery uses "is()" to check if element matches selector
21
+ .should('match', 'td')
22
+ // to match text content against a regular expression
23
+ // first need to invoke jQuery method text()
24
+ // and then match using regular expression
25
+ .invoke('text')
26
+ .should('match', /column content/i)
27
+
28
+ // a better way to check element's text content against a regular expression
29
+ // is to use "cy.contains"
30
+ // https://on.cypress.io/contains
31
+ cy.get('.assertion-table')
32
+ .find('tbody tr:last')
33
+ // finds first <td> element with text content matching regular expression
34
+ .contains('td', /column content/i)
35
+ .should('be.visible')
36
+
37
+ // for more information about asserting element's text
38
+ // see https://on.cypress.io/using-cypress-faq#How-do-I-get-an-element’s-text-contents
39
+ })
40
+
41
+ it('.and() - chain multiple assertions together', () => {
42
+ // https://on.cypress.io/and
43
+ cy.get('.assertions-link')
44
+ .should('have.class', 'active')
45
+ .and('have.attr', 'href')
46
+ .and('include', 'cypress.io')
47
+ })
48
+ })
49
+
50
+ describe('Explicit Assertions', () => {
51
+ // https://on.cypress.io/assertions
52
+ it('expect - make an assertion about a specified subject', () => {
53
+ // We can use Chai's BDD style assertions
54
+ expect(true).to.be.true
55
+ const o = { foo: 'bar' }
56
+
57
+ expect(o).to.equal(o)
58
+ expect(o).to.deep.equal({ foo: 'bar' })
59
+ // matching text using regular expression
60
+ expect('FooBar').to.match(/bar$/i)
61
+ })
62
+
63
+ it('pass your own callback function to should()', () => {
64
+ // Pass a function to should that can have any number
65
+ // of explicit assertions within it.
66
+ // The ".should(cb)" function will be retried
67
+ // automatically until it passes all your explicit assertions or times out.
68
+ cy.get('.assertions-p')
69
+ .find('p')
70
+ .should(($p) => {
71
+ // https://on.cypress.io/$
72
+ // return an array of texts from all of the p's
73
+ const texts = $p.map((i, el) => Cypress.$(el).text())
74
+
75
+ // jquery map returns jquery object
76
+ // and .get() convert this to simple array
77
+ const paragraphs = texts.get()
78
+
79
+ // array should have length of 3
80
+ expect(paragraphs, 'has 3 paragraphs').to.have.length(3)
81
+
82
+ // use second argument to expect(...) to provide clear
83
+ // message with each assertion
84
+ expect(paragraphs, 'has expected text in each paragraph').to.deep.eq([
85
+ 'Some text from first p',
86
+ 'More text from second p',
87
+ 'And even more text from third p',
88
+ ])
89
+ })
90
+ })
91
+
92
+ it('finds element by class name regex', () => {
93
+ cy.get('.docs-header')
94
+ .find('div')
95
+ // .should(cb) callback function will be retried
96
+ .should(($div) => {
97
+ expect($div).to.have.length(1)
98
+
99
+ const className = $div[0].className
100
+
101
+ expect(className).to.match(/heading-/)
102
+ })
103
+ // .then(cb) callback is not retried,
104
+ // it either passes or fails
105
+ .then(($div) => {
106
+ expect($div, 'text content').to.have.text('Introduction')
107
+ })
108
+ })
109
+
110
+ it('can throw any error', () => {
111
+ cy.get('.docs-header')
112
+ .find('div')
113
+ .should(($div) => {
114
+ if ($div.length !== 1) {
115
+ // you can throw your own errors
116
+ throw new Error('Did not find 1 element')
117
+ }
118
+
119
+ const className = $div[0].className
120
+
121
+ if (!className.match(/heading-/)) {
122
+ throw new Error(`Could not find class "heading-" in ${className}`)
123
+ }
124
+ })
125
+ })
126
+
127
+ it('matches unknown text between two elements', () => {
128
+ /**
129
+ * Text from the first element.
130
+ * @type {string}
131
+ */
132
+ let text
133
+
134
+ /**
135
+ * Normalizes passed text,
136
+ * useful before comparing text with spaces and different capitalization.
137
+ * @param {string} s Text to normalize
138
+ */
139
+ const normalizeText = (s) => s.replace(/\s/g, '').toLowerCase()
140
+
141
+ cy.get('.two-elements')
142
+ .find('.first')
143
+ .then(($first) => {
144
+ // save text from the first element
145
+ text = normalizeText($first.text())
146
+ })
147
+
148
+ cy.get('.two-elements')
149
+ .find('.second')
150
+ .should(($div) => {
151
+ // we can massage text before comparing
152
+ const secondText = normalizeText($div.text())
153
+
154
+ expect(secondText, 'second text').to.equal(text)
155
+ })
156
+ })
157
+
158
+ it('assert - assert shape of an object', () => {
159
+ const person = {
160
+ name: 'Joe',
161
+ age: 20,
162
+ }
163
+
164
+ assert.isObject(person, 'value is object')
165
+ })
166
+
167
+ it('retries the should callback until assertions pass', () => {
168
+ cy.get('#random-number')
169
+ .should(($div) => {
170
+ const n = parseFloat($div.text())
171
+
172
+ expect(n).to.be.gte(1).and.be.lte(10)
173
+ })
174
+ })
175
+ })
176
+ })
@@ -0,0 +1,98 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Connectors', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/connectors')
6
+ })
7
+
8
+ it('.each() - iterate over an array of elements', () => {
9
+ // https://on.cypress.io/each
10
+ cy.get('.connectors-each-ul>li')
11
+ .each(($el, index, $list) => {
12
+ console.log($el, index, $list)
13
+ })
14
+ })
15
+
16
+ it('.its() - get properties on the current subject', () => {
17
+ // https://on.cypress.io/its
18
+ cy.get('.connectors-its-ul>li')
19
+ // calls the 'length' property yielding that value
20
+ .its('length')
21
+ .should('be.gt', 2)
22
+ })
23
+
24
+ it('.invoke() - invoke a function on the current subject', () => {
25
+ // our div is hidden in our script.js
26
+ // $('.connectors-div').hide()
27
+ cy.get('.connectors-div').should('be.hidden')
28
+
29
+ // https://on.cypress.io/invoke
30
+ // call the jquery method 'show' on the 'div.container'
31
+ cy.get('.connectors-div').invoke('show')
32
+
33
+ cy.get('.connectors-div').should('be.visible')
34
+ })
35
+
36
+ it('.spread() - spread an array as individual args to callback function', () => {
37
+ // https://on.cypress.io/spread
38
+ const arr = ['foo', 'bar', 'baz']
39
+
40
+ cy.wrap(arr).spread((foo, bar, baz) => {
41
+ expect(foo).to.eq('foo')
42
+ expect(bar).to.eq('bar')
43
+ expect(baz).to.eq('baz')
44
+ })
45
+ })
46
+
47
+ describe('.then()', () => {
48
+ it('invokes a callback function with the current subject', () => {
49
+ // https://on.cypress.io/then
50
+ cy.get('.connectors-list > li')
51
+ .then(($lis) => {
52
+ expect($lis, '3 items').to.have.length(3)
53
+ expect($lis.eq(0), 'first item').to.contain('Walk the dog')
54
+ expect($lis.eq(1), 'second item').to.contain('Feed the cat')
55
+ expect($lis.eq(2), 'third item').to.contain('Write JavaScript')
56
+ })
57
+ })
58
+
59
+ it('yields the returned value to the next command', () => {
60
+ cy.wrap(1)
61
+ .then((num) => {
62
+ expect(num).to.equal(1)
63
+
64
+ return 2
65
+ })
66
+ .then((num) => {
67
+ expect(num).to.equal(2)
68
+ })
69
+ })
70
+
71
+ it('yields the original subject without return', () => {
72
+ cy.wrap(1)
73
+ .then((num) => {
74
+ expect(num).to.equal(1)
75
+ // note that nothing is returned from this callback
76
+ })
77
+ .then((num) => {
78
+ // this callback receives the original unchanged value 1
79
+ expect(num).to.equal(1)
80
+ })
81
+ })
82
+
83
+ it('yields the value yielded by the last Cypress command inside', () => {
84
+ cy.wrap(1)
85
+ .then((num) => {
86
+ expect(num).to.equal(1)
87
+ // note how we run a Cypress command
88
+ // the result yielded by this Cypress command
89
+ // will be passed to the second ".then"
90
+ cy.wrap(2)
91
+ })
92
+ .then((num) => {
93
+ // this callback receives the value yielded by "cy.wrap(2)"
94
+ expect(num).to.equal(2)
95
+ })
96
+ })
97
+ })
98
+ })