@@ -22,7 +22,6 @@ describe(
22
22
beforeEach (
23
23
( ) => {
24
24
cy . visit ( getUrl ( { prefix : '$' , suffix : 'AUD' } , '6.66' ) ) ;
25
- cy . reload ( ) ;
26
25
}
27
26
) ;
28
27
@@ -59,7 +58,6 @@ describe(
59
58
beforeEach (
60
59
( ) => {
61
60
cy . visit ( getUrl ( { prefix : '$' , suffix : 'AUD' , cursor : 'move' } , '6.66' ) ) ;
62
- cy . reload ( ) ;
63
61
}
64
62
) ;
65
63
@@ -70,15 +68,46 @@ describe(
70
68
cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
71
69
cy . get ( 'input' ) . type ( '9' ) ;
72
70
cy . get ( 'input' ) . should ( 'have.value' , '$66,96AUD' ) ;
71
+ }
72
+ ) ;
73
73
74
- cy . get ( 'input' ) . type ( '{backspace}' . repeat ( 4 ) ) ;
74
+ it (
75
+ 'shouldn\'t erase prefix' ,
76
+ ( ) => {
77
+ cy . get ( 'input' ) . should ( 'have.value' , '$6,66AUD' ) ;
78
+ cy . get ( 'input' ) . type ( '{backspace}' . repeat ( 8 ) ) ;
75
79
cy . get ( 'input' ) . type ( '123' ) ;
76
80
cy . get ( 'input' ) . should ( 'have.value' , '$1,23AUD' ) ;
77
81
cy . get ( 'input' ) . type ( '{leftArrow}' . repeat ( 4 ) ) ;
78
82
cy . get ( 'input' ) . type ( '2' ) ;
79
83
cy . get ( 'input' ) . should ( 'have.value' , '$21,23AUD' ) ;
80
84
}
81
85
) ;
86
+
87
+ it (
88
+ 'should keep caret at correct position after inserted' ,
89
+ ( ) => {
90
+ cy . get ( 'input' ) . should ( 'have.value' , '$6,66AUD' ) ;
91
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
92
+ cy . get ( 'input' ) . type ( '9' ) ;
93
+ cy . get ( 'input' ) . should ( 'have.value' , '$66,96AUD' ) ;
94
+ cy . get ( 'input' ) . type ( '{backspace}' ) ;
95
+ cy . get ( 'input' ) . should ( 'have.value' , '$6,66AUD' ) ;
96
+ }
97
+ ) ;
98
+
99
+ it (
100
+ 'should keep caret at correct position after clear' ,
101
+ ( ) => {
102
+ cy . get ( 'input' ) . should ( 'have.value' , '$6,66AUD' ) ;
103
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
104
+ cy . get ( 'input' ) . type ( '9' ) ;
105
+ cy . get ( 'input' ) . should ( 'have.value' , '$66,96AUD' ) ;
106
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
107
+ cy . get ( 'input' ) . type ( '{backspace}' . repeat ( 2 ) ) ;
108
+ cy . get ( 'input' ) . should ( 'have.value' , '$0,96AUD' ) ;
109
+ }
110
+ ) ;
82
111
}
83
112
) ;
84
113
} ,
@@ -90,7 +119,6 @@ describe(
90
119
beforeEach (
91
120
( ) => {
92
121
cy . visit ( getUrl ( { prefix : '$' , suffix : 'AUD' , cursor : 'move' } , '666.99' ) ) ;
93
- cy . reload ( ) ;
94
122
}
95
123
) ;
96
124
@@ -200,3 +228,167 @@ describe(
200
228
}
201
229
) ;
202
230
231
+
232
+ describe (
233
+ 'negative numbers' ,
234
+ ( ) => {
235
+ describe (
236
+ 'should start with negative when allowed' ,
237
+ ( ) => {
238
+ beforeEach (
239
+ ( ) => {
240
+ cy . visit ( getUrl ( { allowNegative : true } , '-6.99' ) ) ;
241
+ }
242
+ ) ;
243
+
244
+ it (
245
+ 'should allow add negative sign' ,
246
+ ( ) => {
247
+ cy . get ( 'input' ) . should ( 'have.value' , '-6,99' ) ;
248
+ cy . get ( 'input' ) . type ( '-' ) ;
249
+ cy . get ( 'input' ) . should ( 'have.value' , '-6,99' ) ;
250
+ }
251
+ ) ;
252
+ }
253
+ ) ;
254
+
255
+ describe (
256
+ 'should allow add and remove negative sign correctly' ,
257
+ ( ) => {
258
+ beforeEach (
259
+ ( ) => {
260
+ cy . visit ( getUrl ( { allowNegative : true , cursor : 'move' } ) ) ;
261
+ }
262
+ ) ;
263
+
264
+ it (
265
+ 'should allow add negative sign' ,
266
+ ( ) => {
267
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00' ) ;
268
+ cy . get ( 'input' ) . type ( '-' ) ;
269
+ cy . get ( 'input' ) . should ( 'have.value' , '-0,00' ) ;
270
+ }
271
+ ) ;
272
+
273
+ it (
274
+ 'should allow add only one negative sign' ,
275
+ ( ) => {
276
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00' ) ;
277
+ cy . get ( 'input' ) . type ( '----' ) ;
278
+ cy . get ( 'input' ) . should ( 'have.value' , '-0,00' ) ;
279
+ }
280
+ ) ;
281
+
282
+ it (
283
+ 'should allow write with negative sign' ,
284
+ ( ) => {
285
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00' ) ;
286
+ cy . get ( 'input' ) . type ( '666' ) ;
287
+ cy . get ( 'input' ) . type ( '-' ) ;
288
+ cy . get ( 'input' ) . should ( 'have.value' , '-6,66' ) ;
289
+ cy . get ( 'input' ) . type ( '963' ) ;
290
+ cy . get ( 'input' ) . should ( 'have.value' , '-6.669,63' ) ;
291
+ }
292
+ ) ;
293
+
294
+ it (
295
+ 'should keep caret at correct position after inserted' ,
296
+ ( ) => {
297
+ cy . get ( 'input' ) . type ( '6-66' ) ;
298
+ cy . get ( 'input' ) . should ( 'have.value' , '-6,66' ) ;
299
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
300
+ cy . get ( 'input' ) . type ( '9' ) ;
301
+ cy . get ( 'input' ) . should ( 'have.value' , '-66,96' ) ;
302
+ cy . get ( 'input' ) . type ( '{backspace}' ) ;
303
+ cy . get ( 'input' ) . should ( 'have.value' , '-6,66' ) ;
304
+ }
305
+ ) ;
306
+
307
+ it (
308
+ 'should keep caret at correct position after clear' ,
309
+ ( ) => {
310
+ cy . get ( 'input' ) . type ( '6-66' ) ;
311
+ cy . get ( 'input' ) . should ( 'have.value' , '-6,66' ) ;
312
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
313
+ cy . get ( 'input' ) . type ( '9' ) ;
314
+ cy . get ( 'input' ) . should ( 'have.value' , '-66,96' ) ;
315
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
316
+ cy . get ( 'input' ) . type ( '{backspace}' . repeat ( 2 ) ) ;
317
+ cy . get ( 'input' ) . should ( 'have.value' , '-0,96' ) ;
318
+ }
319
+ ) ;
320
+ }
321
+ ) ;
322
+
323
+ describe (
324
+ 'should allow add and remove negative sign correctly when it is after numbers' ,
325
+ ( ) => {
326
+ beforeEach (
327
+ ( ) => {
328
+ cy . visit ( getUrl ( { allowNegative : true , negativeSignAfter : true , cursor : 'move' } ) ) ;
329
+ }
330
+ ) ;
331
+
332
+ it (
333
+ 'should allow add negative sign' ,
334
+ ( ) => {
335
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00' ) ;
336
+ cy . get ( 'input' ) . type ( '-' ) ;
337
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00-' ) ;
338
+ }
339
+ ) ;
340
+
341
+ it (
342
+ 'should allow add only one negative sign' ,
343
+ ( ) => {
344
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00' ) ;
345
+ cy . get ( 'input' ) . type ( '----' ) ;
346
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00-' ) ;
347
+ }
348
+ ) ;
349
+
350
+ it (
351
+ 'should allow write with negative sign' ,
352
+ ( ) => {
353
+ cy . get ( 'input' ) . should ( 'have.value' , '0,00' ) ;
354
+ cy . get ( 'input' ) . type ( '666' ) ;
355
+ cy . get ( 'input' ) . type ( '-' ) ;
356
+ cy . get ( 'input' ) . should ( 'have.value' , '6,66-' ) ;
357
+ cy . get ( 'input' ) . type ( '963' ) ;
358
+ cy . get ( 'input' ) . should ( 'have.value' , '6.669,63-' ) ;
359
+ }
360
+ ) ;
361
+
362
+ it (
363
+ 'should keep caret at correct position after inserted' ,
364
+ ( ) => {
365
+ cy . get ( 'input' ) . type ( '6-66' ) ;
366
+ cy . get ( 'input' ) . should ( 'have.value' , '6,66-' ) ;
367
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ;
368
+ cy . get ( 'input' ) . type ( '9' ) ;
369
+ cy . get ( 'input' ) . should ( 'have.value' , '66,69-' ) ;
370
+ cy . get ( 'input' ) . type ( '{backspace}' ) ;
371
+ cy . get ( 'input' ) . should ( 'have.value' , '6,66-' ) ;
372
+ }
373
+ ) ;
374
+
375
+ it (
376
+ 'should keep caret at correct position after clear' ,
377
+ ( ) => {
378
+ cy . get ( 'input' ) . type ( '6-99' ) ; // 6,99-|
379
+ cy . get ( 'input' ) . should ( 'have.value' , '6,99-' ) ;
380
+ cy . get ( 'input' ) . type ( '{leftArrow}' ) ; // 6,99|-
381
+ cy . get ( 'input' ) . type ( '3' ) ;
382
+ cy . get ( 'input' ) . should ( 'have.value' , '69,93-' ) ;
383
+ cy . get ( 'input' ) . type ( '{leftArrow}' . repeat ( 2 ) ) ; // 69,|93-
384
+ cy . get ( 'input' ) . type ( '{backspace}' . repeat ( 2 ) ) ; // 0,|93-
385
+ cy . get ( 'input' ) . should ( 'have.value' , '0,93-' ) ;
386
+ cy . get ( 'input' ) . type ( '{rightArrow}' . repeat ( 3 ) ) ; // 0,93-|
387
+ cy . get ( 'input' ) . type ( '{backspace}' ) ;
388
+ cy . get ( 'input' ) . should ( 'have.value' , '0,93' ) ;
389
+ }
390
+ ) ;
391
+ }
392
+ ) ;
393
+ }
394
+ ) ;
0 commit comments