@@ -87,9 +87,10 @@ describe('FileUploader', () => {
87
87
onDrop = { ( ) => { } }
88
88
onDropAccepted = { ( ) => { } }
89
89
onDropRejected = { ( ) => { } }
90
+ progressAmount = { 50 }
90
91
/>
91
92
) ;
92
- expect ( console . error ) . toHaveBeenCalledTimes ( 3 ) ;
93
+ expect ( console . error ) . toHaveBeenCalledTimes ( 4 ) ;
93
94
expect ( console . error ) . toHaveBeenNthCalledWith ( 1 , 'onDrop is not a prop for FileUploader.' ) ;
94
95
expect ( console . error ) . toHaveBeenNthCalledWith (
95
96
2 ,
@@ -99,6 +100,10 @@ describe('FileUploader', () => {
99
100
3 ,
100
101
'onDropRejected is not a prop for FileUploader.'
101
102
) ;
103
+ expect ( console . error ) . toHaveBeenNthCalledWith (
104
+ 4 ,
105
+ 'progressAmount is not a prop for FileUploader.'
106
+ ) ;
102
107
console . error = original ;
103
108
} ) ;
104
109
@@ -120,20 +125,23 @@ describe('FileUploader', () => {
120
125
file : mockFileAdded ,
121
126
id : '1' ,
122
127
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
128
+ progressAmount : 20 ,
123
129
status : 'added' ,
124
130
} ,
125
131
{
126
132
errorMessage : 'custom error message' ,
127
133
file : mockFileError ,
128
134
id : '2' ,
129
135
imagePreviewThumbnail : '' ,
136
+ progressAmount : 100 ,
130
137
status : 'error' ,
131
138
} ,
132
139
{
133
140
errorMessage : null ,
134
141
file : mockFileProcessed ,
135
142
id : '3' ,
136
143
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
144
+ progressAmount : 100 ,
137
145
status : 'processed' ,
138
146
} ,
139
147
] }
@@ -186,13 +194,15 @@ describe('FileUploader', () => {
186
194
file : mockAcceptedFile ,
187
195
id : '1' ,
188
196
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
197
+ progressAmount : 100 ,
189
198
status : 'processed' ,
190
199
} ,
191
200
{
192
201
errorMessage : null ,
193
202
file : mockRejectedFile ,
194
203
id : '1' ,
195
204
imagePreviewThumbnail : '' ,
205
+ progressAmount : 100 ,
196
206
status : 'processed' ,
197
207
} ,
198
208
] ) ;
@@ -245,6 +255,7 @@ describe('FileUploader', () => {
245
255
file : mockFile ,
246
256
id : '1' ,
247
257
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
258
+ progressAmount : 100 ,
248
259
status : 'error' ,
249
260
} ,
250
261
] ) ;
@@ -270,6 +281,7 @@ describe('FileUploader', () => {
270
281
file : mockFile ,
271
282
id : '1' ,
272
283
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
284
+ progressAmount : 100 ,
273
285
status : 'error' ,
274
286
} ,
275
287
] ) ;
@@ -295,6 +307,7 @@ describe('FileUploader', () => {
295
307
file : mockFile ,
296
308
id : '1' ,
297
309
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
310
+ progressAmount : 100 ,
298
311
status : 'error' ,
299
312
} ,
300
313
] ) ;
@@ -320,6 +333,7 @@ describe('FileUploader', () => {
320
333
file : mockFile ,
321
334
id : '1' ,
322
335
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
336
+ progressAmount : 100 ,
323
337
status : 'error' ,
324
338
} ,
325
339
] ) ;
@@ -345,6 +359,7 @@ describe('FileUploader', () => {
345
359
file : mockFile ,
346
360
id : '1' ,
347
361
imagePreviewThumbnail : '' ,
362
+ progressAmount : 100 ,
348
363
status : 'error' ,
349
364
} ,
350
365
] ) ;
@@ -373,14 +388,24 @@ describe('FileUploader', () => {
373
388
} ) ;
374
389
await waitFor ( ( ) => {
375
390
expect ( mockProcessFileOnDrop ) . toHaveBeenCalledTimes ( 1 ) ;
376
- expect ( mockProcessFileOnDrop ) . toHaveBeenCalledWith ( mockFile ) ;
391
+ expect ( mockProcessFileOnDrop ) . toHaveBeenCalledWith ( mockFile , '1' , [
392
+ {
393
+ errorMessage : 'test error' ,
394
+ file : mockFile ,
395
+ id : '1' ,
396
+ imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
397
+ progressAmount : 100 ,
398
+ status : 'error' ,
399
+ } ,
400
+ ] ) ;
377
401
expect ( mockSetFileRows ) . toHaveBeenCalledTimes ( 3 ) ;
378
402
expect ( mockSetFileRows ) . toHaveBeenNthCalledWith ( 3 , [
379
403
{
380
404
errorMessage : 'test error' ,
381
405
file : mockFile ,
382
406
id : '1' ,
383
407
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
408
+ progressAmount : 100 ,
384
409
status : 'error' ,
385
410
} ,
386
411
] ) ;
@@ -409,7 +434,17 @@ describe('FileUploader', () => {
409
434
} ) ;
410
435
await waitFor ( ( ) => {
411
436
expect ( mockProcessFileOnDrop ) . toHaveBeenCalledTimes ( 1 ) ;
412
- expect ( mockProcessFileOnDrop ) . toHaveBeenCalledWith ( mockFile ) ;
437
+ expect ( mockProcessFileOnDrop ) . toHaveBeenCalledWith ( mockFile , '1' , [
438
+ {
439
+ errorMessage : null ,
440
+ file : mockFile ,
441
+ fileInfo : 'test-file-info' ,
442
+ id : '1' ,
443
+ imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
444
+ progressAmount : 100 ,
445
+ status : 'processed' ,
446
+ } ,
447
+ ] ) ;
413
448
expect ( mockSetFileRows ) . toHaveBeenCalledTimes ( 3 ) ;
414
449
expect ( mockSetFileRows ) . toHaveBeenNthCalledWith ( 3 , [
415
450
{
@@ -418,12 +453,48 @@ describe('FileUploader', () => {
418
453
fileInfo : 'test-file-info' ,
419
454
id : '1' ,
420
455
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
456
+ progressAmount : 100 ,
421
457
status : 'processed' ,
422
458
} ,
423
459
] ) ;
424
460
} ) ;
425
461
} ) ;
426
462
463
+ it ( 'calls setFilesRows with progressAmountStartValue when processFileOnDrop returns with success' , async ( ) => {
464
+ const mockFile = new File ( [ '(⌐□_□)' ] , 'test.png' , {
465
+ type : 'image/png' ,
466
+ } ) ;
467
+ const mockProcessFileOnDrop = jest . fn ( ( file ) =>
468
+ Promise . resolve ( { errorMessage : null , fileInfo : 'test-file-info' } )
469
+ ) ;
470
+ const mockSetFileRows = jest . fn ( ) ;
471
+ render (
472
+ < FileUploader
473
+ fileRows = { [ ] }
474
+ processFileOnDrop = { mockProcessFileOnDrop }
475
+ progressAmountStartValue = { 0 }
476
+ setFileRows = { mockSetFileRows }
477
+ />
478
+ ) ;
479
+ await act ( async ( ) => {
480
+ await fireEvent . drop ( screen . getByText ( locale . contentMessage ) , {
481
+ target : { files : [ mockFile ] } ,
482
+ } ) ;
483
+ } ) ;
484
+ await waitFor ( ( ) => {
485
+ expect ( mockSetFileRows ) . toHaveBeenNthCalledWith ( 1 , [
486
+ {
487
+ errorMessage : null ,
488
+ file : mockFile ,
489
+ id : '1' ,
490
+ imagePreviewThumbnail : '' ,
491
+ progressAmount : 0 ,
492
+ status : 'added' ,
493
+ } ,
494
+ ] ) ;
495
+ } ) ;
496
+ } ) ;
497
+
427
498
it ( 'calls setFilesRows with error when processFileOnDrop returns with undefined error' , async ( ) => {
428
499
const original = console . error ;
429
500
console . error = jest . fn ( ) ;
@@ -447,7 +518,16 @@ describe('FileUploader', () => {
447
518
} ) ;
448
519
await waitFor ( ( ) => {
449
520
expect ( mockProcessFileOnDrop ) . toHaveBeenCalledTimes ( 1 ) ;
450
- expect ( mockProcessFileOnDrop ) . toHaveBeenCalledWith ( mockFile ) ;
521
+ expect ( mockProcessFileOnDrop ) . toHaveBeenCalledWith ( mockFile , '1' , [
522
+ {
523
+ errorMessage : 'unknown processing error' ,
524
+ file : mockFile ,
525
+ id : '1' ,
526
+ imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
527
+ progressAmount : 100 ,
528
+ status : 'error' ,
529
+ } ,
530
+ ] ) ;
451
531
expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
452
532
expect ( console . error ) . toHaveBeenCalledWith ( 'error with processFileOnDrop' , mockError ) ;
453
533
expect ( mockSetFileRows ) . toHaveBeenCalledTimes ( 3 ) ;
@@ -457,6 +537,7 @@ describe('FileUploader', () => {
457
537
file : mockFile ,
458
538
id : '1' ,
459
539
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
540
+ progressAmount : 100 ,
460
541
status : 'error' ,
461
542
} ,
462
543
] ) ;
@@ -494,6 +575,7 @@ describe('FileUploader', () => {
494
575
file : mockFile ,
495
576
id : '1' ,
496
577
imagePreviewThumbnail : '' ,
578
+ progressAmount : 20 ,
497
579
status : 'added' ,
498
580
} ,
499
581
] }
@@ -527,13 +609,15 @@ describe('FileUploader', () => {
527
609
file : mockFileAdded ,
528
610
id : '1' ,
529
611
imagePreviewThumbnail : '' ,
612
+ progressAmount : 20 ,
530
613
status : 'added' ,
531
614
} ,
532
615
{
533
616
errorMessage : null ,
534
617
file : mockFileProcessed ,
535
618
id : '2' ,
536
619
imagePreviewThumbnail : '' ,
620
+ progressAmount : 100 ,
537
621
status : 'processed' ,
538
622
} ,
539
623
] }
@@ -582,6 +666,7 @@ describe('FileUploader', () => {
582
666
file : mockFile ,
583
667
id : '1' ,
584
668
imagePreviewThumbnail : '' ,
669
+ progressAmount : 100 ,
585
670
status : 'error' ,
586
671
} ,
587
672
] ) ;
@@ -601,6 +686,7 @@ describe('FileUploader', () => {
601
686
file : mockFile ,
602
687
id : '1' ,
603
688
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
689
+ progressAmount : 100 ,
604
690
status : 'processed' ,
605
691
} ,
606
692
] }
@@ -633,13 +719,15 @@ describe('FileUploader', () => {
633
719
file : mockDocumentFile ,
634
720
id : '1' ,
635
721
imagePreviewThumbnail : '' ,
722
+ progressAmount : 100 ,
636
723
status : 'processed' ,
637
724
} ,
638
725
{
639
726
errorMessage : null ,
640
727
file : mockImageFile ,
641
728
id : '2' ,
642
729
imagePreviewThumbnail : 'data:image/png;base64,KOKMkOKWoV/ilqEp' ,
730
+ progressAmount : 100 ,
643
731
status : 'processed' ,
644
732
} ,
645
733
] }
0 commit comments