react-dropzone 4.2.13 → 4.3.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.
- package/dist/es/index.js +69 -56
- package/dist/es/utils/index.js +2 -0
- package/dist/index.js +2 -2
- package/package.json +4 -4
- package/src/__snapshots__/index.spec.js.snap +7 -7
- package/src/index.js +68 -50
- package/src/index.spec.js +83 -83
- package/src/utils/index.js +2 -0
package/src/index.spec.js
CHANGED
|
@@ -361,21 +361,21 @@ describe('Dropzone', () => {
|
|
|
361
361
|
dragOverSpy.restore()
|
|
362
362
|
})
|
|
363
363
|
|
|
364
|
-
it('should set proper dragActive state on dragEnter', () => {
|
|
364
|
+
it('should set proper dragActive state on dragEnter', async () => {
|
|
365
365
|
const dropzone = mount(<Dropzone>{props => <DummyChildComponent {...props} />}</Dropzone>)
|
|
366
366
|
const child = dropzone.find(DummyChildComponent)
|
|
367
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
367
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
368
368
|
expect(child).toHaveProp('isDragActive', true)
|
|
369
369
|
expect(child).toHaveProp('isDragAccept', true)
|
|
370
370
|
expect(child).toHaveProp('isDragReject', false)
|
|
371
371
|
})
|
|
372
372
|
|
|
373
|
-
it('should set proper dragReject state on dragEnter', () => {
|
|
373
|
+
it('should set proper dragReject state on dragEnter', async () => {
|
|
374
374
|
const dropzone = mount(
|
|
375
375
|
<Dropzone accept="image/*">{props => <DummyChildComponent {...props} />}</Dropzone>
|
|
376
376
|
)
|
|
377
377
|
const child = dropzone.find(DummyChildComponent)
|
|
378
|
-
dropzone.simulate('dragEnter', {
|
|
378
|
+
await dropzone.simulate('dragEnter', {
|
|
379
379
|
dataTransfer: { files: files.concat(images) }
|
|
380
380
|
})
|
|
381
381
|
expect(child).toHaveProp('isDragActive', true)
|
|
@@ -383,64 +383,64 @@ describe('Dropzone', () => {
|
|
|
383
383
|
expect(child).toHaveProp('isDragReject', true)
|
|
384
384
|
})
|
|
385
385
|
|
|
386
|
-
it('should set proper dragAccept state if multiple is false', () => {
|
|
386
|
+
it('should set proper dragAccept state if multiple is false', async () => {
|
|
387
387
|
const dropzone = mount(
|
|
388
388
|
<Dropzone accept="image/*" multiple={false}>
|
|
389
389
|
{props => <DummyChildComponent {...props} />}
|
|
390
390
|
</Dropzone>
|
|
391
391
|
)
|
|
392
392
|
const child = dropzone.find(DummyChildComponent)
|
|
393
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
393
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
394
394
|
expect(child).toHaveProp('isDragActive', true)
|
|
395
395
|
expect(child).toHaveProp('isDragAccept', false)
|
|
396
396
|
expect(child).toHaveProp('isDragReject', true)
|
|
397
397
|
})
|
|
398
398
|
|
|
399
|
-
it('should set proper dragAccept state if multiple is false', () => {
|
|
399
|
+
it('should set proper dragAccept state if multiple is false', async () => {
|
|
400
400
|
const dropzone = mount(
|
|
401
401
|
<Dropzone accept="image/*" multiple={false}>
|
|
402
402
|
{props => <DummyChildComponent {...props} />}
|
|
403
403
|
</Dropzone>
|
|
404
404
|
)
|
|
405
405
|
const child = dropzone.find(DummyChildComponent)
|
|
406
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
406
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
407
407
|
expect(child).toHaveProp('isDragActive', true)
|
|
408
408
|
expect(child).toHaveProp('isDragAccept', true)
|
|
409
409
|
expect(child).toHaveProp('isDragReject', true)
|
|
410
410
|
})
|
|
411
411
|
|
|
412
|
-
it('should set activeClassName properly', () => {
|
|
412
|
+
it('should set activeClassName properly', async () => {
|
|
413
413
|
const dropzone = mount(
|
|
414
414
|
<Dropzone accept="image/*" activeClassName="👏" multiple={false}>
|
|
415
415
|
{props => <DummyChildComponent {...props} />}
|
|
416
416
|
</Dropzone>
|
|
417
417
|
)
|
|
418
418
|
const child = dropzone.find(DummyChildComponent)
|
|
419
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
419
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
420
420
|
expect(child).toHaveProp('isDragActive', true)
|
|
421
421
|
expect(dropzone.hasClass('👏')).toBe(true)
|
|
422
422
|
})
|
|
423
423
|
|
|
424
|
-
it('should set rejectClassName properly', () => {
|
|
424
|
+
it('should set rejectClassName properly', async () => {
|
|
425
425
|
const dropzone = mount(
|
|
426
426
|
<Dropzone accept="image/*" rejectClassName="👎" multiple={false}>
|
|
427
427
|
{props => <DummyChildComponent {...props} />}
|
|
428
428
|
</Dropzone>
|
|
429
429
|
)
|
|
430
430
|
const child = dropzone.find(DummyChildComponent)
|
|
431
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
431
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
432
432
|
expect(child).toHaveProp('isDragReject', true)
|
|
433
433
|
expect(dropzone.hasClass('👎')).toBe(true)
|
|
434
434
|
})
|
|
435
435
|
|
|
436
|
-
it('should set acceptClassName properly', () => {
|
|
436
|
+
it('should set acceptClassName properly', async () => {
|
|
437
437
|
const dropzone = mount(
|
|
438
438
|
<Dropzone accept="image/*" acceptClassName="👍" className="foo" multiple={false}>
|
|
439
439
|
{props => <DummyChildComponent {...props} />}
|
|
440
440
|
</Dropzone>
|
|
441
441
|
)
|
|
442
442
|
const child = dropzone.find(DummyChildComponent)
|
|
443
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
443
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
444
444
|
expect(child).toHaveProp('isDragAccept', true)
|
|
445
445
|
expect(dropzone.hasClass('👍')).toBe(true)
|
|
446
446
|
})
|
|
@@ -454,16 +454,16 @@ describe('Dropzone', () => {
|
|
|
454
454
|
expect(dropzone.hasClass('🤐')).toBe(true)
|
|
455
455
|
})
|
|
456
456
|
|
|
457
|
-
it('should keep dragging active when leaving from arbitrary node', () => {
|
|
457
|
+
it('should keep dragging active when leaving from arbitrary node', async () => {
|
|
458
458
|
const arbitraryOverlay = mount(<div />)
|
|
459
459
|
const dropzone = mount(<Dropzone>{props => <DummyChildComponent {...props} />}</Dropzone>)
|
|
460
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
460
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
461
461
|
dropzone.simulate('dragLeave', { target: arbitraryOverlay })
|
|
462
462
|
expect(dropzone.state('isDragActive')).toBe(true)
|
|
463
463
|
expect(dropzone.state('draggedFiles').length > 0).toBe(true)
|
|
464
464
|
})
|
|
465
465
|
|
|
466
|
-
it('should apply acceptStyle if multiple is false and single file', () => {
|
|
466
|
+
it('should apply acceptStyle if multiple is false and single file', async () => {
|
|
467
467
|
const dropzone = mount(
|
|
468
468
|
<Dropzone
|
|
469
469
|
accept="image/*"
|
|
@@ -474,12 +474,12 @@ describe('Dropzone', () => {
|
|
|
474
474
|
{props => <DummyChildComponent {...props} />}
|
|
475
475
|
</Dropzone>
|
|
476
476
|
)
|
|
477
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: [images[0]] } })
|
|
477
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: [images[0]] } })
|
|
478
478
|
const mainDiv = dropzone.find('div').at(0)
|
|
479
479
|
expect(mainDiv).toHaveProp('style', { position: 'relative', ...acceptStyle })
|
|
480
480
|
})
|
|
481
481
|
|
|
482
|
-
it('should apply rejectStyle if multiple is false and single bad file type', () => {
|
|
482
|
+
it('should apply rejectStyle if multiple is false and single bad file type', async () => {
|
|
483
483
|
const dropzone = mount(
|
|
484
484
|
<Dropzone
|
|
485
485
|
accept="image/*"
|
|
@@ -490,12 +490,12 @@ describe('Dropzone', () => {
|
|
|
490
490
|
{props => <DummyChildComponent {...props} />}
|
|
491
491
|
</Dropzone>
|
|
492
492
|
)
|
|
493
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: [files[0]] } })
|
|
493
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: [files[0]] } })
|
|
494
494
|
const mainDiv = dropzone.find('div').at(0)
|
|
495
495
|
expect(mainDiv).toHaveProp('style', { position: 'relative', ...rejectStyle })
|
|
496
496
|
})
|
|
497
497
|
|
|
498
|
-
it('should apply acceptStyle + rejectStyle if multiple is false and multiple good file types', () => {
|
|
498
|
+
it('should apply acceptStyle + rejectStyle if multiple is false and multiple good file types', async () => {
|
|
499
499
|
const dropzone = mount(
|
|
500
500
|
<Dropzone
|
|
501
501
|
accept="image/*"
|
|
@@ -506,7 +506,7 @@ describe('Dropzone', () => {
|
|
|
506
506
|
{props => <DummyChildComponent {...props} />}
|
|
507
507
|
</Dropzone>
|
|
508
508
|
)
|
|
509
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
509
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
510
510
|
const mainDiv = dropzone.find('div').at(0)
|
|
511
511
|
const expectedStyle = {
|
|
512
512
|
position: 'relative',
|
|
@@ -516,12 +516,12 @@ describe('Dropzone', () => {
|
|
|
516
516
|
expect(mainDiv).toHaveProp('style', expectedStyle)
|
|
517
517
|
})
|
|
518
518
|
|
|
519
|
-
it('should set proper dragActive state if accept prop changes mid-drag', () => {
|
|
519
|
+
it('should set proper dragActive state if accept prop changes mid-drag', async () => {
|
|
520
520
|
const dropzone = mount(
|
|
521
521
|
<Dropzone accept="image/*">{props => <DummyChildComponent {...props} />}</Dropzone>
|
|
522
522
|
)
|
|
523
523
|
const child = dropzone.find(DummyChildComponent)
|
|
524
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
524
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
525
525
|
expect(child).toHaveProp('isDragActive', true)
|
|
526
526
|
expect(child).toHaveProp('isDragAccept', true)
|
|
527
527
|
expect(child).toHaveProp('isDragReject', false)
|
|
@@ -532,7 +532,7 @@ describe('Dropzone', () => {
|
|
|
532
532
|
expect(child).toHaveProp('isDragReject', true)
|
|
533
533
|
})
|
|
534
534
|
|
|
535
|
-
it('should expose state to children', () => {
|
|
535
|
+
it('should expose state to children', async () => {
|
|
536
536
|
const dropzone = mount(
|
|
537
537
|
<Dropzone accept="image/*">
|
|
538
538
|
{({ isDragActive, isDragAccept, isDragReject }) => {
|
|
@@ -547,13 +547,13 @@ describe('Dropzone', () => {
|
|
|
547
547
|
</Dropzone>
|
|
548
548
|
)
|
|
549
549
|
expect(dropzone.text()).toEqual('Empty')
|
|
550
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
550
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
551
551
|
expect(dropzone.text()).toEqual('Active and Accept')
|
|
552
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
552
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
553
553
|
expect(dropzone.text()).toEqual('Active but Reject')
|
|
554
554
|
})
|
|
555
555
|
|
|
556
|
-
it('should reset the dragAccept/dragReject state when leaving after a child goes away', () => {
|
|
556
|
+
it('should reset the dragAccept/dragReject state when leaving after a child goes away', async () => {
|
|
557
557
|
const DragActiveComponent = () => <p>Accept</p>
|
|
558
558
|
const ChildComponent = () => <p>Child component content</p>
|
|
559
559
|
const dropzone = mount(
|
|
@@ -571,9 +571,9 @@ describe('Dropzone', () => {
|
|
|
571
571
|
)
|
|
572
572
|
const child = dropzone.find(ChildComponent)
|
|
573
573
|
child.simulate('dragEnter', { dataTransfer: { files } })
|
|
574
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
574
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
575
575
|
// make sure we handle any duplicate dragEnter events that the browser may send us
|
|
576
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
576
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
577
577
|
const dragActiveChild = dropzone.find(DragActiveComponent)
|
|
578
578
|
expect(dragActiveChild).toBePresent()
|
|
579
579
|
expect(dragActiveChild).toHaveProp('isDragAccept', true)
|
|
@@ -603,7 +603,7 @@ describe('Dropzone', () => {
|
|
|
603
603
|
dropRejectedSpy.reset()
|
|
604
604
|
})
|
|
605
605
|
|
|
606
|
-
it('should reset the dragActive/dragReject state', () => {
|
|
606
|
+
it('should reset the dragActive/dragReject state', async () => {
|
|
607
607
|
const dropzone = mount(
|
|
608
608
|
<Dropzone
|
|
609
609
|
onDrop={dropSpy}
|
|
@@ -614,7 +614,7 @@ describe('Dropzone', () => {
|
|
|
614
614
|
</Dropzone>
|
|
615
615
|
)
|
|
616
616
|
const child = dropzone.find(DummyChildComponent)
|
|
617
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
617
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
618
618
|
expect(child).toHaveProp('isDragActive', true)
|
|
619
619
|
expect(child).toHaveProp('isDragReject', false)
|
|
620
620
|
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
@@ -622,47 +622,47 @@ describe('Dropzone', () => {
|
|
|
622
622
|
expect(child).toHaveProp('isDragReject', false)
|
|
623
623
|
})
|
|
624
624
|
|
|
625
|
-
it('should add valid files to rejected files on a multple drop when multiple false', () => {
|
|
625
|
+
it('should add valid files to rejected files on a multple drop when multiple false', async () => {
|
|
626
626
|
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
627
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
627
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
628
628
|
const rejected = dropSpy.firstCall.args[0]
|
|
629
629
|
expect(rejected.length).toEqual(1)
|
|
630
630
|
})
|
|
631
631
|
|
|
632
|
-
it('should add invalid files to rejected when multiple is false', () => {
|
|
632
|
+
it('should add invalid files to rejected when multiple is false', async () => {
|
|
633
633
|
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
634
|
-
dropzone.simulate('drop', {
|
|
634
|
+
await dropzone.simulate('drop', {
|
|
635
635
|
dataTransfer: { files: images.concat(files) }
|
|
636
636
|
})
|
|
637
637
|
const rejected = dropSpy.firstCall.args[1]
|
|
638
638
|
expect(rejected.length).toEqual(2)
|
|
639
639
|
})
|
|
640
640
|
|
|
641
|
-
it('should allow single files to be dropped if multiple is false', () => {
|
|
641
|
+
it('should allow single files to be dropped if multiple is false', async () => {
|
|
642
642
|
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
643
643
|
|
|
644
|
-
dropzone.simulate('drop', { dataTransfer: { files: [images[0]] } })
|
|
644
|
+
await dropzone.simulate('drop', { dataTransfer: { files: [images[0]] } })
|
|
645
645
|
const [accepted, rejected] = dropSpy.firstCall.args
|
|
646
646
|
expect(accepted.length).toEqual(1)
|
|
647
647
|
expect(rejected.length).toEqual(0)
|
|
648
648
|
})
|
|
649
649
|
|
|
650
|
-
it('should take all dropped files if multiple is true', () => {
|
|
650
|
+
it('should take all dropped files if multiple is true', async () => {
|
|
651
651
|
const dropzone = mount(<Dropzone onDrop={dropSpy} multiple />)
|
|
652
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
652
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
653
653
|
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
654
654
|
expect(dropSpy.firstCall.args[0][0].name).toEqual(images[0].name)
|
|
655
655
|
expect(dropSpy.firstCall.args[0][1].name).toEqual(images[1].name)
|
|
656
656
|
})
|
|
657
657
|
|
|
658
|
-
it('should set this.isFileDialogActive to false', () => {
|
|
658
|
+
it('should set this.isFileDialogActive to false', async () => {
|
|
659
659
|
const dropzone = mount(<Dropzone />)
|
|
660
660
|
dropzone.instance().isFileDialogActive = true
|
|
661
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
661
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
662
662
|
expect(dropzone.instance().isFileDialogActive).toEqual(false)
|
|
663
663
|
})
|
|
664
664
|
|
|
665
|
-
it('should always call onDrop callback with accepted and rejected arguments', () => {
|
|
665
|
+
it('should always call onDrop callback with accepted and rejected arguments', async () => {
|
|
666
666
|
const dropzone = mount(
|
|
667
667
|
<Dropzone
|
|
668
668
|
onDrop={dropSpy}
|
|
@@ -671,20 +671,20 @@ describe('Dropzone', () => {
|
|
|
671
671
|
accept="image/*"
|
|
672
672
|
/>
|
|
673
673
|
)
|
|
674
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
674
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
675
675
|
expect(dropSpy.callCount).toEqual(1)
|
|
676
676
|
expect(dropSpy.firstCall.args[0]).toEqual([], [...files])
|
|
677
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
677
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
678
678
|
expect(dropSpy.callCount).toEqual(2)
|
|
679
679
|
expect(dropSpy.lastCall.args[0]).toEqual([...images], [])
|
|
680
|
-
dropzone.simulate('drop', {
|
|
680
|
+
await dropzone.simulate('drop', {
|
|
681
681
|
dataTransfer: { files: files.concat(images) }
|
|
682
682
|
})
|
|
683
683
|
expect(dropSpy.callCount).toEqual(3)
|
|
684
684
|
expect(dropSpy.lastCall.args[0]).toEqual([...images], [...files])
|
|
685
685
|
})
|
|
686
686
|
|
|
687
|
-
it('should call onDropAccepted callback if some files were accepted', () => {
|
|
687
|
+
it('should call onDropAccepted callback if some files were accepted', async () => {
|
|
688
688
|
const dropzone = mount(
|
|
689
689
|
<Dropzone
|
|
690
690
|
onDrop={dropSpy}
|
|
@@ -693,19 +693,19 @@ describe('Dropzone', () => {
|
|
|
693
693
|
accept="image/*"
|
|
694
694
|
/>
|
|
695
695
|
)
|
|
696
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
696
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
697
697
|
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
698
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
698
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
699
699
|
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
700
700
|
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
701
|
-
dropzone.simulate('drop', {
|
|
701
|
+
await dropzone.simulate('drop', {
|
|
702
702
|
dataTransfer: { files: files.concat(images) }
|
|
703
703
|
})
|
|
704
704
|
expect(dropAcceptedSpy.callCount).toEqual(2)
|
|
705
705
|
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
706
706
|
})
|
|
707
707
|
|
|
708
|
-
it('should call onDropRejected callback if some files were rejected', () => {
|
|
708
|
+
it('should call onDropRejected callback if some files were rejected', async () => {
|
|
709
709
|
const dropzone = mount(
|
|
710
710
|
<Dropzone
|
|
711
711
|
onDrop={dropSpy}
|
|
@@ -714,19 +714,19 @@ describe('Dropzone', () => {
|
|
|
714
714
|
accept="image/*"
|
|
715
715
|
/>
|
|
716
716
|
)
|
|
717
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
717
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
718
718
|
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
719
719
|
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
720
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
720
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
721
721
|
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
722
|
-
dropzone.simulate('drop', {
|
|
722
|
+
await dropzone.simulate('drop', {
|
|
723
723
|
dataTransfer: { files: files.concat(images) }
|
|
724
724
|
})
|
|
725
725
|
expect(dropRejectedSpy.callCount).toEqual(2)
|
|
726
726
|
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
727
727
|
})
|
|
728
728
|
|
|
729
|
-
it('applies the accept prop to the dropped files', () => {
|
|
729
|
+
it('applies the accept prop to the dropped files', async () => {
|
|
730
730
|
const dropzone = mount(
|
|
731
731
|
<Dropzone
|
|
732
732
|
onDrop={dropSpy}
|
|
@@ -735,7 +735,7 @@ describe('Dropzone', () => {
|
|
|
735
735
|
accept="image/*"
|
|
736
736
|
/>
|
|
737
737
|
)
|
|
738
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
738
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
739
739
|
expect(dropSpy.callCount).toEqual(1)
|
|
740
740
|
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
741
741
|
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
@@ -744,7 +744,7 @@ describe('Dropzone', () => {
|
|
|
744
744
|
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
745
745
|
})
|
|
746
746
|
|
|
747
|
-
it('applies the accept prop to the dropped images', () => {
|
|
747
|
+
it('applies the accept prop to the dropped images', async () => {
|
|
748
748
|
const dropzone = mount(
|
|
749
749
|
<Dropzone
|
|
750
750
|
onDrop={dropSpy}
|
|
@@ -754,7 +754,7 @@ describe('Dropzone', () => {
|
|
|
754
754
|
/>
|
|
755
755
|
)
|
|
756
756
|
|
|
757
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
757
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
758
758
|
expect(dropSpy.callCount).toEqual(1)
|
|
759
759
|
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
760
760
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -763,7 +763,7 @@ describe('Dropzone', () => {
|
|
|
763
763
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
764
764
|
})
|
|
765
765
|
|
|
766
|
-
it('accepts a dropped image when Firefox provides a bogus file type', () => {
|
|
766
|
+
it('accepts a dropped image when Firefox provides a bogus file type', async () => {
|
|
767
767
|
const dropzone = mount(
|
|
768
768
|
<Dropzone
|
|
769
769
|
onDrop={dropSpy}
|
|
@@ -780,7 +780,7 @@ describe('Dropzone', () => {
|
|
|
780
780
|
}
|
|
781
781
|
]
|
|
782
782
|
|
|
783
|
-
dropzone.simulate('drop', { dataTransfer: { files: bogusImages } })
|
|
783
|
+
await dropzone.simulate('drop', { dataTransfer: { files: bogusImages } })
|
|
784
784
|
expect(dropSpy.callCount).toEqual(1)
|
|
785
785
|
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
786
786
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -789,7 +789,7 @@ describe('Dropzone', () => {
|
|
|
789
789
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
790
790
|
})
|
|
791
791
|
|
|
792
|
-
it('accepts all dropped files and images when no accept prop is specified', () => {
|
|
792
|
+
it('accepts all dropped files and images when no accept prop is specified', async () => {
|
|
793
793
|
const dropzone = mount(
|
|
794
794
|
<Dropzone
|
|
795
795
|
onDrop={dropSpy}
|
|
@@ -797,7 +797,7 @@ describe('Dropzone', () => {
|
|
|
797
797
|
onDropRejected={dropRejectedSpy}
|
|
798
798
|
/>
|
|
799
799
|
)
|
|
800
|
-
dropzone.simulate('drop', {
|
|
800
|
+
await dropzone.simulate('drop', {
|
|
801
801
|
dataTransfer: { files: files.concat(images) }
|
|
802
802
|
})
|
|
803
803
|
expect(dropSpy.callCount).toEqual(1)
|
|
@@ -808,7 +808,7 @@ describe('Dropzone', () => {
|
|
|
808
808
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
809
809
|
})
|
|
810
810
|
|
|
811
|
-
it('applies the maxSize prop to the dropped files', () => {
|
|
811
|
+
it('applies the maxSize prop to the dropped files', async () => {
|
|
812
812
|
const dropzone = mount(
|
|
813
813
|
<Dropzone
|
|
814
814
|
onDrop={dropSpy}
|
|
@@ -818,7 +818,7 @@ describe('Dropzone', () => {
|
|
|
818
818
|
/>
|
|
819
819
|
)
|
|
820
820
|
|
|
821
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
821
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
822
822
|
expect(dropSpy.callCount).toEqual(1)
|
|
823
823
|
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
824
824
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -827,7 +827,7 @@ describe('Dropzone', () => {
|
|
|
827
827
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
828
828
|
})
|
|
829
829
|
|
|
830
|
-
it('applies the maxSize prop to the dropped images', () => {
|
|
830
|
+
it('applies the maxSize prop to the dropped images', async () => {
|
|
831
831
|
const dropzone = mount(
|
|
832
832
|
<Dropzone
|
|
833
833
|
onDrop={dropSpy}
|
|
@@ -836,7 +836,7 @@ describe('Dropzone', () => {
|
|
|
836
836
|
maxSize={1111}
|
|
837
837
|
/>
|
|
838
838
|
)
|
|
839
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
839
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
840
840
|
expect(dropSpy.callCount).toEqual(1)
|
|
841
841
|
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
842
842
|
expect(dropSpy.firstCall.args[1]).toHaveLength(2)
|
|
@@ -845,7 +845,7 @@ describe('Dropzone', () => {
|
|
|
845
845
|
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(2)
|
|
846
846
|
})
|
|
847
847
|
|
|
848
|
-
it('applies the minSize prop to the dropped files', () => {
|
|
848
|
+
it('applies the minSize prop to the dropped files', async () => {
|
|
849
849
|
const dropzone = mount(
|
|
850
850
|
<Dropzone
|
|
851
851
|
onDrop={dropSpy}
|
|
@@ -854,7 +854,7 @@ describe('Dropzone', () => {
|
|
|
854
854
|
minSize={1112}
|
|
855
855
|
/>
|
|
856
856
|
)
|
|
857
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
857
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
858
858
|
expect(dropSpy.callCount).toEqual(1)
|
|
859
859
|
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
860
860
|
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
@@ -863,7 +863,7 @@ describe('Dropzone', () => {
|
|
|
863
863
|
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
864
864
|
})
|
|
865
865
|
|
|
866
|
-
it('applies the minSize prop to the dropped images', () => {
|
|
866
|
+
it('applies the minSize prop to the dropped images', async () => {
|
|
867
867
|
const dropzone = mount(
|
|
868
868
|
<Dropzone
|
|
869
869
|
onDrop={dropSpy}
|
|
@@ -872,7 +872,7 @@ describe('Dropzone', () => {
|
|
|
872
872
|
minSize={1112}
|
|
873
873
|
/>
|
|
874
874
|
)
|
|
875
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
875
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
876
876
|
expect(dropSpy.callCount).toEqual(1)
|
|
877
877
|
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
878
878
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -881,7 +881,7 @@ describe('Dropzone', () => {
|
|
|
881
881
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
882
882
|
})
|
|
883
883
|
|
|
884
|
-
it('accepts all dropped files and images when no size prop is specified', () => {
|
|
884
|
+
it('accepts all dropped files and images when no size prop is specified', async () => {
|
|
885
885
|
const dropzone = mount(
|
|
886
886
|
<Dropzone
|
|
887
887
|
onDrop={dropSpy}
|
|
@@ -889,7 +889,7 @@ describe('Dropzone', () => {
|
|
|
889
889
|
onDropRejected={dropRejectedSpy}
|
|
890
890
|
/>
|
|
891
891
|
)
|
|
892
|
-
dropzone.simulate('drop', {
|
|
892
|
+
await dropzone.simulate('drop', {
|
|
893
893
|
dataTransfer: { files: files.concat(images) }
|
|
894
894
|
})
|
|
895
895
|
expect(dropSpy.callCount).toEqual(1)
|
|
@@ -902,36 +902,36 @@ describe('Dropzone', () => {
|
|
|
902
902
|
})
|
|
903
903
|
|
|
904
904
|
describe('preview', () => {
|
|
905
|
-
it('should generate previews for non-images', () => {
|
|
905
|
+
it('should generate previews for non-images', async () => {
|
|
906
906
|
const dropSpy = spy()
|
|
907
907
|
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
908
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
908
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
909
909
|
expect(Object.keys(dropSpy.firstCall.args[0][0])).toContain('preview')
|
|
910
910
|
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://file1.pdf')
|
|
911
911
|
})
|
|
912
912
|
|
|
913
|
-
it('should generate previews for images', () => {
|
|
913
|
+
it('should generate previews for images', async () => {
|
|
914
914
|
const dropSpy = spy()
|
|
915
915
|
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
916
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
916
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
917
917
|
expect(Object.keys(dropSpy.firstCall.args[0][0])).toContain('preview')
|
|
918
918
|
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://cats.gif')
|
|
919
919
|
})
|
|
920
920
|
|
|
921
|
-
it('should not throw error when preview cannot be created', () => {
|
|
921
|
+
it('should not throw error when preview cannot be created', async () => {
|
|
922
922
|
const dropSpy = spy()
|
|
923
923
|
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
924
924
|
|
|
925
|
-
dropzone.simulate('drop', { dataTransfer: { files: ['bad_val'] } })
|
|
925
|
+
await dropzone.simulate('drop', { dataTransfer: { files: ['bad_val'] } })
|
|
926
926
|
|
|
927
927
|
expect(Object.keys(dropSpy.firstCall.args[1][0])).not.toContain('preview')
|
|
928
928
|
})
|
|
929
929
|
|
|
930
|
-
it('should not generate previews if disablePreview is true', () => {
|
|
930
|
+
it('should not generate previews if disablePreview is true', async () => {
|
|
931
931
|
const dropSpy = spy()
|
|
932
932
|
const dropzone = mount(<Dropzone disablePreview onDrop={dropSpy} />)
|
|
933
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
934
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
933
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
934
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
935
935
|
expect(dropSpy.callCount).toEqual(2)
|
|
936
936
|
expect(Object.keys(dropSpy.firstCall.args[0][0])).not.toContain('preview')
|
|
937
937
|
expect(Object.keys(dropSpy.lastCall.args[0][0])).not.toContain('preview')
|
|
@@ -1052,8 +1052,8 @@ describe('Dropzone', () => {
|
|
|
1052
1052
|
innerDropzone = outerDropzone.find(InnerDropzone)
|
|
1053
1053
|
})
|
|
1054
1054
|
|
|
1055
|
-
it('does dragEnter on both dropzones', () => {
|
|
1056
|
-
innerDropzone.simulate('dragEnter', {
|
|
1055
|
+
it('does dragEnter on both dropzones', async () => {
|
|
1056
|
+
await innerDropzone.simulate('dragEnter', {
|
|
1057
1057
|
dataTransfer: { files: images }
|
|
1058
1058
|
})
|
|
1059
1059
|
expect(innerDropzone).toHaveProp('isDragActive', true)
|
package/src/utils/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export function getDataTransferItems(event) {
|
|
|
9
9
|
let dataTransferItemsList = []
|
|
10
10
|
if (event.dataTransfer) {
|
|
11
11
|
const dt = event.dataTransfer
|
|
12
|
+
|
|
12
13
|
if (dt.files && dt.files.length) {
|
|
13
14
|
dataTransferItemsList = dt.files
|
|
14
15
|
} else if (dt.items && dt.items.length) {
|
|
@@ -19,6 +20,7 @@ export function getDataTransferItems(event) {
|
|
|
19
20
|
} else if (event.target && event.target.files) {
|
|
20
21
|
dataTransferItemsList = event.target.files
|
|
21
22
|
}
|
|
23
|
+
|
|
22
24
|
// Convert from DataTransferItemsList to the native Array
|
|
23
25
|
return Array.prototype.slice.call(dataTransferItemsList)
|
|
24
26
|
}
|