@@ -1541,6 +1541,57 @@ describe('state', function () {
15411541 expect ( $state . $current . views [ 'viewB@' ] . templateProvider ( ) ) . toBe ( 'Template for viewB@' ) ;
15421542 } ) ) ;
15431543
1544+ it ( 'should invoke multiple decorators, if exist' , inject ( function ( $state , $q , $httpBackend ) {
1545+ var d = { d1 : false , d2 : false } ;
1546+ function decorator1 ( state , parent ) { d . d1 = true ; return parent ( state ) ; }
1547+ function decorator2 ( state , parent ) { d . d2 = true ; return parent ( state ) ; }
1548+
1549+ stateProvider . decorator ( 'parent' , decorator1 ) ;
1550+ stateProvider . decorator ( 'parent' , decorator2 ) ;
1551+
1552+ stateProvider . state ( { name : "test" , parent : A } ) ;
1553+ $state . go ( "test" ) ; $q . flush ( ) ;
1554+
1555+ expect ( $state . $current . name ) . toBe ( "test" ) ;
1556+ expect ( $state . $current . parent . name ) . toBe ( "A" ) ;
1557+ expect ( d . d1 ) . toBe ( true ) ;
1558+ expect ( d . d2 ) . toBe ( true ) ;
1559+ } ) ) ;
1560+
1561+ it ( 'should allow any decorator to short circuit the chain' , inject ( function ( $state , $q , $httpBackend ) {
1562+ var d = { d1 : false , d2 : false } ;
1563+ function decorator1 ( state , parent ) { d . d1 = true ; return parent ( state ) ; }
1564+ function decorator2 ( state , parent ) { d . d2 = true ; return { } ; }
1565+
1566+ stateProvider . decorator ( 'data' , decorator1 ) ;
1567+ stateProvider . decorator ( 'data' , decorator2 ) ;
1568+
1569+ stateProvider . state ( { name : "test" , data : { x : 1 } } ) ;
1570+ $state . go ( "test" ) ; $q . flush ( ) ;
1571+
1572+ expect ( $state . $current . name ) . toBe ( "test" ) ;
1573+ expect ( $state . $current . data . x ) . toBeUndefined ( ) ;
1574+ expect ( d . d1 ) . toBe ( false ) ;
1575+ expect ( d . d2 ) . toBe ( true ) ;
1576+ } ) ) ;
1577+
1578+ it ( 'should allow any decorator to modify the return value of the parent' , inject ( function ( $state , $q , $httpBackend ) {
1579+ var d = { d1 : false , d2 : false } ;
1580+ function decorator1 ( state , parent ) { d . d1 = true ; return angular . extend ( parent ( state ) , { y : 2 } ) ; }
1581+ function decorator2 ( state , parent ) { d . d2 = true ; return angular . extend ( parent ( state ) , { z : 3 } ) ; }
1582+
1583+ stateProvider . decorator ( 'data' , decorator1 ) ;
1584+ stateProvider . decorator ( 'data' , decorator2 ) ;
1585+
1586+ stateProvider . state ( { name : "test" , data : { x : 1 } } ) ;
1587+ $state . go ( "test" ) ; $q . flush ( ) ;
1588+
1589+ expect ( $state . $current . name ) . toBe ( "test" ) ;
1590+ expect ( $state . $current . data ) . toEqualData ( { x : 1 , y : 2 , z : 3 } ) ;
1591+ expect ( d . d1 ) . toBe ( true ) ;
1592+ expect ( d . d2 ) . toBe ( true ) ;
1593+ } ) ) ;
1594+
15441595 } ) ;
15451596} ) ;
15461597
0 commit comments