1
1
/* eslint no-console:0 */
2
2
import React from 'react' ;
3
3
import { format } from 'util' ;
4
+ import { resetWarned } from 'rc-util/lib/warning' ;
4
5
import { mount } from 'enzyme' ;
5
6
import sinon from 'sinon' ;
6
7
import Uploader from '../index' ;
@@ -409,6 +410,35 @@ describe('uploader', () => {
409
410
done ( ) ;
410
411
} , 100 ) ;
411
412
} ) ;
413
+
414
+ it ( 'accept if type is invalidate' , done => {
415
+ resetWarned ( ) ;
416
+ const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
417
+
418
+ uploader . unmount ( ) ;
419
+ uploader = mount ( < Uploader { ...props } accept = "jpg,png" /> ) ;
420
+
421
+ const input = uploader . find ( 'input' ) . first ( ) ;
422
+ const files = [
423
+ {
424
+ name : 'unaccepted.webp' ,
425
+ } ,
426
+ ] ;
427
+ input . simulate ( 'change' , { target : { files } } ) ;
428
+ const mockStart = jest . fn ( ) ;
429
+ handlers . onStart = mockStart ;
430
+
431
+ expect ( errSpy ) . toHaveBeenCalledWith (
432
+ "Warning: Upload takes an invalidate 'accept' type 'jpg'.Skip for check." ,
433
+ ) ;
434
+
435
+ setTimeout ( ( ) => {
436
+ expect ( mockStart . mock . calls . length ) . toBe ( 1 ) ;
437
+
438
+ errSpy . mockRestore ( ) ;
439
+ done ( ) ;
440
+ } , 100 ) ;
441
+ } ) ;
412
442
} ) ;
413
443
414
444
describe ( 'accept' , ( ) => {
@@ -430,15 +460,25 @@ describe('uploader', () => {
430
460
} ,
431
461
} ;
432
462
433
- function test ( desc , value , files , expecptCallTimes ) {
463
+ function test ( desc , value , files , expectCallTimes , errorMessage ) {
434
464
it ( desc , done => {
465
+ resetWarned ( ) ;
466
+ const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
467
+
435
468
uploader = mount ( < Uploader { ...props } accept = { value } /> ) ;
436
469
const input = uploader . find ( 'input' ) . first ( ) ;
437
470
input . simulate ( 'change' , { target : { files } } ) ;
438
471
const mockStart = jest . fn ( ) ;
439
472
handlers . onStart = mockStart ;
473
+
474
+ if ( errorMessage ) {
475
+ expect ( errSpy ) . toHaveBeenCalledWith ( errorMessage ) ;
476
+ }
477
+
440
478
setTimeout ( ( ) => {
441
- expect ( mockStart . mock . calls . length ) . toBe ( expecptCallTimes ) ;
479
+ expect ( mockStart . mock . calls . length ) . toBe ( expectCallTimes ) ;
480
+
481
+ errSpy . mockRestore ( ) ;
442
482
done ( ) ;
443
483
} , 100 ) ;
444
484
} ) ;
@@ -576,6 +616,23 @@ describe('uploader', () => {
576
616
] ,
577
617
2 ,
578
618
) ;
619
+
620
+ test (
621
+ 'invalidate type should skip' ,
622
+ 'jpg' ,
623
+ [
624
+ {
625
+ name : 'accepted.png' ,
626
+ type : 'image/png' ,
627
+ } ,
628
+ {
629
+ name : 'accepted.text' ,
630
+ type : 'text/plain' ,
631
+ } ,
632
+ ] ,
633
+ 2 ,
634
+ "Warning: Upload takes an invalidate 'accept' type 'jpg'.Skip for check." ,
635
+ ) ;
579
636
} ) ;
580
637
581
638
describe ( 'transform file before request' , ( ) => {
0 commit comments