tonder-web-sdk 1.16.1 → 1.16.6-beta.DEV-1433.1

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 (105) hide show
  1. package/README.md +134 -40
  2. package/package.json +29 -6
  3. package/types/card.d.ts +17 -17
  4. package/types/checkout.d.ts +85 -87
  5. package/types/common.d.ts +8 -2
  6. package/types/customer.d.ts +10 -10
  7. package/types/index.d.ts +9 -11
  8. package/types/inlineCheckout.d.ts +81 -61
  9. package/types/liteInlineCheckout.d.ts +78 -83
  10. package/types/paymentMethod.d.ts +17 -17
  11. package/types/transaction.d.ts +94 -94
  12. package/v1/bundle.min.js +1 -18
  13. package/.env-example +0 -1
  14. package/cypress/e2e/1-getting-started/todo.cy.js +0 -143
  15. package/cypress/e2e/2-advanced-examples/actions.cy.js +0 -299
  16. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +0 -39
  17. package/cypress/e2e/2-advanced-examples/assertions.cy.js +0 -176
  18. package/cypress/e2e/2-advanced-examples/connectors.cy.js +0 -98
  19. package/cypress/e2e/2-advanced-examples/cookies.cy.js +0 -118
  20. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +0 -185
  21. package/cypress/e2e/2-advanced-examples/files.cy.js +0 -85
  22. package/cypress/e2e/2-advanced-examples/location.cy.js +0 -32
  23. package/cypress/e2e/2-advanced-examples/misc.cy.js +0 -104
  24. package/cypress/e2e/2-advanced-examples/navigation.cy.js +0 -56
  25. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +0 -163
  26. package/cypress/e2e/2-advanced-examples/querying.cy.js +0 -114
  27. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +0 -201
  28. package/cypress/e2e/2-advanced-examples/storage.cy.js +0 -110
  29. package/cypress/e2e/2-advanced-examples/traversal.cy.js +0 -121
  30. package/cypress/e2e/2-advanced-examples/utilities.cy.js +0 -108
  31. package/cypress/e2e/2-advanced-examples/viewport.cy.js +0 -58
  32. package/cypress/e2e/2-advanced-examples/waiting.cy.js +0 -30
  33. package/cypress/e2e/2-advanced-examples/window.cy.js +0 -22
  34. package/cypress/fixtures/example.json +0 -5
  35. package/cypress/support/commands.js +0 -25
  36. package/cypress/support/e2e.js +0 -20
  37. package/cypress.config.js +0 -9
  38. package/index.js.example +0 -50
  39. package/samples/react/README.md +0 -70
  40. package/samples/react/build/asset-manifest.json +0 -16
  41. package/samples/react/build/favicon.ico +0 -0
  42. package/samples/react/build/index.html +0 -1
  43. package/samples/react/build/logo192.png +0 -0
  44. package/samples/react/build/logo512.png +0 -0
  45. package/samples/react/build/manifest.json +0 -25
  46. package/samples/react/build/robots.txt +0 -3
  47. package/samples/react/build/static/css/main.073c9b0a.css +0 -2
  48. package/samples/react/build/static/css/main.073c9b0a.css.map +0 -1
  49. package/samples/react/build/static/js/787.b83ed06f.chunk.js +0 -2
  50. package/samples/react/build/static/js/787.b83ed06f.chunk.js.map +0 -1
  51. package/samples/react/build/static/js/main.0a848807.js +0 -3
  52. package/samples/react/build/static/js/main.0a848807.js.LICENSE.txt +0 -39
  53. package/samples/react/build/static/js/main.0a848807.js.map +0 -1
  54. package/samples/react/build/static/media/sdk-icons.b491623214b2af4cccdb.png +0 -0
  55. package/samples/react/package-lock.json +0 -28973
  56. package/samples/react/package.json +0 -44
  57. package/samples/react/public/favicon.ico +0 -0
  58. package/samples/react/public/index.html +0 -43
  59. package/samples/react/public/logo192.png +0 -0
  60. package/samples/react/public/logo512.png +0 -0
  61. package/samples/react/public/manifest.json +0 -25
  62. package/samples/react/public/robots.txt +0 -3
  63. package/samples/react/src/App.css +0 -38
  64. package/samples/react/src/App.js +0 -22
  65. package/samples/react/src/App.test.js +0 -8
  66. package/samples/react/src/assets/img/sdk-icons.png +0 -0
  67. package/samples/react/src/components/Cart.js +0 -29
  68. package/samples/react/src/components/ProductCard.js +0 -27
  69. package/samples/react/src/context/CartContext.js +0 -116
  70. package/samples/react/src/index.css +0 -13
  71. package/samples/react/src/index.js +0 -17
  72. package/samples/react/src/logo.svg +0 -1
  73. package/samples/react/src/reportWebVitals.js +0 -13
  74. package/samples/react/src/screens/Checkout.js +0 -82
  75. package/samples/react/src/screens/Store.js +0 -21
  76. package/samples/react/src/setupTests.js +0 -5
  77. package/samples/react/src/storeProducts.js +0 -30
  78. package/src/classes/3dsHandler.js +0 -203
  79. package/src/classes/BaseInlineCheckout.js +0 -324
  80. package/src/classes/LiteInlineCheckout.js +0 -220
  81. package/src/classes/checkout.js +0 -125
  82. package/src/classes/globalLoader.js +0 -29
  83. package/src/classes/inlineCheckout.js +0 -515
  84. package/src/data/apmApi.js +0 -44
  85. package/src/data/businessApi.js +0 -19
  86. package/src/data/cardApi.js +0 -143
  87. package/src/data/checkoutApi.js +0 -92
  88. package/src/data/customerApi.js +0 -37
  89. package/src/data/index.js +0 -17
  90. package/src/data/openPayApi.js +0 -16
  91. package/src/data/skyflowApi.js +0 -18
  92. package/src/helpers/skyflow.js +0 -361
  93. package/src/helpers/styles.js +0 -61
  94. package/src/helpers/template-skeleton.js +0 -59
  95. package/src/helpers/template.js +0 -743
  96. package/src/helpers/utils.js +0 -163
  97. package/src/helpers/validations.js +0 -54
  98. package/src/index-dev.js +0 -307
  99. package/src/index.html +0 -172
  100. package/src/index.js +0 -15
  101. package/src/shared/catalog/paymentMethodsCatalog.js +0 -247
  102. package/src/shared/constants/messages.js +0 -10
  103. package/src/shared/constants/paymentMethodAPM.js +0 -63
  104. package/src/shared/constants/tonderUrl.js +0 -8
  105. package/webpack.config.js +0 -77
