@@ -1624,4 +1624,56 @@ describe('ngRepeat animations', function() {
1624
1624
expect ( item . element . text ( ) ) . toBe ( '2' ) ;
1625
1625
} )
1626
1626
) ;
1627
+
1628
+ it ( 'should maintain the order when the track by expression evaluates to an integer' ,
1629
+ inject ( function ( $compile , $rootScope , $animate , $document , $sniffer , $timeout ) {
1630
+ if ( ! $sniffer . transitions ) return ;
1631
+
1632
+ var item ;
1633
+ var ss = createMockStyleSheet ( $document ) ;
1634
+
1635
+ var items = [
1636
+ { id : 1 , name : 'A' } ,
1637
+ { id : 2 , name : 'B' } ,
1638
+ { id : 4 , name : 'C' } ,
1639
+ { id : 3 , name : 'D' }
1640
+ ]
1641
+
1642
+ try {
1643
+
1644
+ $animate . enabled ( true ) ;
1645
+
1646
+ ss . addRule ( '.animate-me div' ,
1647
+ 'transition:1s linear all;' ) ;
1648
+
1649
+ element = $compile ( html ( '<div class="animate-me">' +
1650
+ '<div ng-repeat="item in items track by item.id">{{ item.name }}</div>' +
1651
+ '</div>' ) ) ( $rootScope ) ;
1652
+
1653
+ $rootScope . items = [ items [ 0 ] , items [ 1 ] , items [ 2 ] ] ;
1654
+ $rootScope . $digest ( ) ;
1655
+ expect ( element . text ( ) ) . toBe ( 'ABC' ) ;
1656
+
1657
+ $rootScope . items . push ( items [ 3 ] ) ;
1658
+ $rootScope . $digest ( ) ;
1659
+
1660
+ expect ( element . text ( ) ) . toBe ( 'ABCD' ) ; // the original order should be preserved
1661
+ $animate . flush ( ) ;
1662
+ $timeout . flush ( 1500 ) ; // 1s * 1.5 closing buffer
1663
+ expect ( element . text ( ) ) . toBe ( 'ABCD' ) ;
1664
+
1665
+ $rootScope . items = [ items [ 0 ] , items [ 1 ] , items [ 3 ] ] ;
1666
+ $rootScope . $digest ( ) ;
1667
+
1668
+ // The leaving item should maintain it's position until it is removed
1669
+ expect ( element . text ( ) ) . toBe ( 'ABCD' ) ;
1670
+ $animate . flush ( ) ;
1671
+ $timeout . flush ( 1500 ) ; // 1s * 1.5 closing buffer
1672
+ expect ( element . text ( ) ) . toBe ( 'ABD' ) ;
1673
+
1674
+ } finally {
1675
+ ss . destroy ( ) ;
1676
+ }
1677
+ } )
1678
+ ) ;
1627
1679
} ) ;
0 commit comments