tonder-web-sdk 1.4.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 (83) hide show
  1. package/.env-example +1 -0
  2. package/.htaccess +1 -0
  3. package/README.md +204 -0
  4. package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
  5. package/cypress/e2e/2-advanced-examples/actions.cy.js +299 -0
  6. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
  7. package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
  8. package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
  9. package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
  10. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +185 -0
  11. package/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
  12. package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
  13. package/cypress/e2e/2-advanced-examples/misc.cy.js +104 -0
  14. package/cypress/e2e/2-advanced-examples/navigation.cy.js +56 -0
  15. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
  16. package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
  17. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +201 -0
  18. package/cypress/e2e/2-advanced-examples/storage.cy.js +110 -0
  19. package/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
  20. package/cypress/e2e/2-advanced-examples/utilities.cy.js +108 -0
  21. package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
  22. package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
  23. package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
  24. package/cypress/fixtures/example.json +5 -0
  25. package/cypress/support/commands.js +25 -0
  26. package/cypress/support/e2e.js +20 -0
  27. package/cypress.config.js +9 -0
  28. package/index.html +178 -0
  29. package/index.js.example +50 -0
  30. package/package.json +29 -0
  31. package/samples/react/README.md +70 -0
  32. package/samples/react/build/asset-manifest.json +16 -0
  33. package/samples/react/build/favicon.ico +0 -0
  34. package/samples/react/build/index.html +1 -0
  35. package/samples/react/build/logo192.png +0 -0
  36. package/samples/react/build/logo512.png +0 -0
  37. package/samples/react/build/manifest.json +25 -0
  38. package/samples/react/build/robots.txt +3 -0
  39. package/samples/react/build/static/css/main.073c9b0a.css +2 -0
  40. package/samples/react/build/static/css/main.073c9b0a.css.map +1 -0
  41. package/samples/react/build/static/js/787.b83ed06f.chunk.js +2 -0
  42. package/samples/react/build/static/js/787.b83ed06f.chunk.js.map +1 -0
  43. package/samples/react/build/static/js/main.0a848807.js +3 -0
  44. package/samples/react/build/static/js/main.0a848807.js.LICENSE.txt +39 -0
  45. package/samples/react/build/static/js/main.0a848807.js.map +1 -0
  46. package/samples/react/build/static/media/sdk-icons.b491623214b2af4cccdb.png +0 -0
  47. package/samples/react/package-lock.json +28973 -0
  48. package/samples/react/package.json +44 -0
  49. package/samples/react/public/favicon.ico +0 -0
  50. package/samples/react/public/index.html +43 -0
  51. package/samples/react/public/logo192.png +0 -0
  52. package/samples/react/public/logo512.png +0 -0
  53. package/samples/react/public/manifest.json +25 -0
  54. package/samples/react/public/robots.txt +3 -0
  55. package/samples/react/src/App.css +38 -0
  56. package/samples/react/src/App.js +22 -0
  57. package/samples/react/src/App.test.js +8 -0
  58. package/samples/react/src/assets/img/sdk-icons.png +0 -0
  59. package/samples/react/src/components/Cart.js +29 -0
  60. package/samples/react/src/components/ProductCard.js +27 -0
  61. package/samples/react/src/context/CartContext.js +116 -0
  62. package/samples/react/src/index.css +13 -0
  63. package/samples/react/src/index.js +17 -0
  64. package/samples/react/src/logo.svg +1 -0
  65. package/samples/react/src/reportWebVitals.js +13 -0
  66. package/samples/react/src/screens/Checkout.js +82 -0
  67. package/samples/react/src/screens/Store.js +21 -0
  68. package/samples/react/src/setupTests.js +5 -0
  69. package/samples/react/src/storeProducts.js +30 -0
  70. package/src/classes/3dsHandler.js +203 -0
  71. package/src/classes/checkout.js +125 -0
  72. package/src/classes/inlineCheckout.js +349 -0
  73. package/src/data/api.js +109 -0
  74. package/src/helpers/skyflow.js +139 -0
  75. package/src/helpers/styles.js +61 -0
  76. package/src/helpers/template.js +112 -0
  77. package/src/helpers/utils.js +68 -0
  78. package/src/index-dev.js +129 -0
  79. package/src/index.html +58 -0
  80. package/src/index.js +7 -0
  81. package/success.html +22 -0
  82. package/v1/bundle.min.js +18 -0
  83. package/webpack.config.js +66 -0
