@@ -633,6 +633,36 @@ describe('CdkDrag', () => {
633
633
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
634
634
} ) ) ;
635
635
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
+
636
666
it ( 'should not move items in a vertical list if the pointer is too far away' , fakeAsync ( ( ) => {
637
667
const fixture = createComponent ( DraggableInDropZone ) ;
638
668
fixture . detectChanges ( ) ;
@@ -2075,6 +2105,7 @@ const DROP_ZONE_FIXTURE_TEMPLATE = `
2075
2105
style="width: 100px; background: pink;"
2076
2106
[id]="dropZoneId"
2077
2107
[cdkDropListData]="items"
2108
+ (cdkDropListSorted)="sortedSpy($event)"
2078
2109
(cdkDropListDropped)="droppedSpy($event)">
2079
2110
<div
2080
2111
*ngFor="let item of items"
@@ -2097,6 +2128,7 @@ class DraggableInDropZone {
2097
2128
{ value : 'Three' , height : ITEM_HEIGHT , margin : 0 }
2098
2129
] ;
2099
2130
dropZoneId = 'items' ;
2131
+ sortedSpy = jasmine . createSpy ( 'sorted spy' ) ;
2100
2132
droppedSpy = jasmine . createSpy ( 'dropped spy' ) . and . callFake ( ( event : CdkDragDrop < string [ ] > ) => {
2101
2133
moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
2102
2134
} ) ;
0 commit comments