@@ -232,22 +232,35 @@ describe('form-file', () => {
232
232
233
233
// Emulate the files array
234
234
wrapper . vm . setFiles ( files )
235
+ await waitNT ( wrapper . vm )
235
236
expect ( wrapper . emitted ( 'input' ) ) . toBeDefined ( )
236
237
expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 1 )
237
238
expect ( wrapper . emitted ( 'input' ) [ 0 ] [ 0 ] ) . toEqual ( files )
238
239
239
240
// Setting to same array of files should not emit event
240
241
wrapper . vm . setFiles ( files )
242
+ await waitNT ( wrapper . vm )
241
243
expect ( wrapper . emitted ( 'input' ) ) . toBeDefined ( )
242
244
expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 1 )
243
245
244
246
// Setting to new array of same files should not emit event
245
247
wrapper . vm . setFiles ( [ file1 , file2 ] )
248
+ await waitNT ( wrapper . vm )
246
249
expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 1 )
247
250
248
251
// Setting to array of new files should emit event
249
252
wrapper . vm . setFiles ( files . slice ( ) . reverse ( ) )
253
+ await waitNT ( wrapper . vm )
250
254
expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 2 )
255
+ expect ( wrapper . emitted ( 'input' ) [ 1 ] [ 0 ] ) . toEqual ( files . slice ( ) . reverse ( ) )
256
+
257
+ // Internally setting `selectedFile` to `null` should emit empty array
258
+ wrapper . setData ( {
259
+ selectedFile : null
260
+ } )
261
+ await waitNT ( wrapper . vm )
262
+ expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 3 )
263
+ expect ( wrapper . emitted ( 'input' ) [ 2 ] [ 0 ] ) . toEqual ( [ ] )
251
264
252
265
wrapper . destroy ( )
253
266
} )
@@ -498,6 +511,83 @@ describe('form-file', () => {
498
511
wrapper . destroy ( )
499
512
} )
500
513
514
+ it ( 'drag placeholder and drop works' , async ( ) => {
515
+ const wrapper = mount ( BFormFile , {
516
+ propsData : {
517
+ id : 'foo' ,
518
+ placeholder : 'PLACEHOLDER' ,
519
+ dropPlaceholder : 'DROPHERE' ,
520
+ noDrop : true
521
+ }
522
+ } )
523
+ const file = new File ( [ 'foo' ] , 'foo.txt' , {
524
+ type : 'text/plain' ,
525
+ lastModified : Date . now ( )
526
+ } )
527
+
528
+ expect ( wrapper . isVueInstance ( ) ) . toBe ( true )
529
+ const $label = wrapper . find ( 'label' )
530
+ expect ( $label . exists ( ) ) . toBe ( true )
531
+ expect ( $label . text ( ) ) . toContain ( 'PLACEHOLDER' )
532
+ expect ( $label . text ( ) ) . not . toContain ( 'DROPHERE' )
533
+
534
+ wrapper . trigger ( 'dragover' )
535
+ await waitNT ( wrapper . vm )
536
+
537
+ expect ( $label . text ( ) ) . toContain ( 'PLACEHOLDER' )
538
+ expect ( $label . text ( ) ) . not . toContain ( 'DROPHERE' )
539
+
540
+ wrapper . trigger ( 'drop' , {
541
+ dataTransfer : {
542
+ files : [ file ]
543
+ }
544
+ } )
545
+ await waitNT ( wrapper . vm )
546
+
547
+ expect ( $label . text ( ) ) . toContain ( 'PLACEHOLDER' )
548
+ expect ( $label . text ( ) ) . not . toContain ( 'DROPHERE' )
549
+ expect ( $label . text ( ) ) . not . toContain ( file . name )
550
+
551
+ wrapper . setProps ( {
552
+ noDrop : false
553
+ } )
554
+ await waitNT ( wrapper . vm )
555
+
556
+ expect ( $label . text ( ) ) . toContain ( 'PLACEHOLDER' )
557
+ expect ( $label . text ( ) ) . not . toContain ( 'DROPHERE' )
558
+
559
+ wrapper . trigger ( 'dragover' )
560
+ await waitNT ( wrapper . vm )
561
+
562
+ expect ( $label . text ( ) ) . not . toContain ( 'PLACEHOLDER' )
563
+ expect ( $label . text ( ) ) . toContain ( 'DROPHERE' )
564
+
565
+ wrapper . trigger ( 'dragleave' )
566
+ await waitNT ( wrapper . vm )
567
+
568
+ expect ( $label . text ( ) ) . toContain ( 'PLACEHOLDER' )
569
+ expect ( $label . text ( ) ) . not . toContain ( 'DROPHERE' )
570
+
571
+ wrapper . trigger ( 'dragover' )
572
+ await waitNT ( wrapper . vm )
573
+
574
+ expect ( $label . text ( ) ) . not . toContain ( 'PLACEHOLDER' )
575
+ expect ( $label . text ( ) ) . toContain ( 'DROPHERE' )
576
+
577
+ wrapper . trigger ( 'drop' , {
578
+ dataTransfer : {
579
+ files : [ file ]
580
+ }
581
+ } )
582
+ await waitNT ( wrapper . vm )
583
+
584
+ expect ( $label . text ( ) ) . not . toContain ( 'PLACEHOLDER' )
585
+ expect ( $label . text ( ) ) . not . toContain ( 'DROPHERE' )
586
+ expect ( $label . text ( ) ) . toContain ( file . name )
587
+
588
+ wrapper . destroy ( )
589
+ } )
590
+
501
591
// These tests are wrapped in a new describe to limit the scope of the getBCR Mock
502
592
describe ( 'prop `autofocus`' , ( ) => {
503
593
const origGetBCR = Element . prototype . getBoundingClientRect
0 commit comments