@@ -698,6 +698,36 @@ describe('CdkDrag', () => {
698
698
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
699
699
} ) ) ;
700
700
701
+ it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
702
+ const fixture = createComponent ( DraggableInDropZone ) ;
703
+ fixture . detectChanges ( ) ;
704
+
705
+ const items = fixture . componentInstance . dragItems . map ( item => item . element . nativeElement ) ;
706
+ const draggedItem = items [ 0 ] ;
707
+ const { top, left} = draggedItem . getBoundingClientRect ( ) ;
708
+
709
+ startDraggingViaMouse ( fixture , draggedItem , left , top ) ;
710
+
711
+ // Drag over each item one-by-one going downwards.
712
+ for ( let i = 1 ; i < items . length ; i ++ ) {
713
+ const elementRect = items [ i ] . getBoundingClientRect ( ) ;
714
+
715
+ dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . top + 5 ) ;
716
+ fixture . detectChanges ( ) ;
717
+
718
+ expect ( fixture . componentInstance . sortedSpy . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( {
719
+ previousIndex : i - 1 ,
720
+ currentIndex : i ,
721
+ item : fixture . componentInstance . dragItems . first ,
722
+ container : fixture . componentInstance . dropInstance
723
+ } ) ;
724
+ }
725
+
726
+ dispatchMouseEvent ( document , 'mouseup' ) ;
727
+ fixture . detectChanges ( ) ;
728
+ flush ( ) ;
729
+ } ) ) ;
730
+
701
731
it ( 'should not move items in a vertical list if the pointer is too far away' , fakeAsync ( ( ) => {
702
732
const fixture = createComponent ( DraggableInDropZone ) ;
703
733
fixture . detectChanges ( ) ;
@@ -2192,6 +2222,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
2192
2222
style="width: 100px; background: pink;"
2193
2223
[id]="dropZoneId"
2194
2224
[cdkDropListData]="items"
2225
+ (cdkDropListSorted)="sortedSpy($event)"
2195
2226
(cdkDropListDropped)="droppedSpy($event)">
2196
2227
<div
2197
2228
*ngFor="let item of items"
@@ -2214,6 +2245,7 @@ class DraggableInDropZone {
2214
2245
{ value : 'Three' , height : ITEM_HEIGHT , margin : 0 }
2215
2246
] ;
2216
2247
dropZoneId = 'items' ;
2248
+ sortedSpy = jasmine . createSpy ( 'sorted spy' ) ;
2217
2249
droppedSpy = jasmine . createSpy ( 'dropped spy' ) . and . callFake ( ( event : CdkDragDrop < string [ ] > ) => {
2218
2250
moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
2219
2251
} ) ;
0 commit comments