@@ -776,13 +776,55 @@ describe('CdkDrag', () => {
776
776
currentIndex : 2 ,
777
777
item : firstItem ,
778
778
container : fixture . componentInstance . dropInstance ,
779
- previousContainer : fixture . componentInstance . dropInstance
779
+ previousContainer : fixture . componentInstance . dropInstance ,
780
+ isPointerOverContainer : true
780
781
} ) ;
781
782
782
783
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
783
784
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
784
785
} ) ) ;
785
786
787
+ it ( 'should expose whether an item was dropped over a container' , fakeAsync ( ( ) => {
788
+ const fixture = createComponent ( DraggableInDropZone ) ;
789
+ fixture . detectChanges ( ) ;
790
+ const dragItems = fixture . componentInstance . dragItems ;
791
+ const firstItem = dragItems . first ;
792
+ const thirdItemRect = dragItems . toArray ( ) [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
793
+
794
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
795
+ thirdItemRect . left + 1 , thirdItemRect . top + 1 ) ;
796
+ flush ( ) ;
797
+ fixture . detectChanges ( ) ;
798
+
799
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
800
+
801
+ const event : CdkDragDrop < any > =
802
+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
803
+
804
+ expect ( event . isPointerOverContainer ) . toBe ( true ) ;
805
+ } ) ) ;
806
+
807
+ it ( 'should expose whether an item was dropped outside of a container' , fakeAsync ( ( ) => {
808
+ const fixture = createComponent ( DraggableInDropZone ) ;
809
+ fixture . detectChanges ( ) ;
810
+ const dragItems = fixture . componentInstance . dragItems ;
811
+ const firstItem = dragItems . first ;
812
+ const containerRect = fixture . componentInstance . dropInstance . element
813
+ . nativeElement . getBoundingClientRect ( ) ;
814
+
815
+ dragElementViaMouse ( fixture , firstItem . element . nativeElement ,
816
+ containerRect . right + 10 , containerRect . bottom + 10 ) ;
817
+ flush ( ) ;
818
+ fixture . detectChanges ( ) ;
819
+
820
+ expect ( fixture . componentInstance . droppedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
821
+
822
+ const event : CdkDragDrop < any > =
823
+ fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
824
+
825
+ expect ( event . isPointerOverContainer ) . toBe ( false ) ;
826
+ } ) ) ;
827
+
786
828
it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
787
829
const fixture = createComponent ( DraggableInDropZone ) ;
788
830
fixture . detectChanges ( ) ;
@@ -841,7 +883,8 @@ describe('CdkDrag', () => {
841
883
currentIndex : 0 ,
842
884
item : firstItem ,
843
885
container : fixture . componentInstance . dropInstance ,
844
- previousContainer : fixture . componentInstance . dropInstance
886
+ previousContainer : fixture . componentInstance . dropInstance ,
887
+ isPointerOverContainer : false
845
888
} ) ;
846
889
847
890
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -898,7 +941,8 @@ describe('CdkDrag', () => {
898
941
currentIndex : 2 ,
899
942
item : firstItem ,
900
943
container : fixture . componentInstance . dropInstance ,
901
- previousContainer : fixture . componentInstance . dropInstance
944
+ previousContainer : fixture . componentInstance . dropInstance ,
945
+ isPointerOverContainer : true
902
946
} ) ;
903
947
904
948
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -937,7 +981,8 @@ describe('CdkDrag', () => {
937
981
currentIndex : 2 ,
938
982
item : firstItem ,
939
983
container : fixture . componentInstance . dropInstance ,
940
- previousContainer : fixture . componentInstance . dropInstance
984
+ previousContainer : fixture . componentInstance . dropInstance ,
985
+ isPointerOverContainer : true
941
986
} ) ;
942
987
943
988
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -972,7 +1017,8 @@ describe('CdkDrag', () => {
972
1017
currentIndex : 0 ,
973
1018
item : firstItem ,
974
1019
container : fixture . componentInstance . dropInstance ,
975
- previousContainer : fixture . componentInstance . dropInstance
1020
+ previousContainer : fixture . componentInstance . dropInstance ,
1021
+ isPointerOverContainer : false
976
1022
} ) ;
977
1023
978
1024
expect ( dragItems . map ( drag => drag . element . nativeElement . textContent ! . trim ( ) ) )
@@ -1808,7 +1854,8 @@ describe('CdkDrag', () => {
1808
1854
currentIndex : 3 ,
1809
1855
item,
1810
1856
container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
1811
- previousContainer : fixture . componentInstance . dropInstances . first
1857
+ previousContainer : fixture . componentInstance . dropInstances . first ,
1858
+ isPointerOverContainer : true
1812
1859
} ) ;
1813
1860
} ) ) ;
1814
1861
@@ -1909,7 +1956,8 @@ describe('CdkDrag', () => {
1909
1956
currentIndex : 3 ,
1910
1957
item : groups [ 0 ] [ 1 ] ,
1911
1958
container : dropInstances [ 1 ] ,
1912
- previousContainer : dropInstances [ 0 ]
1959
+ previousContainer : dropInstances [ 0 ] ,
1960
+ isPointerOverContainer : true
1913
1961
} ) ;
1914
1962
} ) ) ;
1915
1963
@@ -1938,7 +1986,8 @@ describe('CdkDrag', () => {
1938
1986
currentIndex : 1 ,
1939
1987
item : groups [ 0 ] [ 1 ] ,
1940
1988
container : dropInstances [ 0 ] ,
1941
- previousContainer : dropInstances [ 0 ]
1989
+ previousContainer : dropInstances [ 0 ] ,
1990
+ isPointerOverContainer : false
1942
1991
} ) ;
1943
1992
} ) ) ;
1944
1993
@@ -1967,7 +2016,8 @@ describe('CdkDrag', () => {
1967
2016
currentIndex : 1 ,
1968
2017
item : groups [ 0 ] [ 1 ] ,
1969
2018
container : dropInstances [ 0 ] ,
1970
- previousContainer : dropInstances [ 0 ]
2019
+ previousContainer : dropInstances [ 0 ] ,
2020
+ isPointerOverContainer : false
1971
2021
} ) ;
1972
2022
} ) ) ;
1973
2023
@@ -2089,7 +2139,8 @@ describe('CdkDrag', () => {
2089
2139
currentIndex : 3 ,
2090
2140
item : groups [ 0 ] [ 1 ] ,
2091
2141
container : dropInstances [ 1 ] ,
2092
- previousContainer : dropInstances [ 0 ]
2142
+ previousContainer : dropInstances [ 0 ] ,
2143
+ isPointerOverContainer : true
2093
2144
} ) ;
2094
2145
} ) ) ;
2095
2146
@@ -2114,7 +2165,8 @@ describe('CdkDrag', () => {
2114
2165
currentIndex : 3 ,
2115
2166
item : groups [ 0 ] [ 1 ] ,
2116
2167
container : dropInstances [ 1 ] ,
2117
- previousContainer : dropInstances [ 0 ]
2168
+ previousContainer : dropInstances [ 0 ] ,
2169
+ isPointerOverContainer : true
2118
2170
} ) ;
2119
2171
} ) ) ;
2120
2172
@@ -2144,7 +2196,8 @@ describe('CdkDrag', () => {
2144
2196
currentIndex : 3 ,
2145
2197
item : groups [ 0 ] [ 1 ] ,
2146
2198
container : dropInstances [ 1 ] ,
2147
- previousContainer : dropInstances [ 0 ]
2199
+ previousContainer : dropInstances [ 0 ] ,
2200
+ isPointerOverContainer : true
2148
2201
} ) ;
2149
2202
} ) ) ;
2150
2203
@@ -2178,7 +2231,8 @@ describe('CdkDrag', () => {
2178
2231
currentIndex : 0 ,
2179
2232
item,
2180
2233
container : fixture . componentInstance . dropInstances . toArray ( ) [ 1 ] ,
2181
- previousContainer : fixture . componentInstance . dropInstances . first
2234
+ previousContainer : fixture . componentInstance . dropInstances . first ,
2235
+ isPointerOverContainer : true
2182
2236
} ) ;
2183
2237
2184
2238
expect ( dropContainers [ 0 ] . contains ( item . element . nativeElement ) ) . toBe ( true ,
@@ -2667,7 +2721,7 @@ function dragElementViaMouse(fixture: ComponentFixture<any>,
2667
2721
dispatchMouseEvent ( document , 'mousemove' , x , y ) ;
2668
2722
fixture . detectChanges ( ) ;
2669
2723
2670
- dispatchMouseEvent ( document , 'mouseup' ) ;
2724
+ dispatchMouseEvent ( document , 'mouseup' , x , y ) ;
2671
2725
fixture . detectChanges ( ) ;
2672
2726
}
2673
2727
@@ -2706,7 +2760,7 @@ function dragElementViaTouch(fixture: ComponentFixture<any>,
2706
2760
dispatchTouchEvent ( document , 'touchmove' , x , y ) ;
2707
2761
fixture . detectChanges ( ) ;
2708
2762
2709
- dispatchTouchEvent ( document , 'touchend' ) ;
2763
+ dispatchTouchEvent ( document , 'touchend' , x , y ) ;
2710
2764
fixture . detectChanges ( ) ;
2711
2765
}
2712
2766
0 commit comments