wick-dom-observer 1.0.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.
@@ -0,0 +1,313 @@
1
+ /* Example specs for wick-dom-observer */
2
+
3
+ describe('clickSpinner examples', () => {
4
+ beforeEach(() => {
5
+ cy.visit('/demo.html')
6
+ })
7
+
8
+ // SPINNERS EXAMPLES
9
+ // ------------------------------------------------------------
10
+
11
+ it('config only', () => {
12
+ cy.get('#spinnerBtn1').clickAndWatchForElement({
13
+ selector: '.spinner',
14
+ assert: ($el) => {
15
+ expect($el).to.be.visible()
16
+ },
17
+ })
18
+ })
19
+
20
+ it('config + mustLast 2000ms', () => {
21
+ cy.get('#spinnerBtn1').clickAndWatchForElement({
22
+ selector: '.spinner',
23
+ appear: 'required',
24
+ disappear: true,
25
+ mustLast: 2000,
26
+ assert: ($el) => {
27
+ expect($el).to.be.visible()
28
+ },
29
+ })
30
+ })
31
+
32
+ it('config + options ({ force: true })', () => {
33
+ cy.get('#spinnerBtn1').clickAndWatchForElement(
34
+ {
35
+ selector: '.spinner',
36
+ assert: ($el) => {
37
+ expect($el).to.have.class('loading')
38
+ },
39
+ },
40
+ { force: true }
41
+ )
42
+ })
43
+
44
+ it('config + position (position "left")', () => {
45
+ cy.get('#spinnerBtn1').clickAndWatchForElement(
46
+ {
47
+ selector: '.spinner',
48
+ appear: 'required',
49
+ disappear: true,
50
+ assert: ($el) => {
51
+ expect($el.text()).to.contain('Loading')
52
+ },
53
+ },
54
+ 'left'
55
+ )
56
+ })
57
+
58
+ it('config + position + options (position "topRight" and { force: true })', () => {
59
+ cy.get('#spinnerBtn1').clickAndWatchForElement(
60
+ {
61
+ selector: '.spinner',
62
+ assert: ($el) => {
63
+ expect($el).to.be.visible()
64
+ },
65
+ },
66
+ 'topRight',
67
+ { force: true }
68
+ )
69
+ })
70
+
71
+ it.only('required spinner + disappearance', { defaultCommandTimeout: 3500 }, () => {
72
+
73
+ cy.get('#spinnerBtn1').clickAndWatchForElement({
74
+ selector: '.spinner',
75
+ appear: 'required',
76
+ disappear: true,
77
+ timeout: 3000,
78
+ // timeout: 4000,
79
+ pollingInterval: 10,
80
+ assert: ($el) => {
81
+ expect($el).to.be.visible()
82
+ expect($el).to.have.class('loading')
83
+ },
84
+ })
85
+ })
86
+
87
+ it.only('required spinner + mustLast + disappearance (THIS TEST WILL FAIL - timeout set to 3000ms is too short)', { defaultCommandTimeout: 10000 }, () => {
88
+ cy.get('#spinnerBtn2').clickAndWatchForElement({
89
+ selector: '.spinner',
90
+
91
+ appear: 'required',
92
+ mustLast: 3000,
93
+ disappear: true,
94
+ timeout: 5000, // All spinner-related actions (appear/disappear/mustLast) are restricted by this timeout: if the spinner takes longer than 3000ms to appear, disappear, or complete its required duration, the test will fail.
95
+ pollingInterval: 10,
96
+ assert: ($el) => {
97
+ expect($el).to.be.visible()
98
+ expect($el.text()).to.eq('Loading')
99
+ },
100
+ })
101
+ })
102
+
103
+ it('required spinner with mustLast and disappearance', { defaultCommandTimeout: 10000 }, () => {
104
+ cy.get('#spinnerBtn2').clickAndWatchForElement({
105
+ selector: '.spinner',
106
+
107
+ appear: 'required',
108
+ mustLast: 1000,
109
+
110
+ disappear: true,
111
+ timeout: 10000,
112
+ pollingInterval: 10,
113
+ assert: ($el) => {
114
+ expect($el).to.be.visible()
115
+ expect($el.text()).to.eq('Loading')
116
+ expect($el).to.have.css('color', 'rgb(17, 24, 39)')
117
+ expect($el).to.have.attr('data-from', 'spinnerBtn2')
118
+ },
119
+ })
120
+ })
121
+
122
+ it('optional spinner without disappearance check', { defaultCommandTimeout: 10000 }, () => {
123
+ cy.get('#spinnerBtn2').clickAndWatchForElement({
124
+ selector: '.spinner',
125
+ timeout: 10000,
126
+ pollingInterval: 10,
127
+ appear: 'optional', // or 'required'
128
+ disappear: false,
129
+ assert: ($el) => {
130
+ expect($el).to.be.visible()
131
+ expect($el.text()).to.eq('Loading')
132
+ expect($el).to.have.css('color', 'rgb(17, 24, 39)')
133
+ expect($el).to.have.attr('data-from', 'spinnerBtn2')
134
+ },
135
+ })
136
+ })
137
+
138
+ it.only('required spinner + disappearance', () => {
139
+ cy.get('#spinnerBtn3').clickAndWatchForElement({
140
+ selector: '.spinner[data-from="spinnerBtn3"]',
141
+ appear: 'required',
142
+ disappear: true,
143
+ timeout: 4500,
144
+ pollingInterval: 10,
145
+ assert: ($el) => {
146
+ expect($el).to.be.visible()
147
+ expect($el).to.have.attr('data-from', 'spinnerBtn3')
148
+ },
149
+ })
150
+ })
151
+
152
+ it('required spinner for spinnerBtn4 without disappearance', () => {
153
+ cy.get('#spinnerBtn4').clickAndWatchForElement({
154
+ selector: '.spinner[data-from="spinnerBtn4"]',
155
+ appear: 'required',
156
+ disappear: false,
157
+ timeout: 2500,
158
+ pollingInterval: 10,
159
+ assert: ($el) => {
160
+ expect($el).to.be.visible()
161
+ expect($el).to.have.attr('data-from', 'spinnerBtn4')
162
+ expect($el.text()).to.eq('Waiting')
163
+ },
164
+ })
165
+ })
166
+
167
+ it.only('required spinner INSIDE button + musat last 800ms', () => {
168
+ cy.get('#spinnerBtn5').clickAndWatchForElement({
169
+ selector: '.button-inline-spinner',
170
+ appear: 'required',
171
+ mustLast: 800,
172
+ timeout: 2500,
173
+ disappear: true,
174
+ pollingInterval: 10,
175
+ assert: ($el) => {
176
+ expect($el).to.be.visible()
177
+ expect($el.closest('#spinnerBtn5')).to.have.class('is-loading')
178
+ },
179
+ })
180
+ })
181
+
182
+ it('optional spinner INSIDE button', () => {
183
+ cy.get('#spinnerBtn5').clickAndWatchForElement({
184
+ selector: '.button-inline-spinner',
185
+ appear: 'optional',
186
+ disappear: true,
187
+ timeout: 3000,
188
+ pollingInterval: 10,
189
+ assert: ($el) => {
190
+ expect($el).to.be.visible()
191
+ expect($el.closest('#spinnerBtn5')).to.have.class('is-loading')
192
+ },
193
+ })
194
+ })
195
+
196
+ it('no spinner appears (optional + no disappearance)', () => {
197
+ cy.get('#spinnerBtn6').clickAndWatchForElement({
198
+ selector: '.spinner[data-from="spinnerBtn6"]',
199
+ appear: 'optional',
200
+ disappear: false,
201
+ timeout: 1000,
202
+ pollingInterval: 10,
203
+ assert: ($el) => {
204
+ expect($el).to.be.visible()
205
+ },
206
+ })
207
+ })
208
+
209
+ it.only('required spinner Superfast but will still pass (config + x + y)', () => {
210
+ cy.get('#spinnerCanvas').clickAndWatchForElement(
211
+ {
212
+ selector: '.spinner',
213
+ appear: 'required',
214
+ disappear: true,
215
+ // mustLast: 30,
216
+ assert: ($el) => {
217
+ expect($el).to.be.visible()
218
+ expect($el).to.have.length(1)
219
+ expect($el).to.have.class('spinner')
220
+ expect($el).to.have.class('spinner-removed')
221
+ expect($el).to.have.class('loading')
222
+ expect($el).to.have.attr('data-from', 'spinnerCanvas')
223
+ expect($el.text()).to.eq('Loading')
224
+ expect($el).to.have.css('color', 'rgb(17, 24, 39)')
225
+ expect($el).to.have.css('font-weight', '700')
226
+ },
227
+ },
228
+ 20,
229
+ 20
230
+ )
231
+ })
232
+
233
+ // TOASTS EXAMPLES
234
+ // ------------------------------------------------------------
235
+
236
+ it.only('toast required + disappearance (created/removed toast)', () => {
237
+ cy.get('#toastBtn1').clickAndWatchForElement({
238
+ selector: '.toast[data-from="toastBtn1"]',
239
+ appear: 'required',
240
+ disappear: true,
241
+ timeout: 4000,
242
+ pollingInterval: 10,
243
+ assert: ($el) => {
244
+ expect($el).to.be.visible()
245
+ expect($el).to.have.attr('data-from', 'toastBtn1')
246
+ expect($el.find('.toast-message').text()).to.contain('removed after 1000ms')
247
+ },
248
+ })
249
+ })
250
+
251
+ it.only('toast required + no disappearance check (persistent hidden toast)', () => {
252
+ cy.get('#toastBtn2').clickAndWatchForElement({
253
+ selector: '.toast[data-from="toastBtn2"]',
254
+ appear: 'required',
255
+ disappear: false,
256
+ timeout: 2000,
257
+ pollingInterval: 10,
258
+ assert: ($el) => {
259
+ expect($el).to.be.visible()
260
+ expect($el).to.have.class('toast-persistent')
261
+ expect($el.find('.toast-message').text()).to.contain('hidden after 3000ms')
262
+ },
263
+ })
264
+ })
265
+
266
+ it.only('no toast appears (optional + no disappearance)', () => {
267
+ cy.get('#toastBtn3').clickAndWatchForElement({
268
+ selector: '.toast[data-from="toastBtn3"]',
269
+ appear: 'optional',
270
+ disappear: false,
271
+ timeout: 1200,
272
+ pollingInterval: 10,
273
+ assert: ($el) => {
274
+ expect($el).to.be.visible()
275
+ },
276
+ })
277
+ })
278
+
279
+ it.only('toast equired + disappearance - super fast toast (but will still pass)', () => {
280
+ cy.get('#toastCanvas').clickAndWatchForElement({
281
+ selector: '.toast[data-from="toastCanvas"]',
282
+ appear: 'required',
283
+ disappear: true,
284
+ timeout: 300,
285
+ pollingInterval: 10,
286
+ assert: ($el) => {
287
+ expect($el).to.be.visible()
288
+ expect($el).to.have.attr('data-from', 'toastCanvas')
289
+ },
290
+ }, 40, 40)
291
+ })
292
+
293
+
294
+ it('toast required + disappearance - super fast toast (THIS TEST WILL FAIL - timeout is too short)', () => {
295
+ cy.get('#toastCanvas').clickAndWatchForElement({
296
+ selector: '.toast[data-from="toastCanvas"]',
297
+ appear: 'required',
298
+ disappear: true,
299
+ timeout: 180, // Note something: Since this is a toast that has an animation when retracting,
300
+ // we need to wait for the animation to complete, even when in the DOM element is hidden after 110ms
301
+ pollingInterval: 10,
302
+ assert: ($el) => {
303
+ expect($el).to.be.visible()
304
+ expect($el).to.have.attr('data-from', 'toastCanvas')
305
+ },
306
+ }, 40, 40)
307
+ })
308
+
309
+ })
310
+
311
+
312
+ // Seems the bottom is spinner THAT SHOW FOR >= 60 milliseconds
313
+