@@ -2095,14 +2095,21 @@ describe('otherwise and state redirects', function() {
2095
2095
} ) ;
2096
2096
2097
2097
2098
- describe ( 'hook redirects from .otherwise() ' , function ( ) {
2099
- var log ;
2098
+ describe ( 'hook redirects' , function ( ) {
2099
+ var log , resolvelog ;
2100
2100
beforeEach ( module ( function ( $stateProvider , $urlRouterProvider ) {
2101
- log = "" ;
2101
+ log = resolvelog = "" ;
2102
2102
$urlRouterProvider . otherwise ( '/home' ) ;
2103
- $stateProvider
2104
- . state ( 'home' , { url : '/home' , template : 'home' , controller : function ( ) { log += "homeCtrl;" ; } } )
2105
- . state ( 'loginPage' , { url : '/login' , template : 'login' } ) ;
2103
+ $stateProvider . state ( 'home' , {
2104
+ url : '/home' ,
2105
+ template : 'home <ui-view></ui-view>' ,
2106
+ controller : function ( ) { log += "homeCtrl;" ; } ,
2107
+ resolve : {
2108
+ foo : function ( ) { resolvelog += "fooResolve;" ; return "foo" ; }
2109
+ }
2110
+ } )
2111
+ . state ( 'home.foo' , { url : '/foo' , template : 'foo' } )
2112
+ . state ( 'loginPage' , { url : '/login' , template : 'login' } ) ;
2106
2113
} ) ) ;
2107
2114
2108
2115
beforeEach ( inject ( function ( $compile , $rootScope ) {
@@ -2111,7 +2118,7 @@ describe('hook redirects from .otherwise()', function() {
2111
2118
} ) ) ;
2112
2119
2113
2120
// Test for #2455
2114
- it ( "should go to the redirect-to target state and url" , inject ( function ( $transitions , $q , $state , $location ) {
2121
+ it ( "from .otherwise() should go to the redirect-to target state and url" , inject ( function ( $transitions , $q , $state , $location ) {
2115
2122
$transitions . onBefore ( { to : 'home' } , function ( ) {
2116
2123
return $state . target ( 'loginPage' , { } , { location : true } ) ;
2117
2124
} ) ;
@@ -2132,7 +2139,7 @@ describe('hook redirects from .otherwise()', function() {
2132
2139
2133
2140
$transitions . onBefore ( { to : 'home' } , function ( $state , $transition$ ) {
2134
2141
var options = $transition$ . options ( ) ;
2135
- if ( ! options . reload && count ++ < 2 ) {
2142
+ if ( ! options . reload && count ++ < 5 ) {
2136
2143
return $state . target ( $transition$ . to ( ) , $transition$ . params ( "to" ) , extend ( { } , options , { reload : true } ) ) ;
2137
2144
}
2138
2145
} ) ;
@@ -2142,4 +2149,28 @@ describe('hook redirects from .otherwise()', function() {
2142
2149
expect ( $state . current . name ) . toBe ( "home" ) ;
2143
2150
expect ( log ) . toBe ( "homeCtrl;homeCtrl;" ) ;
2144
2151
} ) ) ;
2152
+
2153
+ // Test for #2539
2154
+ it ( "should re-resolve when reloading during a redirect" , inject ( function ( $transitions , $q , $state , $trace ) {
2155
+ var count = 0 ;
2156
+ $q . flush ( ) ;
2157
+
2158
+ expect ( $state . current . name ) . toBe ( "home" ) ;
2159
+ expect ( resolvelog ) . toBe ( "fooResolve;" ) ;
2160
+
2161
+ $state . go ( 'home.foo' ) ; $q . flush ( ) ;
2162
+ expect ( resolvelog ) . toBe ( "fooResolve;" ) ;
2163
+
2164
+ $transitions . onStart ( { to : 'home' } , function ( $transition$ , $state ) {
2165
+ if ( ! $transition$ . options ( ) . reload && count ++ < 5 ) {
2166
+ console . log ( "forcing re-enter (reload) of home state " ) ;
2167
+ var options = $transition$ . options ( ) ;
2168
+ return $state . target ( $transition$ . to ( ) , $transition$ . params ( "to" ) , extend ( { } , options , { reload : true } ) ) ;
2169
+ }
2170
+ } ) ;
2171
+
2172
+ $state . go ( 'home' ) ; $q . flush ( ) ;
2173
+ expect ( $state . current . name ) . toBe ( "home" ) ;
2174
+ expect ( resolvelog ) . toBe ( "fooResolve;fooResolve;" ) ;
2175
+ } ) ) ;
2145
2176
} ) ;
0 commit comments