package/.env-example DELETED
@@ -1 +0,0 @@
1
- BASE_URL=http://localhost:8000
@@ -1,143 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- // Welcome to Cypress!
4
- //
5
- // This spec file contains a variety of sample tests
6
- // for a todo list app that are designed to demonstrate
7
- // the power of writing tests in Cypress.
8
- //
9
- // To learn more about how Cypress works and
10
- // what makes it such an awesome testing tool,
11
- // please read our getting started guide:
12
- // https://on.cypress.io/introduction-to-cypress
13
-
14
- describe('example to-do app', () => {
15
- beforeEach(() => {
16
- // Cypress starts out with a blank slate for each test
17
- // so we must tell it to visit our website with the `cy.visit()` command.
18
- // Since we want to visit the same URL at the start of all our tests,
19
- // we include it in our beforeEach function so that it runs before each test
20
- cy.visit('https://example.cypress.io/todo')
21
- })
22
-
23
- it('displays two todo items by default', () => {
24
- // We use the `cy.get()` command to get all elements that match the selector.
25
- // Then, we use `should` to assert that there are two matched items,
26
- // which are the two default items.
27
- cy.get('.todo-list li').should('have.length', 2)
28
-
29
- // We can go even further and check that the default todos each contain
30
- // the correct text. We use the `first` and `last` functions
31
- // to get just the first and last matched elements individually,
32
- // and then perform an assertion with `should`.
33
- cy.get('.todo-list li').first().should('have.text', 'Pay electric bill')
34
- cy.get('.todo-list li').last().should('have.text', 'Walk the dog')
35
- })
36
-
37
- it('can add new todo items', () => {
38
- // We'll store our item text in a variable so we can reuse it
39
- const newItem = 'Feed the cat'
40
-
41
- // Let's get the input element and use the `type` command to
42
- // input our new list item. After typing the content of our item,
43
- // we need to type the enter key as well in order to submit the input.
44
- // This input has a data-test attribute so we'll use that to select the
45
- // element in accordance with best practices:
46
- // https://on.cypress.io/selecting-elements
47
- cy.get('[data-test=new-todo]').type(`${newItem}{enter}`)
48
-
49
- // Now that we've typed our new item, let's check that it actually was added to the list.
50
- // Since it's the newest item, it should exist as the last element in the list.
51
- // In addition, with the two default items, we should have a total of 3 elements in the list.
52
- // Since assertions yield the element that was asserted on,
53
- // we can chain both of these assertions together into a single statement.
54
- cy.get('.todo-list li')
55
- .should('have.length', 3)
56
- .last()
57
- .should('have.text', newItem)
58
- })
59
-
60
- it('can check off an item as completed', () => {
61
- // In addition to using the `get` command to get an element by selector,
62
- // we can also use the `contains` command to get an element by its contents.
63
- // However, this will yield the <label>, which is lowest-level element that contains the text.
64
- // In order to check the item, we'll find the <input> element for this <label>
65
- // by traversing up the dom to the parent element. From there, we can `find`
66
- // the child checkbox <input> element and use the `check` command to check it.
67
- cy.contains('Pay electric bill')
68
- .parent()
69
- .find('input[type=checkbox]')
70
- .check()
71
-
72
- // Now that we've checked the button, we can go ahead and make sure
73
- // that the list element is now marked as completed.
74
- // Again we'll use `contains` to find the <label> element and then use the `parents` command
75
- // to traverse multiple levels up the dom until we find the corresponding <li> element.
76
- // Once we get that element, we can assert that it has the completed class.
77
- cy.contains('Pay electric bill')
78
- .parents('li')
79
- .should('have.class', 'completed')
80
- })
81
-
82
- context('with a checked task', () => {
83
- beforeEach(() => {
84
- // We'll take the command we used above to check off an element
85
- // Since we want to perform multiple tests that start with checking
86
- // one element, we put it in the beforeEach hook
87
- // so that it runs at the start of every test.
88
- cy.contains('Pay electric bill')
89
- .parent()
90
- .find('input[type=checkbox]')
91
- .check()
92
- })
93
-
94
- it('can filter for uncompleted tasks', () => {
95
- // We'll click on the "active" button in order to
96
- // display only incomplete items
97
- cy.contains('Active').click()
98
-
99
- // After filtering, we can assert that there is only the one
100
- // incomplete item in the list.
101
- cy.get('.todo-list li')
102
- .should('have.length', 1)
103
- .first()
104
- .should('have.text', 'Walk the dog')
105
-
106
- // For good measure, let's also assert that the task we checked off
107
- // does not exist on the page.
108
- cy.contains('Pay electric bill').should('not.exist')
109
- })
110
-
111
- it('can filter for completed tasks', () => {
112
- // We can perform similar steps as the test above to ensure
113
- // that only completed tasks are shown
114
- cy.contains('Completed').click()
115
-
116
- cy.get('.todo-list li')
117
- .should('have.length', 1)
118
- .first()
119
- .should('have.text', 'Pay electric bill')
120
-
121
- cy.contains('Walk the dog').should('not.exist')
122
- })
123
-
124
- it('can delete all completed tasks', () => {
125
- // First, let's click the "Clear completed" button
126
- // `contains` is actually serving two purposes here.
127
- // First, it's ensuring that the button exists within the dom.
128
- // This button only appears when at least one task is checked
129
- // so this command is implicitly verifying that it does exist.
130
- // Second, it selects the button so we can click it.
131
- cy.contains('Clear completed').click()
132
-
133
- // Then we can make sure that there is only one element
134
- // in the list and our element does not exist
135
- cy.get('.todo-list li')
136
- .should('have.length', 1)
137
- .should('not.have.text', 'Pay electric bill')
138
-
139
- // Finally, make sure that the clear button no longer exists.
140
- cy.contains('Clear completed').should('not.exist')
141
- })
142
- })
143
- })
@@ -1,299 +0,0 @@
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')
13
- .type('fake@email.com').should('have.value', 'fake@email.com')
14
-
15
- // .type() with special character sequences
16
- .type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
17
- .type('{del}{selectall}{backspace}')
18
-
19
- // .type() with key modifiers
20
- .type('{alt}{option}') //these are equivalent
21
- .type('{ctrl}{control}') //these are equivalent
22
- .type('{meta}{command}{cmd}') //these are equivalent
23
- .type('{shift}')
24
-
25
- // Delay each keypress by 0.1 sec
26
- .type('slow.typing@email.com', { delay: 100 })
27
- .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
- .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
- .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').blur()
46
- .should('have.class', 'error')
47
- .prev().should('have.attr', 'style', 'color: red;')
48
- })
49
-
50
- it('.clear() - clears an input or textarea element', () => {
51
- // https://on.cypress.io/clear
52
- cy.get('.action-clear').type('Clear this text')
53
- .should('have.value', 'Clear this text')
54
- .clear()
55
- .should('have.value', '')
56
- })
57
-
58
- it('.submit() - submit a form', () => {
59
- // https://on.cypress.io/submit
60
- cy.get('.action-form')
61
- .find('[type="text"]').type('HALFOFF')
62
-
63
- cy.get('.action-form').submit()
64
- .next().should('contain', 'Your form has been submitted!')
65
- })
66
-
67
- it('.click() - click on a DOM element', () => {
68
- // https://on.cypress.io/click
69
- cy.get('.action-btn').click()
70
-
71
- // You can click on 9 specific positions of an element:
72
- // -----------------------------------
73
- // | topLeft top topRight |
74
- // | |
75
- // | |
76
- // | |
77
- // | left center right |
78
- // | |
79
- // | |
80
- // | |
81
- // | bottomLeft bottom bottomRight |
82
- // -----------------------------------
83
-
84
- // clicking in the center of the element is the default
85
- cy.get('#action-canvas').click()
86
-
87
- cy.get('#action-canvas').click('topLeft')
88
- cy.get('#action-canvas').click('top')
89
- cy.get('#action-canvas').click('topRight')
90
- cy.get('#action-canvas').click('left')
91
- cy.get('#action-canvas').click('right')
92
- cy.get('#action-canvas').click('bottomLeft')
93
- cy.get('#action-canvas').click('bottom')
94
- cy.get('#action-canvas').click('bottomRight')
95
-
96
- // .click() accepts an x and y coordinate
97
- // that controls where the click occurs :)
98
-
99
- cy.get('#action-canvas')
100
- .click(80, 75) // click 80px on x coord and 75px on y coord
101
- .click(170, 75)
102
- .click(80, 165)
103
- .click(100, 185)
104
- .click(125, 190)
105
- .click(150, 185)
106
- .click(170, 165)
107
-
108
- // click multiple elements by passing multiple: true
109
- cy.get('.action-labels>.label').click({ multiple: true })
110
-
111
- // Ignore error checking prior to clicking
112
- cy.get('.action-opacity>.btn').click({ force: true })
113
- })
114
-
115
- it('.dblclick() - double click on a DOM element', () => {
116
- // https://on.cypress.io/dblclick
117
-
118
- // Our app has a listener on 'dblclick' event in our 'scripts.js'
119
- // that hides the div and shows an input on double click
120
- cy.get('.action-div').dblclick().should('not.be.visible')
121
- cy.get('.action-input-hidden').should('be.visible')
122
- })
123
-
124
- it('.rightclick() - right click on a DOM element', () => {
125
- // https://on.cypress.io/rightclick
126
-
127
- // Our app has a listener on 'contextmenu' event in our 'scripts.js'
128
- // that hides the div and shows an input on right click
129
- cy.get('.rightclick-action-div').rightclick().should('not.be.visible')
130
- cy.get('.rightclick-action-input-hidden').should('be.visible')
131
- })
132
-
133
- it('.check() - check a checkbox or radio element', () => {
134
- // https://on.cypress.io/check
135
-
136
- // By default, .check() will check all
137
- // matching checkbox or radio elements in succession, one after another
138
- cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]')
139
- .check().should('be.checked')
140
-
141
- cy.get('.action-radios [type="radio"]').not('[disabled]')
142
- .check().should('be.checked')
143
-
144
- // .check() accepts a value argument
145
- cy.get('.action-radios [type="radio"]')
146
- .check('radio1').should('be.checked')
147
-
148
- // .check() accepts an array of values
149
- cy.get('.action-multiple-checkboxes [type="checkbox"]')
150
- .check(['checkbox1', 'checkbox2']).should('be.checked')
151
-
152
- // Ignore error checking prior to checking
153
- cy.get('.action-checkboxes [disabled]')
154
- .check({ force: true }).should('be.checked')
155
-
156
- cy.get('.action-radios [type="radio"]')
157
- .check('radio3', { force: true }).should('be.checked')
158
- })
159
-
160
- it('.uncheck() - uncheck a checkbox element', () => {
161
- // https://on.cypress.io/uncheck
162
-
163
- // By default, .uncheck() will uncheck all matching
164
- // checkbox elements in succession, one after another
165
- cy.get('.action-check [type="checkbox"]')
166
- .not('[disabled]')
167
- .uncheck().should('not.be.checked')
168
-
169
- // .uncheck() accepts a value argument
170
- cy.get('.action-check [type="checkbox"]')
171
- .check('checkbox1')
172
- .uncheck('checkbox1').should('not.be.checked')
173
-
174
- // .uncheck() accepts an array of values
175
- cy.get('.action-check [type="checkbox"]')
176
- .check(['checkbox1', 'checkbox3'])
177
- .uncheck(['checkbox1', 'checkbox3']).should('not.be.checked')
178
-
179
- // Ignore error checking prior to unchecking
180
- cy.get('.action-check [disabled]')
181
- .uncheck({ force: true }).should('not.be.checked')
182
- })
183
-
184
- it('.select() - select an option in a <select> element', () => {
185
- // https://on.cypress.io/select
186
-
187
- // at first, no option should be selected
188
- cy.get('.action-select')
189
- .should('have.value', '--Select a fruit--')
190
-
191
- // Select option(s) with matching text content
192
- cy.get('.action-select').select('apples')
193
- // confirm the apples were selected
194
- // note that each value starts with "fr-" in our HTML
195
- cy.get('.action-select').should('have.value', 'fr-apples')
196
-
197
- cy.get('.action-select-multiple')
198
- .select(['apples', 'oranges', 'bananas'])
199
- // when getting multiple values, invoke "val" method first
200
- .invoke('val')
201
- .should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
202
-
203
- // Select option(s) with matching value
204
- cy.get('.action-select').select('fr-bananas')
205
- // can attach an assertion right away to the element
206
- .should('have.value', 'fr-bananas')
207
-
208
- cy.get('.action-select-multiple')
209
- .select(['fr-apples', 'fr-oranges', 'fr-bananas'])
210
- .invoke('val')
211
- .should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
212
-
213
- // assert the selected values include oranges
214
- cy.get('.action-select-multiple')
215
- .invoke('val').should('include', 'fr-oranges')
216
- })
217
-
218
- it('.scrollIntoView() - scroll an element into view', () => {
219
- // https://on.cypress.io/scrollintoview
220
-
221
- // normally all of these buttons are hidden,
222
- // because they're not within
223
- // the viewable area of their parent
224
- // (we need to scroll to see them)
225
- cy.get('#scroll-horizontal button')
226
- .should('not.be.visible')
227
-
228
- // scroll the button into view, as if the user had scrolled
229
- cy.get('#scroll-horizontal button').scrollIntoView()
230
- .should('be.visible')
231
-
232
- cy.get('#scroll-vertical button')
233
- .should('not.be.visible')
234
-
235
- // Cypress handles the scroll direction needed
236
- cy.get('#scroll-vertical button').scrollIntoView()
237
- .should('be.visible')
238
-
239
- cy.get('#scroll-both button')
240
- .should('not.be.visible')
241
-
242
- // Cypress knows to scroll to the right and down
243
- cy.get('#scroll-both button').scrollIntoView()
244
- .should('be.visible')
245
- })
246
-
247
- it('.trigger() - trigger an event on a DOM element', () => {
248
- // https://on.cypress.io/trigger
249
-
250
- // To interact with a range input (slider)
251
- // we need to set its value & trigger the
252
- // event to signal it changed
253
-
254
- // Here, we invoke jQuery's val() method to set
255
- // the value and trigger the 'change' event
256
- cy.get('.trigger-input-range')
257
- .invoke('val', 25)
258
- .trigger('change')
259
- .get('input[type=range]').siblings('p')
260
- .should('have.text', '25')
261
- })
262
-
263
- it('cy.scrollTo() - scroll the window or element to a position', () => {
264
- // https://on.cypress.io/scrollto
265
-
266
- // You can scroll to 9 specific positions of an element:
267
- // -----------------------------------
268
- // | topLeft top topRight |
269
- // | |
270
- // | |
271
- // | |
272
- // | left center right |
273
- // | |
274
- // | |
275
- // | |
276
- // | bottomLeft bottom bottomRight |
277
- // -----------------------------------
278
-
279
- // if you chain .scrollTo() off of cy, we will
280
- // scroll the entire window
281
- cy.scrollTo('bottom')
282
-
283
- cy.get('#scrollable-horizontal').scrollTo('right')
284
-
285
- // or you can scroll to a specific coordinate:
286
- // (x axis, y axis) in pixels
287
- cy.get('#scrollable-vertical').scrollTo(250, 250)
288
-
289
- // or you can scroll to a specific percentage
290
- // of the (width, height) of the element
291
- cy.get('#scrollable-both').scrollTo('75%', '25%')
292
-
293
- // control the easing of the scroll (default is 'swing')
294
- cy.get('#scrollable-vertical').scrollTo('center', { easing: 'linear' })
295
-
296
- // control the duration of the scroll (in ms)
297
- cy.get('#scrollable-both').scrollTo('center', { duration: 2000 })
298
- })
299
- })
@@ -1,39 +0,0 @@
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
- })
@@ -1,176 +0,0 @@
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
- })