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
@@ -1,163 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- context('Network Requests', () => {
4
- beforeEach(() => {
5
- cy.visit('https://example.cypress.io/commands/network-requests')
6
- })
7
-
8
- // Manage HTTP requests in your app
9
-
10
- it('cy.request() - make an XHR request', () => {
11
- // https://on.cypress.io/request
12
- cy.request('https://jsonplaceholder.cypress.io/comments')
13
- .should((response) => {
14
- expect(response.status).to.eq(200)
15
- // the server sometimes gets an extra comment posted from another machine
16
- // which gets returned as 1 extra object
17
- expect(response.body).to.have.property('length').and.be.oneOf([500, 501])
18
- expect(response).to.have.property('headers')
19
- expect(response).to.have.property('duration')
20
- })
21
- })
22
-
23
- it('cy.request() - verify response using BDD syntax', () => {
24
- cy.request('https://jsonplaceholder.cypress.io/comments')
25
- .then((response) => {
26
- // https://on.cypress.io/assertions
27
- expect(response).property('status').to.equal(200)
28
- expect(response).property('body').to.have.property('length').and.be.oneOf([500, 501])
29
- expect(response).to.include.keys('headers', 'duration')
30
- })
31
- })
32
-
33
- it('cy.request() with query parameters', () => {
34
- // will execute request
35
- // https://jsonplaceholder.cypress.io/comments?postId=1&id=3
36
- cy.request({
37
- url: 'https://jsonplaceholder.cypress.io/comments',
38
- qs: {
39
- postId: 1,
40
- id: 3,
41
- },
42
- })
43
- .its('body')
44
- .should('be.an', 'array')
45
- .and('have.length', 1)
46
- .its('0') // yields first element of the array
47
- .should('contain', {
48
- postId: 1,
49
- id: 3,
50
- })
51
- })
52
-
53
- it('cy.request() - pass result to the second request', () => {
54
- // first, let's find out the userId of the first user we have
55
- cy.request('https://jsonplaceholder.cypress.io/users?_limit=1')
56
- .its('body') // yields the response object
57
- .its('0') // yields the first element of the returned list
58
- // the above two commands its('body').its('0')
59
- // can be written as its('body.0')
60
- // if you do not care about TypeScript checks
61
- .then((user) => {
62
- expect(user).property('id').to.be.a('number')
63
- // make a new post on behalf of the user
64
- cy.request('POST', 'https://jsonplaceholder.cypress.io/posts', {
65
- userId: user.id,
66
- title: 'Cypress Test Runner',
67
- body: 'Fast, easy and reliable testing for anything that runs in a browser.',
68
- })
69
- })
70
- // note that the value here is the returned value of the 2nd request
71
- // which is the new post object
72
- .then((response) => {
73
- expect(response).property('status').to.equal(201) // new entity created
74
- expect(response).property('body').to.contain({
75
- title: 'Cypress Test Runner',
76
- })
77
-
78
- // we don't know the exact post id - only that it will be > 100
79
- // since JSONPlaceholder has built-in 100 posts
80
- expect(response.body).property('id').to.be.a('number')
81
- .and.to.be.gt(100)
82
-
83
- // we don't know the user id here - since it was in above closure
84
- // so in this test just confirm that the property is there
85
- expect(response.body).property('userId').to.be.a('number')
86
- })
87
- })
88
-
89
- it('cy.request() - save response in the shared test context', () => {
90
- // https://on.cypress.io/variables-and-aliases
91
- cy.request('https://jsonplaceholder.cypress.io/users?_limit=1')
92
- .its('body').its('0') // yields the first element of the returned list
93
- .as('user') // saves the object in the test context
94
- .then(function () {
95
- // NOTE 👀
96
- // By the time this callback runs the "as('user')" command
97
- // has saved the user object in the test context.
98
- // To access the test context we need to use
99
- // the "function () { ... }" callback form,
100
- // otherwise "this" points at a wrong or undefined object!
101
- cy.request('POST', 'https://jsonplaceholder.cypress.io/posts', {
102
- userId: this.user.id,
103
- title: 'Cypress Test Runner',
104
- body: 'Fast, easy and reliable testing for anything that runs in a browser.',
105
- })
106
- .its('body').as('post') // save the new post from the response
107
- })
108
- .then(function () {
109
- // When this callback runs, both "cy.request" API commands have finished
110
- // and the test context has "user" and "post" objects set.
111
- // Let's verify them.
112
- expect(this.post, 'post has the right user id').property('userId').to.equal(this.user.id)
113
- })
114
- })
115
-
116
- it('cy.intercept() - route responses to matching requests', () => {
117
- // https://on.cypress.io/intercept
118
-
119
- let message = 'whoa, this comment does not exist'
120
-
121
- // Listen to GET to comments/1
122
- cy.intercept('GET', '**/comments/*').as('getComment')
123
-
124
- // we have code that gets a comment when
125
- // the button is clicked in scripts.js
126
- cy.get('.network-btn').click()
127
-
128
- // https://on.cypress.io/wait
129
- cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])
130
-
131
- // Listen to POST to comments
132
- cy.intercept('POST', '**/comments').as('postComment')
133
-
134
- // we have code that posts a comment when
135
- // the button is clicked in scripts.js
136
- cy.get('.network-post').click()
137
- cy.wait('@postComment').should(({ request, response }) => {
138
- expect(request.body).to.include('email')
139
- expect(request.headers).to.have.property('content-type')
140
- expect(response && response.body).to.have.property('name', 'Using POST in cy.intercept()')
141
- })
142
-
143
- // Stub a response to PUT comments/ ****
144
- cy.intercept({
145
- method: 'PUT',
146
- url: '**/comments/*',
147
- }, {
148
- statusCode: 404,
149
- body: { error: message },
150
- headers: { 'access-control-allow-origin': '*' },
151
- delayMs: 500,
152
- }).as('putComment')
153
-
154
- // we have code that puts a comment when
155
- // the button is clicked in scripts.js
156
- cy.get('.network-put').click()
157
-
158
- cy.wait('@putComment')
159
-
160
- // our 404 statusCode logic in scripts.js executed
161
- cy.get('.network-put-comment').should('contain', message)
162
- })
163
- })
@@ -1,114 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- context('Querying', () => {
4
- beforeEach(() => {
5
- cy.visit('https://example.cypress.io/commands/querying')
6
- })
7
-
8
- // The most commonly used query is 'cy.get()', you can
9
- // think of this like the '$' in jQuery
10
-
11
- it('cy.get() - query DOM elements', () => {
12
- // https://on.cypress.io/get
13
-
14
- cy.get('#query-btn').should('contain', 'Button')
15
-
16
- cy.get('.query-btn').should('contain', 'Button')
17
-
18
- cy.get('#querying .well>button:first').should('contain', 'Button')
19
- // ↲
20
- // Use CSS selectors just like jQuery
21
-
22
- cy.get('[data-test-id="test-example"]').should('have.class', 'example')
23
-
24
- // 'cy.get()' yields jQuery object, you can get its attribute
25
- // by invoking `.attr()` method
26
- cy.get('[data-test-id="test-example"]')
27
- .invoke('attr', 'data-test-id')
28
- .should('equal', 'test-example')
29
-
30
- // or you can get element's CSS property
31
- cy.get('[data-test-id="test-example"]')
32
- .invoke('css', 'position')
33
- .should('equal', 'static')
34
-
35
- // or use assertions directly during 'cy.get()'
36
- // https://on.cypress.io/assertions
37
- cy.get('[data-test-id="test-example"]')
38
- .should('have.attr', 'data-test-id', 'test-example')
39
- .and('have.css', 'position', 'static')
40
- })
41
-
42
- it('cy.contains() - query DOM elements with matching content', () => {
43
- // https://on.cypress.io/contains
44
- cy.get('.query-list')
45
- .contains('bananas')
46
- .should('have.class', 'third')
47
-
48
- // we can pass a regexp to `.contains()`
49
- cy.get('.query-list')
50
- .contains(/^b\w+/)
51
- .should('have.class', 'third')
52
-
53
- cy.get('.query-list')
54
- .contains('apples')
55
- .should('have.class', 'first')
56
-
57
- // passing a selector to contains will
58
- // yield the selector containing the text
59
- cy.get('#querying')
60
- .contains('ul', 'oranges')
61
- .should('have.class', 'query-list')
62
-
63
- cy.get('.query-button')
64
- .contains('Save Form')
65
- .should('have.class', 'btn')
66
- })
67
-
68
- it('.within() - query DOM elements within a specific element', () => {
69
- // https://on.cypress.io/within
70
- cy.get('.query-form').within(() => {
71
- cy.get('input:first').should('have.attr', 'placeholder', 'Email')
72
- cy.get('input:last').should('have.attr', 'placeholder', 'Password')
73
- })
74
- })
75
-
76
- it('cy.root() - query the root DOM element', () => {
77
- // https://on.cypress.io/root
78
-
79
- // By default, root is the document
80
- cy.root().should('match', 'html')
81
-
82
- cy.get('.query-ul').within(() => {
83
- // In this within, the root is now the ul DOM element
84
- cy.root().should('have.class', 'query-ul')
85
- })
86
- })
87
-
88
- it('best practices - selecting elements', () => {
89
- // https://on.cypress.io/best-practices#Selecting-Elements
90
- cy.get('[data-cy=best-practices-selecting-elements]').within(() => {
91
- // Worst - too generic, no context
92
- cy.get('button').click()
93
-
94
- // Bad. Coupled to styling. Highly subject to change.
95
- cy.get('.btn.btn-large').click()
96
-
97
- // Average. Coupled to the `name` attribute which has HTML semantics.
98
- cy.get('[name=submission]').click()
99
-
100
- // Better. But still coupled to styling or JS event listeners.
101
- cy.get('#main').click()
102
-
103
- // Slightly better. Uses an ID but also ensures the element
104
- // has an ARIA role attribute
105
- cy.get('#main[role=button]').click()
106
-
107
- // Much better. But still coupled to text content that may change.
108
- cy.contains('Submit').click()
109
-
110
- // Best. Insulated from all changes.
111
- cy.get('[data-cy=submit]').click()
112
- })
113
- })
114
- })
@@ -1,201 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- context('Spies, Stubs, and Clock', () => {
4
- it('cy.spy() - wrap a method in a spy', () => {
5
- // https://on.cypress.io/spy
6
- cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
7
-
8
- const obj = {
9
- foo () {},
10
- }
11
-
12
- const spy = cy.spy(obj, 'foo').as('anyArgs')
13
-
14
- obj.foo()
15
-
16
- expect(spy).to.be.called
17
- })
18
-
19
- it('cy.spy() retries until assertions pass', () => {
20
- cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
21
-
22
- const obj = {
23
- /**
24
- * Prints the argument passed
25
- * @param x {any}
26
- */
27
- foo (x) {
28
- console.log('obj.foo called with', x)
29
- },
30
- }
31
-
32
- cy.spy(obj, 'foo').as('foo')
33
-
34
- setTimeout(() => {
35
- obj.foo('first')
36
- }, 500)
37
-
38
- setTimeout(() => {
39
- obj.foo('second')
40
- }, 2500)
41
-
42
- cy.get('@foo').should('have.been.calledTwice')
43
- })
44
-
45
- it('cy.stub() - create a stub and/or replace a function with stub', () => {
46
- // https://on.cypress.io/stub
47
- cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
48
-
49
- const obj = {
50
- /**
51
- * prints both arguments to the console
52
- * @param a {string}
53
- * @param b {string}
54
- */
55
- foo (a, b) {
56
- console.log('a', a, 'b', b)
57
- },
58
- }
59
-
60
- const stub = cy.stub(obj, 'foo').as('foo')
61
-
62
- obj.foo('foo', 'bar')
63
-
64
- expect(stub).to.be.called
65
- })
66
-
67
- it('cy.clock() - control time in the browser', () => {
68
- // https://on.cypress.io/clock
69
-
70
- // create the date in UTC so its always the same
71
- // no matter what local timezone the browser is running in
72
- const now = new Date(Date.UTC(2017, 2, 14)).getTime()
73
-
74
- cy.clock(now)
75
- cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
76
- cy.get('#clock-div').click()
77
- .should('have.text', '1489449600')
78
- })
79
-
80
- it('cy.tick() - move time in the browser', () => {
81
- // https://on.cypress.io/tick
82
-
83
- // create the date in UTC so its always the same
84
- // no matter what local timezone the browser is running in
85
- const now = new Date(Date.UTC(2017, 2, 14)).getTime()
86
-
87
- cy.clock(now)
88
- cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
89
- cy.get('#tick-div').click()
90
- .should('have.text', '1489449600')
91
-
92
- cy.tick(10000) // 10 seconds passed
93
- cy.get('#tick-div').click()
94
- .should('have.text', '1489449610')
95
- })
96
-
97
- it('cy.stub() matches depending on arguments', () => {
98
- // see all possible matchers at
99
- // https://sinonjs.org/releases/latest/matchers/
100
- const greeter = {
101
- /**
102
- * Greets a person
103
- * @param {string} name
104
- */
105
- greet (name) {
106
- return `Hello, ${name}!`
107
- },
108
- }
109
-
110
- cy.stub(greeter, 'greet')
111
- .callThrough() // if you want non-matched calls to call the real method
112
- .withArgs(Cypress.sinon.match.string).returns('Hi')
113
- .withArgs(Cypress.sinon.match.number).throws(new Error('Invalid name'))
114
-
115
- expect(greeter.greet('World')).to.equal('Hi')
116
- expect(() => greeter.greet(42)).to.throw('Invalid name')
117
- expect(greeter.greet).to.have.been.calledTwice
118
-
119
- // non-matched calls goes the actual method
120
- expect(greeter.greet()).to.equal('Hello, undefined!')
121
- })
122
-
123
- it('matches call arguments using Sinon matchers', () => {
124
- // see all possible matchers at
125
- // https://sinonjs.org/releases/latest/matchers/
126
- const calculator = {
127
- /**
128
- * returns the sum of two arguments
129
- * @param a {number}
130
- * @param b {number}
131
- */
132
- add (a, b) {
133
- return a + b
134
- },
135
- }
136
-
137
- const spy = cy.spy(calculator, 'add').as('add')
138
-
139
- expect(calculator.add(2, 3)).to.equal(5)
140
-
141
- // if we want to assert the exact values used during the call
142
- expect(spy).to.be.calledWith(2, 3)
143
-
144
- // let's confirm "add" method was called with two numbers
145
- expect(spy).to.be.calledWith(Cypress.sinon.match.number, Cypress.sinon.match.number)
146
-
147
- // alternatively, provide the value to match
148
- expect(spy).to.be.calledWith(Cypress.sinon.match(2), Cypress.sinon.match(3))
149
-
150
- // match any value
151
- expect(spy).to.be.calledWith(Cypress.sinon.match.any, 3)
152
-
153
- // match any value from a list
154
- expect(spy).to.be.calledWith(Cypress.sinon.match.in([1, 2, 3]), 3)
155
-
156
- /**
157
- * Returns true if the given number is even
158
- * @param {number} x
159
- */
160
- const isEven = (x) => x % 2 === 0
161
-
162
- // expect the value to pass a custom predicate function
163
- // the second argument to "sinon.match(predicate, message)" is
164
- // shown if the predicate does not pass and assertion fails
165
- expect(spy).to.be.calledWith(Cypress.sinon.match(isEven, 'isEven'), 3)
166
-
167
- /**
168
- * Returns a function that checks if a given number is larger than the limit
169
- * @param {number} limit
170
- * @returns {(x: number) => boolean}
171
- */
172
- const isGreaterThan = (limit) => (x) => x > limit
173
-
174
- /**
175
- * Returns a function that checks if a given number is less than the limit
176
- * @param {number} limit
177
- * @returns {(x: number) => boolean}
178
- */
179
- const isLessThan = (limit) => (x) => x < limit
180
-
181
- // you can combine several matchers using "and", "or"
182
- expect(spy).to.be.calledWith(
183
- Cypress.sinon.match.number,
184
- Cypress.sinon.match(isGreaterThan(2), '> 2').and(Cypress.sinon.match(isLessThan(4), '< 4')),
185
- )
186
-
187
- expect(spy).to.be.calledWith(
188
- Cypress.sinon.match.number,
189
- Cypress.sinon.match(isGreaterThan(200), '> 200').or(Cypress.sinon.match(3)),
190
- )
191
-
192
- // matchers can be used from BDD assertions
193
- cy.get('@add').should('have.been.calledWith',
194
- Cypress.sinon.match.number, Cypress.sinon.match(3))
195
-
196
- // you can alias matchers for shorter test code
197
- const { match: M } = Cypress.sinon
198
-
199
- cy.get('@add').should('have.been.calledWith', M.number, M(3))
200
- })
201
- })
@@ -1,110 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- context('Local Storage / Session Storage', () => {
4
- beforeEach(() => {
5
- cy.visit('https://example.cypress.io/commands/storage')
6
- })
7
- // Although localStorage is automatically cleared
8
- // in between tests to maintain a clean state
9
- // sometimes we need to clear localStorage manually
10
-
11
- it('cy.clearLocalStorage() - clear all data in localStorage for the current origin', () => {
12
- // https://on.cypress.io/clearlocalstorage
13
- cy.get('.ls-btn').click().should(() => {
14
- expect(localStorage.getItem('prop1')).to.eq('red')
15
- expect(localStorage.getItem('prop2')).to.eq('blue')
16
- expect(localStorage.getItem('prop3')).to.eq('magenta')
17
- })
18
-
19
- // clearLocalStorage() yields the localStorage object
20
- cy.clearLocalStorage().should((ls) => {
21
- expect(ls.getItem('prop1')).to.be.null
22
- expect(ls.getItem('prop2')).to.be.null
23
- expect(ls.getItem('prop3')).to.be.null
24
- })
25
-
26
- cy.get('.ls-btn').click().should(() => {
27
- expect(localStorage.getItem('prop1')).to.eq('red')
28
- expect(localStorage.getItem('prop2')).to.eq('blue')
29
- expect(localStorage.getItem('prop3')).to.eq('magenta')
30
- })
31
-
32
- // Clear key matching string in localStorage
33
- cy.clearLocalStorage('prop1').should((ls) => {
34
- expect(ls.getItem('prop1')).to.be.null
35
- expect(ls.getItem('prop2')).to.eq('blue')
36
- expect(ls.getItem('prop3')).to.eq('magenta')
37
- })
38
-
39
- cy.get('.ls-btn').click().should(() => {
40
- expect(localStorage.getItem('prop1')).to.eq('red')
41
- expect(localStorage.getItem('prop2')).to.eq('blue')
42
- expect(localStorage.getItem('prop3')).to.eq('magenta')
43
- })
44
-
45
- // Clear keys matching regex in localStorage
46
- cy.clearLocalStorage(/prop1|2/).should((ls) => {
47
- expect(ls.getItem('prop1')).to.be.null
48
- expect(ls.getItem('prop2')).to.be.null
49
- expect(ls.getItem('prop3')).to.eq('magenta')
50
- })
51
- })
52
-
53
- it('cy.getAllLocalStorage() - get all data in localStorage for all origins', () => {
54
- // https://on.cypress.io/getalllocalstorage
55
- cy.get('.ls-btn').click()
56
-
57
- // getAllLocalStorage() yields a map of origins to localStorage values
58
- cy.getAllLocalStorage().should((storageMap) => {
59
- expect(storageMap).to.deep.equal({
60
- // other origins will also be present if localStorage is set on them
61
- 'https://example.cypress.io': {
62
- 'prop1': 'red',
63
- 'prop2': 'blue',
64
- 'prop3': 'magenta',
65
- },
66
- })
67
- })
68
- })
69
-
70
- it('cy.clearAllLocalStorage() - clear all data in localStorage for all origins', () => {
71
- // https://on.cypress.io/clearalllocalstorage
72
- cy.get('.ls-btn').click()
73
-
74
- // clearAllLocalStorage() yields null
75
- cy.clearAllLocalStorage().should(() => {
76
- expect(sessionStorage.getItem('prop1')).to.be.null
77
- expect(sessionStorage.getItem('prop2')).to.be.null
78
- expect(sessionStorage.getItem('prop3')).to.be.null
79
- })
80
- })
81
-
82
- it('cy.getAllSessionStorage() - get all data in sessionStorage for all origins', () => {
83
- // https://on.cypress.io/getallsessionstorage
84
- cy.get('.ls-btn').click()
85
-
86
- // getAllSessionStorage() yields a map of origins to sessionStorage values
87
- cy.getAllSessionStorage().should((storageMap) => {
88
- expect(storageMap).to.deep.equal({
89
- // other origins will also be present if sessionStorage is set on them
90
- 'https://example.cypress.io': {
91
- 'prop4': 'cyan',
92
- 'prop5': 'yellow',
93
- 'prop6': 'black',
94
- },
95
- })
96
- })
97
- })
98
-
99
- it('cy.clearAllSessionStorage() - clear all data in sessionStorage for all origins', () => {
100
- // https://on.cypress.io/clearallsessionstorage
101
- cy.get('.ls-btn').click()
102
-
103
- // clearAllSessionStorage() yields null
104
- cy.clearAllSessionStorage().should(() => {
105
- expect(sessionStorage.getItem('prop4')).to.be.null
106
- expect(sessionStorage.getItem('prop5')).to.be.null
107
- expect(sessionStorage.getItem('prop6')).to.be.null
108
- })
109
- })
110
- })