@@ -461,6 +461,41 @@ describe('CdkDrag', () => {
461
461
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
462
462
} ) ) ;
463
463
464
+ it ( 'should not move items in a vertical list if the pointer is too far away' , fakeAsync ( ( ) => {
465
+ const fixture = createComponent ( DraggableInDropZone ) ;
466
+ fixture . detectChanges ( ) ;
467
+ const dragItems = fixture . componentInstance . dragItems ;
468
+
469
+ expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
470
+ . toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
471
+
472
+ const firstItem = dragItems . first ;
473
+ const thirdItemRect = dragItems . toArray ( ) [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
474
+
475
+ // Move the cursor all the way to the right so it doesn't intersect along the x axis.
476
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
477
+ thirdItemRect . right + 1000 , thirdItemRect . top + 1 ) ;
478
+ flush ( ) ;
479
+ fixture . detectChanges ( ) ;
480
+
481
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
482
+
483
+ const event = fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
484
+
485
+ // Assert the event like this, rather than `toHaveBeenCalledWith`, because Jasmine will
486
+ // go into an infinite loop trying to stringify the event, if the test fails.
487
+ expect ( event ) . toEqual ( {
488
+ previousIndex : 0 ,
489
+ currentIndex : 0 ,
490
+ item : firstItem ,
491
+ container : fixture . componentInstance . dropInstance ,
492
+ previousContainer : fixture . componentInstance . dropInstance
493
+ } ) ;
494
+
495
+ expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
496
+ . toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
497
+ } ) ) ;
498
+
464
499
it ( 'should not move the original element from its initial DOM position' , fakeAsync ( ( ) => {
465
500
const fixture = createComponent ( DraggableInDropZone ) ;
466
501
fixture . detectChanges ( ) ;
@@ -518,6 +553,41 @@ describe('CdkDrag', () => {
518
553
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
519
554
} ) ) ;
520
555
556
+ it ( 'should not move items in a horizontal list if pointer is too far away' , fakeAsync ( ( ) => {
557
+ const fixture = createComponent ( DraggableInHorizontalDropZone ) ;
558
+ fixture . detectChanges ( ) ;
559
+ const dragItems = fixture . componentInstance . dragItems ;
560
+
561
+ expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
562
+ . toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
563
+
564
+ const firstItem = dragItems . first ;
565
+ const thirdItemRect = dragItems . toArray ( ) [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
566
+
567
+ // Move the cursor all the way to the bottom so it doesn't intersect along the y axis.
568
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
569
+ thirdItemRect . left + 1 , thirdItemRect . bottom + 1000 ) ;
570
+ flush ( ) ;
571
+ fixture . detectChanges ( ) ;
572
+
573
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
574
+
575
+ const event = fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
576
+
577
+ // Assert the event like this, rather than `toHaveBeenCalledWith`, because Jasmine will
578
+ // go into an infinite loop trying to stringify the event, if the test fails.
579
+ expect ( event ) . toEqual ( {
580
+ previousIndex : 0 ,
581
+ currentIndex : 0 ,
582
+ item : firstItem ,
583
+ container : fixture . componentInstance . dropInstance ,
584
+ previousContainer : fixture . componentInstance . dropInstance
585
+ } ) ;
586
+
587
+ expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
588
+ . toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
589
+ } ) ) ;
590
+
521
591
it ( 'should create a preview element while the item is dragged' , fakeAsync ( ( ) => {
522
592
const fixture = createComponent ( DraggableInDropZone ) ;
523
593
fixture . detectChanges ( ) ;
0 commit comments