package/.env-example ADDED
@@ -0,0 +1 @@
1
+ BASE_URL=http://localhost:8000
package/.htaccess ADDED
@@ -0,0 +1 @@
1
+ DirectoryIndex index.html
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Tonder SDK
2
+
3
+ Tonder SDK helps to integrate the services Tonder offers in your own website
4
+
5
+ ## Installation
6
+
7
+ You can install using NPM
8
+ ```bash
9
+ npm i tonder-web-sdk
10
+ ```
11
+
12
+ or using an script tag
13
+ ```html
14
+ <script src="https://zplit-stage.s3.amazonaws.com/v1/bundle.min.js"></script>
15
+ ```
16
+
17
+ Add dependencies to the root of the app (index.html)
18
+ ```html
19
+ <script src="https://js.skyflow.com/v1/index.js"></script>
20
+ <script src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>
21
+ <script src="https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"></script>
22
+ ```
23
+
24
+ ## Usage
25
+ HTML
26
+ ```html
27
+ <div>
28
+ <h1>Checkout</h1>
29
+ <!-- You have to add an entry point with the ID 'tonder-checkout' -->
30
+ <div id="tonder-checkout">
31
+ </div>
32
+ </div>
33
+ ```
34
+ ## Javascript Example
35
+ ```javascript
36
+ import { InlineCheckout } from "tonder-web-sdk" // Not required if using script tag
37
+ ```
38
+
39
+
40
+ ```javascript
41
+ const customStyles = {
42
+ inputStyles: {
43
+ base: {
44
+ border: "1px solid #e0e0e0",
45
+ padding: "10px 7px",
46
+ borderRadius: "5px",
47
+ color: "#1d1d1d",
48
+ marginTop: "2px",
49
+ backgroundColor: "white",
50
+ fontFamily: '"Inter", sans-serif',
51
+ fontSize: '16px',
52
+ '&::placeholder': {
53
+ color: "#ccc",
54
+ },
55
+ },
56
+ cardIcon: {
57
+ position: 'absolute',
58
+ left: '6px',
59
+ bottom: 'calc(50% - 12px)',
60
+ },
61
+ complete: {
62
+ color: "#4caf50",
63
+ },
64
+ empty: {},
65
+ focus: {},
66
+ invalid: {
67
+ border: "1px solid #f44336",
68
+ },
69
+ global: {
70
+ '@import': 'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
71
+ }
72
+ },
73
+ labelStyles: {
74
+ base: {
75
+ fontSize: '12px',
76
+ fontWeight: '500',
77
+ fontFamily: '"Inter", sans-serif'
78
+ },
79
+ },
80
+ errorTextStyles: {
81
+ base: {
82
+ fontSize: '12px',
83
+ fontWeight: '500',
84
+ color: "#f44336",
85
+ fontFamily: '"Inter", sans-serif'
86
+ },
87
+ },
88
+ labels: {
89
+ nameLabel: 'Titular de la tarjeta',
90
+ cardLabel: 'Número de tarjeta',
91
+ cvvLabel: 'CVC/CVV',
92
+ expiryDateLabel: 'Fecha de expiración',
93
+ },
94
+ placeholders: {
95
+ namePlaceholder: 'Nombre como aparece en la tarjeta',
96
+ cardPlaceholder: '1234 1234 1234 1234',
97
+ cvvPlaceholder: '3-4 dígitos',
98
+ expiryMonthPlaceholder: 'MM',
99
+ expiryYearPlaceholder: 'AA'
100
+ }
101
+ }
102
+
103
+ const checkoutData = {
104
+ customer: {
105
+ firstName: "Juan",
106
+ lastName: "Hernández",
107
+ country: "Mexico",
108
+ address: "Av. Revolución 356, Col. Roma",
109
+ city: "Monterrey",
110
+ state: "Nuevo León",
111
+ postCode: "64700",
112
+ email: "juan.hernandez@mail.com",
113
+ phone: "8187654321",
114
+ },
115
+ currency: 'mxn',
116
+ cart: {
117
+ total: 399,
118
+ items: [
119
+ {
120
+ description: "Black T-Shirt",
121
+ quantity: 1,
122
+ price_unit: 1,
123
+ discount: 0,
124
+ taxes: 0,
125
+ product_reference: 1,
126
+ name: "T-Shirt",
127
+ amount_total: 399,
128
+ },
129
+ ]
130
+ },
131
+ metadata: {
132
+ order_id: 123456
133
+ },
134
+ card: {
135
+ skyflow_id: "12340120349123049",
136
+ }
137
+ };
138
+
139
+ const apiKey = "4c87c36e697e65ddfe288be0afbe7967ea0ab865";
140
+ const returnUrl = "http://my-website:8080/checkout"
141
+ const successUrl = "http://my-website:8080/success"
142
+ // if using script tag, it should be initialized like this
143
+ // new TonderSdk.InlineCheckout
144
+ const inlineCheckout = new InlineCheckout({
145
+ apiKey,
146
+ returnUrl,
147
+ successUrl,
148
+ styles: customStyles
149
+ });
150
+
151
+ inlineCheckout.injectCheckout();
152
+
153
+ const response = await inlineCheckout.payment(checkoutData);
154
+ ```
155
+
156
+ ## React Example
157
+ ```javascript
158
+ ```
159
+
160
+ ## Configuration
161
+ | Property | Type | Description |
162
+ |:---------------:|:-------------:|:---------------------------------------------------:|
163
+ | apiKey | string | You can take this from you Tonder Dashboard |
164
+ | backgroundColor | string | Hex color #000000 |
165
+ | returnUrl | string | |
166
+ | successUrl | string | |
167
+ | backgroundColor | string | |
168
+
169
+ ## setPayment params
170
+ ### products
171
+ It will receive an array of objects that represent the products.
172
+ ```javascript
173
+ [
174
+ {
175
+ name: 'name of the product',
176
+ price_unit: 'valid float string with the price of the product',
177
+ quantity: 'valid integer strig with the quantity of this product',
178
+ }
179
+ ]
180
+ ```
181
+ ### shippingCost
182
+ It is a valid float string, that will be the shipping cost.
183
+
184
+ ### email
185
+ The email of the customer that is making the purchase.
186
+
187
+ ### apiKey
188
+ Your api key getted from Tonder Dashboard
189
+
190
+ ### customer
191
+ The data of the customer to be registered in the transaction
192
+
193
+ ### items
194
+ An array of items to be registered in the Tonder order.
195
+
196
+ ### Mount element
197
+ You need to have an element where the inline checkout will be mounted, this should be a DIV element with the ID "tonder-checkout"
198
+
199
+ ```html
200
+ <div id="tonder-checkout"></div>
201
+ ```
202
+ ## License
203
+
204
+ [MIT](https://choosealicense.com/licenses/mit/)
@@ -0,0 +1,143 @@
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
+ })
@@ -0,0 +1,299 @@
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
+ })
@@ -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
+ })