@@ -698,6 +698,36 @@ describe('CdkDrag', () => {
698698 . toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
699699 } ) ) ;
700700
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+
701731 it ( 'should not move items in a vertical list if the pointer is too far away' , fakeAsync ( ( ) => {
702732 const fixture = createComponent ( DraggableInDropZone ) ;
703733 fixture . detectChanges ( ) ;
@@ -2192,6 +2222,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
21922222 style="width: 100px; background: pink;"
21932223 [id]="dropZoneId"
21942224 [cdkDropListData]="items"
2225+ (cdkDropListSorted)="sortedSpy($event)"
21952226 (cdkDropListDropped)="droppedSpy($event)">
21962227 <div
21972228 *ngFor="let item of items"
@@ -2214,6 +2245,7 @@ class DraggableInDropZone {
22142245 { value : 'Three' , height : ITEM_HEIGHT , margin : 0 }
22152246 ] ;
22162247 dropZoneId = 'items' ;
2248+ sortedSpy = jasmine . createSpy ( 'sorted spy' ) ;
22172249 droppedSpy = jasmine . createSpy ( 'dropped spy' ) . and . callFake ( ( event : CdkDragDrop < string [ ] > ) => {
22182250 moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
22192251 } ) ;
0 commit comments