@@ -765,13 +765,55 @@ describe('CdkDrag', () => {
765
765
currentIndex : 2 ,
766
766
item : firstItem ,
767
767
container : fixture . componentInstance . dropInstance ,
768
- previousContainer : fixture . componentInstance . dropInstance
768
+ previousContainer : fixture . componentInstance . dropInstance ,
769
+ isPointerOverContainer : true
769
770
} ) ;
770
771
771
772
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
772
773
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
773
774
} ) ) ;
774
775
776
+ it ( 'should expose whether an item was dropped over a container' , fakeAsync ( ( ) => {
777
+ const fixture = createComponent ( DraggableInDropZone ) ;
778
+ fixture . detectChanges ( ) ;
779
+ const dragItems = fixture . componentInstance . dragItems ;
780
+ const firstItem = dragItems . first ;
781
+ const thirdItemRect = dragItems . toArray ( ) [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
782
+
783
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
784
+ thirdItemRect . left + 1 , thirdItemRect . top + 1 ) ;
785
+ flush ( ) ;
786
+ fixture . detectChanges ( ) ;
787
+
788
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
789
+
790
+ const event : CdkDragDrop < any > =
791
+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
792
+
793
+ expect ( event . isPointerOverContainer ) . toBe ( true ) ;
794
+ } ) ) ;
795
+
796
+ it ( 'should expose whether an item was dropped outside of a container' , fakeAsync ( ( ) => {
797
+ const fixture = createComponent ( DraggableInDropZone ) ;
798
+ fixture . detectChanges ( ) ;
799
+ const dragItems = fixture . componentInstance . dragItems ;
800
+ const firstItem = dragItems . first ;
801
+ const containerRect = fixture . componentInstance . dropInstance . element
802
+ . nativeElement . getBoundingClientRect ( ) ;
803
+
804
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
805
+ containerRect . right + 10 , containerRect . bottom + 10 ) ;
806
+ flush ( ) ;
807
+ fixture . detectChanges ( ) ;
808
+
809
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
810
+
811
+ const event : CdkDragDrop < any > =
812
+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
813
+
814
+ expect ( event . isPointerOverContainer ) . toBe ( false ) ;
815
+ } ) ) ;
816
+
775
817
it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
776
818
const fixture = createComponent ( DraggableInDropZone ) ;
777
819
fixture . detectChanges ( ) ;
@@ -830,7 +872,8 @@ describe('CdkDrag', () => {
830
872
currentIndex : 0 ,
831
873
item : firstItem ,
832
874
container : fixture . componentInstance . dropInstance ,
833
- previousContainer : fixture . componentInstance . dropInstance
875
+ previousContainer : fixture . componentInstance . dropInstance ,
876
+ isPointerOverContainer : false
834
877
} ) ;
835
878
836
879
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -887,7 +930,8 @@ describe('CdkDrag', () => {
887
930
currentIndex : 2 ,
888
931
item : firstItem ,
889
932
container : fixture . componentInstance . dropInstance ,
890
- previousContainer : fixture . componentInstance . dropInstance
933
+ previousContainer : fixture . componentInstance . dropInstance ,
934
+ isPointerOverContainer : true
891
935
} ) ;
892
936
893
937
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -926,7 +970,8 @@ describe('CdkDrag', () => {
926
970
currentIndex : 2 ,
927
971
item : firstItem ,
928
972
container : fixture . componentInstance . dropInstance ,
929
- previousContainer : fixture . componentInstance . dropInstance
973
+ previousContainer : fixture . componentInstance . dropInstance ,
974
+ isPointerOverContainer : true
930
975
} ) ;
931
976
932
977
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -961,7 +1006,8 @@ describe('CdkDrag', () => {
961
1006
currentIndex : 0 ,
962
1007
item : firstItem ,
963
1008
container : fixture . componentInstance . dropInstance ,
964
- previousContainer : fixture . componentInstance . dropInstance
1009
+ previousContainer : fixture . componentInstance . dropInstance ,
1010
+ isPointerOverContainer : false
965
1011
} ) ;
966
1012
967
1013
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -1797,7 +1843,8 @@ describe('CdkDrag', () => {
1797
1843
currentIndex : 3 ,
1798
1844
item,
1799
1845
container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
1800
- previousContainer : fixture . componentInstance . dropInstances . first
1846
+ previousContainer : fixture . componentInstance . dropInstances . first ,
1847
+ isPointerOverContainer : true
1801
1848
} ) ;
1802
1849
} ) ) ;
1803
1850
@@ -1898,7 +1945,8 @@ describe('CdkDrag', () => {
1898
1945
currentIndex : 3 ,
1899
1946
item : groups [ 0 ] [ 1 ] ,
1900
1947
container : dropInstances [ 1 ] ,
1901
- previousContainer : dropInstances [ 0 ]
1948
+ previousContainer : dropInstances [ 0 ] ,
1949
+ isPointerOverContainer : true
1902
1950
} ) ;
1903
1951
} ) ) ;
1904
1952
@@ -1927,7 +1975,8 @@ describe('CdkDrag', () => {
1927
1975
currentIndex : 1 ,
1928
1976
item : groups [ 0 ] [ 1 ] ,
1929
1977
container : dropInstances [ 0 ] ,
1930
- previousContainer : dropInstances [ 0 ]
1978
+ previousContainer : dropInstances [ 0 ] ,
1979
+ isPointerOverContainer : false
1931
1980
} ) ;
1932
1981
} ) ) ;
1933
1982
@@ -1956,7 +2005,8 @@ describe('CdkDrag', () => {
1956
2005
currentIndex : 1 ,
1957
2006
item : groups [ 0 ] [ 1 ] ,
1958
2007
container : dropInstances [ 0 ] ,
1959
- previousContainer : dropInstances [ 0 ]
2008
+ previousContainer : dropInstances [ 0 ] ,
2009
+ isPointerOverContainer : false
1960
2010
} ) ;
1961
2011
} ) ) ;
1962
2012
@@ -2078,7 +2128,8 @@ describe('CdkDrag', () => {
2078
2128
currentIndex : 3 ,
2079
2129
item : groups [ 0 ] [ 1 ] ,
2080
2130
container : dropInstances [ 1 ] ,
2081
- previousContainer : dropInstances [ 0 ]
2131
+ previousContainer : dropInstances [ 0 ] ,
2132
+ isPointerOverContainer : true
2082
2133
} ) ;
2083
2134
} ) ) ;
2084
2135
@@ -2103,7 +2154,8 @@ describe('CdkDrag', () => {
2103
2154
currentIndex : 3 ,
2104
2155
item : groups [ 0 ] [ 1 ] ,
2105
2156
container : dropInstances [ 1 ] ,
2106
- previousContainer : dropInstances [ 0 ]
2157
+ previousContainer : dropInstances [ 0 ] ,
2158
+ isPointerOverContainer : true
2107
2159
} ) ;
2108
2160
} ) ) ;
2109
2161
@@ -2133,7 +2185,8 @@ describe('CdkDrag', () => {
2133
2185
currentIndex : 3 ,
2134
2186
item : groups [ 0 ] [ 1 ] ,
2135
2187
container : dropInstances [ 1 ] ,
2136
- previousContainer : dropInstances [ 0 ]
2188
+ previousContainer : dropInstances [ 0 ] ,
2189
+ isPointerOverContainer : true
2137
2190
} ) ;
2138
2191
} ) ) ;
2139
2192
@@ -2167,7 +2220,8 @@ describe('CdkDrag', () => {
2167
2220
currentIndex : 0 ,
2168
2221
item,
2169
2222
container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
2170
- previousContainer : fixture . componentInstance . dropInstances . first
2223
+ previousContainer : fixture . componentInstance . dropInstances . first ,
2224
+ isPointerOverContainer : true
2171
2225
} ) ;
2172
2226
2173
2227
expect ( dropContainers [ 0 ] . contains ( item . element . nativeElement ) ) . toBe ( true ,
@@ -2656,7 +2710,7 @@ function dragElementViaMouse(fixture: ComponentFixture<any>,
2656
2710
dispatchMouseEvent ( document , 'mousemove' , x , y ) ;
2657
2711
fixture . detectChanges ( ) ;
2658
2712
2659
- dispatchMouseEvent ( document , 'mouseup' ) ;
2713
+ dispatchMouseEvent ( document , 'mouseup' , x , y ) ;
2660
2714
fixture . detectChanges ( ) ;
2661
2715
}
2662
2716
@@ -2695,7 +2749,7 @@ function dragElementViaTouch(fixture: ComponentFixture<any>,
2695
2749
dispatchTouchEvent ( document , 'touchmove' , x , y ) ;
2696
2750
fixture . detectChanges ( ) ;
2697
2751
2698
- dispatchTouchEvent ( document , 'touchend' ) ;
2752
+ dispatchTouchEvent ( document , 'touchend' , x , y ) ;
2699
2753
fixture . detectChanges ( ) ;
2700
2754
}
2701
2755
0 commit comments