@@ -691,13 +691,55 @@ describe('CdkDrag', () => {
691
691
currentIndex : 2 ,
692
692
item : firstItem ,
693
693
container : fixture . componentInstance . dropInstance ,
694
- previousContainer : fixture . componentInstance . dropInstance
694
+ previousContainer : fixture . componentInstance . dropInstance ,
695
+ isPointerOverContainer : true
695
696
} ) ;
696
697
697
698
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
698
699
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
699
700
} ) ) ;
700
701
702
+ it ( 'should expose whether an item was dropped over a container' , fakeAsync ( ( ) => {
703
+ const fixture = createComponent ( DraggableInDropZone ) ;
704
+ fixture . detectChanges ( ) ;
705
+ const dragItems = fixture . componentInstance . dragItems ;
706
+ const firstItem = dragItems . first ;
707
+ const thirdItemRect = dragItems . toArray ( ) [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
708
+
709
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
710
+ thirdItemRect . left + 1 , thirdItemRect . top + 1 ) ;
711
+ flush ( ) ;
712
+ fixture . detectChanges ( ) ;
713
+
714
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
715
+
716
+ const event : CdkDragDrop < any > =
717
+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
718
+
719
+ expect ( event . isPointerOverContainer ) . toBe ( true ) ;
720
+ } ) ) ;
721
+
722
+ it ( 'should expose whether an item was dropped outside of a container' , fakeAsync ( ( ) => {
723
+ const fixture = createComponent ( DraggableInDropZone ) ;
724
+ fixture . detectChanges ( ) ;
725
+ const dragItems = fixture . componentInstance . dragItems ;
726
+ const firstItem = dragItems . first ;
727
+ const containerRect = fixture . componentInstance . dropInstance . element
728
+ . nativeElement . getBoundingClientRect ( ) ;
729
+
730
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
731
+ containerRect . right + 10 , containerRect . bottom + 10 ) ;
732
+ flush ( ) ;
733
+ fixture . detectChanges ( ) ;
734
+
735
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
736
+
737
+ const event : CdkDragDrop < any > =
738
+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
739
+
740
+ expect ( event . isPointerOverContainer ) . toBe ( false ) ;
741
+ } ) ) ;
742
+
701
743
it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
702
744
const fixture = createComponent ( DraggableInDropZone ) ;
703
745
fixture . detectChanges ( ) ;
@@ -756,7 +798,8 @@ describe('CdkDrag', () => {
756
798
currentIndex : 0 ,
757
799
item : firstItem ,
758
800
container : fixture . componentInstance . dropInstance ,
759
- previousContainer : fixture . componentInstance . dropInstance
801
+ previousContainer : fixture . componentInstance . dropInstance ,
802
+ isPointerOverContainer : false
760
803
} ) ;
761
804
762
805
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -813,7 +856,8 @@ describe('CdkDrag', () => {
813
856
currentIndex : 2 ,
814
857
item : firstItem ,
815
858
container : fixture . componentInstance . dropInstance ,
816
- previousContainer : fixture . componentInstance . dropInstance
859
+ previousContainer : fixture . componentInstance . dropInstance ,
860
+ isPointerOverContainer : true
817
861
} ) ;
818
862
819
863
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -852,7 +896,8 @@ describe('CdkDrag', () => {
852
896
currentIndex : 2 ,
853
897
item : firstItem ,
854
898
container : fixture . componentInstance . dropInstance ,
855
- previousContainer : fixture . componentInstance . dropInstance
899
+ previousContainer : fixture . componentInstance . dropInstance ,
900
+ isPointerOverContainer : true
856
901
} ) ;
857
902
858
903
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -887,7 +932,8 @@ describe('CdkDrag', () => {
887
932
currentIndex : 0 ,
888
933
item : firstItem ,
889
934
container : fixture . componentInstance . dropInstance ,
890
- previousContainer : fixture . componentInstance . dropInstance
935
+ previousContainer : fixture . componentInstance . dropInstance ,
936
+ isPointerOverContainer : false
891
937
} ) ;
892
938
893
939
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -1699,7 +1745,8 @@ describe('CdkDrag', () => {
1699
1745
currentIndex : 3 ,
1700
1746
item,
1701
1747
container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
1702
- previousContainer : fixture . componentInstance . dropInstances . first
1748
+ previousContainer : fixture . componentInstance . dropInstances . first ,
1749
+ isPointerOverContainer : true
1703
1750
} ) ;
1704
1751
} ) ) ;
1705
1752
@@ -1800,7 +1847,8 @@ describe('CdkDrag', () => {
1800
1847
currentIndex : 3 ,
1801
1848
item : groups [ 0 ] [ 1 ] ,
1802
1849
container : dropInstances [ 1 ] ,
1803
- previousContainer : dropInstances [ 0 ]
1850
+ previousContainer : dropInstances [ 0 ] ,
1851
+ isPointerOverContainer : true
1804
1852
} ) ;
1805
1853
} ) ) ;
1806
1854
@@ -1829,7 +1877,8 @@ describe('CdkDrag', () => {
1829
1877
currentIndex : 1 ,
1830
1878
item : groups [ 0 ] [ 1 ] ,
1831
1879
container : dropInstances [ 0 ] ,
1832
- previousContainer : dropInstances [ 0 ]
1880
+ previousContainer : dropInstances [ 0 ] ,
1881
+ isPointerOverContainer : false
1833
1882
} ) ;
1834
1883
} ) ) ;
1835
1884
@@ -1858,7 +1907,8 @@ describe('CdkDrag', () => {
1858
1907
currentIndex : 1 ,
1859
1908
item : groups [ 0 ] [ 1 ] ,
1860
1909
container : dropInstances [ 0 ] ,
1861
- previousContainer : dropInstances [ 0 ]
1910
+ previousContainer : dropInstances [ 0 ] ,
1911
+ isPointerOverContainer : false
1862
1912
} ) ;
1863
1913
} ) ) ;
1864
1914
@@ -1980,7 +2030,8 @@ describe('CdkDrag', () => {
1980
2030
currentIndex : 3 ,
1981
2031
item : groups [ 0 ] [ 1 ] ,
1982
2032
container : dropInstances [ 1 ] ,
1983
- previousContainer : dropInstances [ 0 ]
2033
+ previousContainer : dropInstances [ 0 ] ,
2034
+ isPointerOverContainer : true
1984
2035
} ) ;
1985
2036
} ) ) ;
1986
2037
@@ -2005,7 +2056,8 @@ describe('CdkDrag', () => {
2005
2056
currentIndex : 3 ,
2006
2057
item : groups [ 0 ] [ 1 ] ,
2007
2058
container : dropInstances [ 1 ] ,
2008
- previousContainer : dropInstances [ 0 ]
2059
+ previousContainer : dropInstances [ 0 ] ,
2060
+ isPointerOverContainer : true
2009
2061
} ) ;
2010
2062
} ) ) ;
2011
2063
@@ -2035,7 +2087,8 @@ describe('CdkDrag', () => {
2035
2087
currentIndex : 3 ,
2036
2088
item : groups [ 0 ] [ 1 ] ,
2037
2089
container : dropInstances [ 1 ] ,
2038
- previousContainer : dropInstances [ 0 ]
2090
+ previousContainer : dropInstances [ 0 ] ,
2091
+ isPointerOverContainer : true
2039
2092
} ) ;
2040
2093
} ) ) ;
2041
2094
@@ -2069,7 +2122,8 @@ describe('CdkDrag', () => {
2069
2122
currentIndex : 0 ,
2070
2123
item,
2071
2124
container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
2072
- previousContainer : fixture . componentInstance . dropInstances . first
2125
+ previousContainer : fixture . componentInstance . dropInstances . first ,
2126
+ isPointerOverContainer : true
2073
2127
} ) ;
2074
2128
2075
2129
expect ( dropContainers [ 0 ] . contains ( item . element . nativeElement ) ) . toBe ( true ,
@@ -2516,7 +2570,7 @@ function dragElementViaMouse(fixture: ComponentFixture<any>,
2516
2570
dispatchMouseEvent ( document , 'mousemove' , x , y ) ;
2517
2571
fixture . detectChanges ( ) ;
2518
2572
2519
- dispatchMouseEvent ( document , 'mouseup' ) ;
2573
+ dispatchMouseEvent ( document , 'mouseup' , x , y ) ;
2520
2574
fixture . detectChanges ( ) ;
2521
2575
}
2522
2576
@@ -2555,7 +2609,7 @@ function dragElementViaTouch(fixture: ComponentFixture<any>,
2555
2609
dispatchTouchEvent ( document , 'touchmove' , x , y ) ;
2556
2610
fixture . detectChanges ( ) ;
2557
2611
2558
- dispatchTouchEvent ( document , 'touchend' ) ;
2612
+ dispatchTouchEvent ( document , 'touchend' , x , y ) ;
2559
2613
fixture . detectChanges ( ) ;
2560
2614
}
2561
2615
0 commit comments