@@ -484,6 +484,30 @@ describe('treeControl', function() {
484484 expect ( element . find ( 'li:eq(2)' ) . text ( ) ) . toBe ( 'a' ) ;
485485 } ) ;
486486
487+ it ( 'should order sub-trees on different orders by expression' , function ( ) {
488+ $rootScope . treedata = [
489+ { subTreeSortOrder :"-label" , label : "a" , children : [ { label :"a2" , children :[ ] } , { label :"a3" , children :[ ] } , { label :"a1" , children :[ ] } ] } ,
490+ { subTreeSortOrder :"label" , label : "b" , children : [ { label :"b2" , children :[ ] } , { label :"b3" , children :[ ] } , { label :"b1" , children :[ ] } ] }
491+ ] ;
492+ element = $compile ( '<treecontrol tree-model="treedata" order-by-expression="node.subTreeSortOrder">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
493+ $rootScope . $digest ( ) ;
494+ element . find ( 'li:eq(1) .tree-branch-head' ) . click ( ) ; // expand 'b' sub-tree
495+ element . find ( 'li:eq(0) .tree-branch-head' ) . click ( ) ; // expand 'a' sub-tree
496+ expect ( element . find ( 'li' ) . length ) . toBe ( 8 ) ;
497+
498+ // 'A' sub-tree is ordered by descending label
499+ expect ( element . find ( 'li:eq(0) div.tree-label:eq(0)' ) . text ( ) ) . toBe ( 'a' ) ;
500+ expect ( element . find ( 'li:eq(1)' ) . text ( ) ) . toBe ( 'a3' ) ;
501+ expect ( element . find ( 'li:eq(2)' ) . text ( ) ) . toBe ( 'a2' ) ;
502+ expect ( element . find ( 'li:eq(3)' ) . text ( ) ) . toBe ( 'a1' ) ;
503+
504+ // 'B' sub-tree is ordered by ascending label
505+ expect ( element . find ( 'li:eq(4) div.tree-label:eq(0)' ) . text ( ) ) . toBe ( 'b' ) ;
506+ expect ( element . find ( 'li:eq(5)' ) . text ( ) ) . toBe ( 'b1' ) ;
507+ expect ( element . find ( 'li:eq(6)' ) . text ( ) ) . toBe ( 'b2' ) ;
508+ expect ( element . find ( 'li:eq(7)' ) . text ( ) ) . toBe ( 'b3' ) ;
509+ } ) ;
510+
487511 it ( 'should be able to accept alternative children variable name' , function ( ) {
488512 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
489513 $rootScope . treedata . push ( { kinder : [ { } ] } ) ;
0 commit comments