@@ -581,6 +581,36 @@ describe('CdkDrag', () => {
581
581
. toEqual ( [ 'One' , 'Two' , 'Zero' , 'Three' ] ) ;
582
582
} ) ) ;
583
583
584
+ it ( 'should dispatch the `sorted` event as an item is being sorted' , fakeAsync ( ( ) => {
585
+ const fixture = createComponent ( DraggableInDropZone ) ;
586
+ fixture . detectChanges ( ) ;
587
+
588
+ const items = fixture . componentInstance . dragItems . map ( item => item . element . nativeElement ) ;
589
+ const draggedItem = items [ 0 ] ;
590
+ const { top, left} = draggedItem . getBoundingClientRect ( ) ;
591
+
592
+ startDraggingViaMouse ( fixture , draggedItem , left , top ) ;
593
+
594
+ // Drag over each item one-by-one going downwards.
595
+ for ( let i = 1 ; i < items . length ; i ++ ) {
596
+ const elementRect = items [ i ] . getBoundingClientRect ( ) ;
597
+
598
+ dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . top + 5 ) ;
599
+ fixture . detectChanges ( ) ;
600
+
601
+ expect ( fixture . componentInstance . sortedSpy . calls . mostRecent ( ) . args [ 0 ] ) . toEqual ( {
602
+ previousIndex : i - 1 ,
603
+ currentIndex : i ,
604
+ item : fixture . componentInstance . dragItems . first ,
605
+ container : fixture . componentInstance . dropInstance
606
+ } ) ;
607
+ }
608
+
609
+ dispatchMouseEvent ( document , 'mouseup' ) ;
610
+ fixture . detectChanges ( ) ;
611
+ flush ( ) ;
612
+ } ) ) ;
613
+
584
614
it ( 'should not move items in a vertical list if the pointer is too far away' , fakeAsync ( ( ) => {
585
615
const fixture = createComponent ( DraggableInDropZone ) ;
586
616
fixture . detectChanges ( ) ;
@@ -1814,6 +1844,7 @@ class StandaloneDraggableWithMultipleHandles {
1814
1844
style="width: 100px; background: pink;"
1815
1845
[id]="dropZoneId"
1816
1846
[cdkDropListData]="items"
1847
+ (cdkDropListSorted)="sortedSpy($event)"
1817
1848
(cdkDropListDropped)="droppedSpy($event)">
1818
1849
<div
1819
1850
*ngFor="let item of items"
@@ -1828,6 +1859,7 @@ class DraggableInDropZone {
1828
1859
@ViewChild ( CdkDropList ) dropInstance : CdkDropList ;
1829
1860
items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
1830
1861
dropZoneId = 'items' ;
1862
+ sortedSpy = jasmine . createSpy ( 'sorted spy' ) ;
1831
1863
droppedSpy = jasmine . createSpy ( 'dropped spy' ) . and . callFake ( ( event : CdkDragDrop < string [ ] > ) => {
1832
1864
moveItemInArray ( this . items , event . previousIndex , event . currentIndex ) ;
1833
1865
} ) ;
0 commit comments