@@ -633,6 +633,36 @@ describe('CdkDrag', () => {
633633 . toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
634634 } ) ) ;
635635
636+ it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
637+ const fixture = createComponent ( DraggableInDropZone ) ;
638+ fixture . detectChanges ( ) ;
639+
640+ const items = fixture . componentInstance . dragItems . map ( item => item . element . nativeElement ) ;
641+ const draggedItem = items [ 0 ] ;
642+ const { top, left} = draggedItem . getBoundingClientRect ( ) ;
643+
644+ startDraggingViaMouse ( fixture , draggedItem , left , top ) ;
645+
646+ // Drag over each item one-by-one going downwards.
647+ for ( let i = 1 ; i < items . length ; i ++ ) {
648+ const elementRect = items [ i ] . getBoundingClientRect ( ) ;
649+
650+ dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . top + 5 ) ;
651+ fixture . detectChanges ( ) ;
652+
653+ expect ( fixture . componentInstance . sortedSpy . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( {
654+ previousIndex : i - 1 ,
655+ currentIndex : i ,
656+ item : fixture . componentInstance . dragItems . first ,
657+ container : fixture . componentInstance . dropInstance
658+ } ) ;
659+ }
660+
661+ dispatchMouseEvent ( document , 'mouseup' ) ;
662+ fixture . detectChanges ( ) ;
663+ flush ( ) ;
664+ } ) ) ;
665+
636666 it ( 'should not move items in a vertical list if the pointer is too far away' , fakeAsync ( ( ) => {
637667 const fixture = createComponent ( DraggableInDropZone ) ;
638668 fixture . detectChanges ( ) ;
@@ -2075,6 +2105,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
20752105 style="width: 100px; background: pink;"
20762106 [id]="dropZoneId"
20772107 [cdkDropListData]="items"
2108+ (cdkDropListSorted)="sortedSpy($event)"
20782109 (cdkDropListDropped)="droppedSpy($event)">
20792110 <div
20802111 *ngFor="let item of items"
@@ -2097,6 +2128,7 @@ class DraggableInDropZone {
20972128 { value : 'Three' , height : ITEM_HEIGHT , margin : 0 }
20982129 ] ;
20992130 dropZoneId = 'items' ;
2131+ sortedSpy = jasmine . createSpy ( 'sorted spy' ) ;
21002132 droppedSpy = jasmine . createSpy ( 'dropped spy' ) . and . callFake ( ( event : CdkDragDrop < string [ ] > ) => {
21012133 moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
21022134 } ) ;
0 commit comments