@@ -222,7 +222,7 @@ describe('state helpers', function() {
222
222
223
223
describe ( 'state' , function ( ) {
224
224
225
- var $injector , stateProvider , locationProvider , templateParams , template , ctrlName ;
225
+ var $injector , $ stateProvider, locationProvider , templateParams , template , ctrlName ;
226
226
227
227
beforeEach ( module ( 'ui.router' , function ( $locationProvider ) {
228
228
locationProvider = $locationProvider ;
@@ -248,24 +248,18 @@ describe('state', function () {
248
248
HH = { parent : H , template : "hh" } ,
249
249
HHH = { parent : HH , data : { propA : 'overriddenA' , propC : 'propC' } , template : "hhh" } ,
250
250
RS = { url : '^/search?term' , reloadOnSearch : false , template : "rs" } ,
251
- dynamicstate = {
252
- url : '^/dynstate/:path/:pathDyn?search&searchDyn' , params : {
253
- pathDyn : { dynamic : true } ,
254
- searchDyn : { dynamic : true }
255
- } , template : "dynamicstate"
256
- } ,
257
251
OPT = { url : '/opt/:param' , params : { param : "100" } , template : "opt" } ,
258
252
OPT2 = { url : '/opt2/:param2/:param3' , params : { param3 : "300" , param4 : "400" } , template : "opt2" } ,
259
253
ISS2101 = { params : { bar : { squash : false , value : 'qux' } } , url : '/2101/{bar:string}' } ,
260
254
URLLESS = { url : '/urllessparams' , params : { myparam : { type : 'int' } } } ,
261
255
AppInjectable = { } ;
262
256
263
- beforeEach ( module ( function ( $stateProvider , $provide ) {
257
+ beforeEach ( module ( function ( _$stateProvider_ , $provide ) {
264
258
angular . forEach ( [ A , B , C , D , DD , E , H , HH , HHH ] , function ( state ) {
265
259
state . onEnter = callbackLogger ( state , 'onEnter' ) ;
266
260
state . onExit = callbackLogger ( state , 'onExit' ) ;
267
261
} ) ;
268
- stateProvider = $stateProvider ;
262
+ $ stateProvider = _$stateProvider_ ;
269
263
270
264
$stateProvider
271
265
. state ( 'A' , A )
@@ -280,7 +274,6 @@ describe('state', function () {
280
274
. state ( 'HH' , HH )
281
275
. state ( 'HHH' , HHH )
282
276
. state ( 'RS' , RS )
283
- . state ( 'dynamicstate' , dynamicstate )
284
277
. state ( 'OPT' , OPT )
285
278
. state ( 'OPT.OPT2' , OPT2 )
286
279
. state ( 'ISS2101' , ISS2101 )
@@ -409,10 +402,10 @@ describe('state', function () {
409
402
describe ( 'provider' , function ( ) {
410
403
it ( 'should ignore Object properties when registering states' , function ( ) {
411
404
expect ( function ( ) {
412
- stateProvider . state ( 'toString' , { url : "/to-string" } ) ;
405
+ $ stateProvider. state ( 'toString' , { url : "/to-string" } ) ;
413
406
} ) . not . toThrow ( ) ;
414
407
expect ( function ( ) {
415
- stateProvider . state ( 'watch' , { url : "/watch" } ) ;
408
+ $ stateProvider. state ( 'watch' , { url : "/watch" } ) ;
416
409
} ) . not . toThrow ( ) ;
417
410
} ) ;
418
411
} ) ;
@@ -446,17 +439,6 @@ describe('state', function () {
446
439
} ) ) ;
447
440
448
441
describe ( "(dynamic params)" , function ( ) {
449
- var stateChanged ;
450
-
451
- beforeEach ( inject ( function ( _$rootScope_ , _$state_ , _$stateParams_ , _$transitions_ , _$q_ , _$location_ ) {
452
- $transitions . onStart ( { } , function ( ) {
453
- stateChanged = true ;
454
- } ) ;
455
-
456
- $q . flush ( ) ;
457
- } ) ) ;
458
-
459
-
460
442
it ( 'resolves a fully dynamic $state.go() with the current state' , function ( ) {
461
443
initStateTo ( RS ) ;
462
444
var destState , promise = $state . go ( "." , { term : "hello" } ) ;
@@ -480,7 +462,27 @@ describe('state', function () {
480
462
} ) ;
481
463
482
464
describe ( "" , function ( ) {
465
+ var stateChanged , dynamicstate ;
466
+
483
467
beforeEach ( function ( ) {
468
+ dynamicstate = {
469
+ name : 'dynamicstate' ,
470
+ url : '^/dynstate/:path/:pathDyn?search&searchDyn' ,
471
+ params : {
472
+ pathDyn : { dynamic : true } ,
473
+ searchDyn : { dynamic : true }
474
+ } ,
475
+ template : "dynamicstate" ,
476
+ controller : function ( $stateParams ) {
477
+ $scope . $watch ( $stateParams . searchDyn ) ;
478
+ }
479
+ }
480
+ $stateProvider . state ( dynamicstate ) ;
481
+
482
+ $transitions . onSuccess ( { } , function ( ) {
483
+ stateChanged = true ;
484
+ } ) ;
485
+
484
486
initStateTo ( dynamicstate , { path : 'pathfoo' , pathDyn : 'pathbar' , search : 'searchfoo' , searchDyn : 'searchbar' } ) ;
485
487
expect ( stateChanged ) . toBeTruthy ( ) ;
486
488
expect ( obj ( $stateParams ) ) . toEqual ( { path : 'pathfoo' , pathDyn : 'pathbar' , search : 'searchfoo' , searchDyn : 'searchbar' } ) ;
@@ -489,28 +491,28 @@ describe('state', function () {
489
491
} ) ;
490
492
491
493
it ( 'triggers state change for non-dynamic search params' , function ( ) {
492
- $state . go ( dynamicstate , { search : 'somethingelse' } ) ;
494
+ $state . go ( ' dynamicstate' , { search : 'somethingelse' } ) ;
493
495
$q . flush ( ) ;
494
496
expect ( stateChanged ) . toBeTruthy ( ) ;
495
497
expect ( obj ( $stateParams ) ) . toEqual ( { path : 'pathfoo' , pathDyn : 'pathbar' , search : 'somethingelse' , searchDyn : 'searchbar' } ) ;
496
498
} ) ;
497
499
498
500
it ( 'does not trigger state change for dynamic search params' , function ( ) {
499
- $state . go ( dynamicstate , { searchDyn : 'somethingelse' } ) ;
501
+ $state . go ( ' dynamicstate' , { searchDyn : 'somethingelse' } ) ;
500
502
$q . flush ( ) ;
501
503
expect ( stateChanged ) . toBeFalsy ( ) ;
502
504
expect ( obj ( $stateParams ) ) . toEqual ( { path : 'pathfoo' , pathDyn : 'pathbar' , search : 'searchfoo' , searchDyn : 'somethingelse' } ) ;
503
505
} ) ;
504
506
505
507
it ( 'triggers state change for non-dynamic path params' , function ( ) {
506
- $state . go ( dynamicstate , { path : 'somethingelse' } ) ;
508
+ $state . go ( ' dynamicstate' , { path : 'somethingelse' } ) ;
507
509
$q . flush ( ) ;
508
510
expect ( stateChanged ) . toBeTruthy ( ) ;
509
511
expect ( obj ( $stateParams ) ) . toEqual ( { path : 'somethingelse' , pathDyn : 'pathbar' , search : 'searchfoo' , searchDyn : 'searchbar' } ) ;
510
512
} ) ;
511
513
512
514
it ( 'does not trigger state change for dynamic path params' , function ( ) {
513
- $state . go ( dynamicstate , { pathDyn : 'somethingelse' } ) ;
515
+ $state . go ( ' dynamicstate' , { pathDyn : 'somethingelse' } ) ;
514
516
$q . flush ( ) ;
515
517
expect ( stateChanged ) . toBeFalsy ( ) ;
516
518
expect ( obj ( $stateParams ) ) . toEqual ( { path : 'pathfoo' , pathDyn : 'somethingelse' , search : 'searchfoo' , searchDyn : 'searchbar' } ) ;
@@ -1127,7 +1129,7 @@ describe('state', function () {
1127
1129
var list = $state . get ( ) . sort ( function ( a , b ) { return ( a . name > b . name ) - ( b . name > a . name ) ; } ) ;
1128
1130
var names = [ '' , 'A' , 'B' , 'C' , 'D' , 'DD' , 'DDDD' , 'E' , 'F' , 'H' , 'HH' , 'HHH' , 'ISS2101' , 'OPT' , 'OPT.OPT2' , 'RS' , 'URLLESS' ,
1129
1131
'about' , 'about.person' , 'about.person.item' , 'about.sidebar' , 'about.sidebar.item' ,
1130
- 'badParam' , 'badParam2' , 'dynamicTemplate' , 'dynamicstate' , ' first', 'home' , 'home.item' , 'home.redirect' ,
1132
+ 'badParam' , 'badParam2' , 'dynamicTemplate' , 'first' , 'home' , 'home.item' , 'home.redirect' ,
1131
1133
'json' , 'logA' , 'logA.logB' , 'logA.logB.logC' , 'resolveFail' , 'resolveTimeout' ,
1132
1134
'root' , 'root.sub1' , 'root.sub2' , 'second' ] ;
1133
1135
@@ -1278,7 +1280,7 @@ describe('state', function () {
1278
1280
var $rootScope , $state , $compile ;
1279
1281
beforeEach ( function ( ) {
1280
1282
1281
- stateProvider . state ( 'myState' , {
1283
+ $ stateProvider. state ( 'myState' , {
1282
1284
template : 'myState' ,
1283
1285
url : '/my-state?:previous' ,
1284
1286
controller : function ( ) {
@@ -1350,7 +1352,7 @@ describe('state', function () {
1350
1352
1351
1353
describe ( "typed parameter handling" , function ( ) {
1352
1354
beforeEach ( function ( ) {
1353
- stateProvider . state ( {
1355
+ $ stateProvider. state ( {
1354
1356
name : "types" ,
1355
1357
url : "/types/{p1:string}/{p2:date}" ,
1356
1358
params : {
@@ -1359,7 +1361,7 @@ describe('state', function () {
1359
1361
nonurl : null
1360
1362
}
1361
1363
} ) ;
1362
- stateProvider . state ( {
1364
+ $ stateProvider. state ( {
1363
1365
name : "types.substate" ,
1364
1366
url : "/sub/{p3[]:int}/{p4:json}?{p5:bool}" ,
1365
1367
params : {
@@ -1627,33 +1629,33 @@ describe('state', function () {
1627
1629
describe ( 'provider decorators' , function ( ) {
1628
1630
1629
1631
it ( 'should return built-in decorators' , inject ( function ( $state ) {
1630
- expect ( stateProvider . decorator ( 'parent' ) ( { parent : A } ) . self . name ) . toBe ( "A" ) ;
1632
+ expect ( $ stateProvider. decorator ( 'parent' ) ( { parent : A } ) . self . name ) . toBe ( "A" ) ;
1631
1633
} ) ) ;
1632
1634
1633
1635
it ( 'should allow built-in decorators to be overridden' , inject ( function ( $state , $q ) {
1634
- stateProvider . decorator ( 'data' , function ( state ) {
1636
+ $ stateProvider. decorator ( 'data' , function ( state ) {
1635
1637
return angular . extend ( state . data || { } , { foo : "bar" } ) ;
1636
1638
} ) ;
1637
- stateProvider . state ( 'AA' , { parent : A , data : { baz : "true" } } ) ;
1639
+ $ stateProvider. state ( 'AA' , { parent : A , data : { baz : "true" } } ) ;
1638
1640
1639
1641
$state . transitionTo ( 'AA' ) ;
1640
1642
$q . flush ( ) ;
1641
1643
expect ( $state . current . data ) . toEqual ( { baz : 'true' , foo : 'bar' } ) ;
1642
1644
} ) ) ;
1643
1645
1644
1646
it ( 'should allow new decorators to be added' , inject ( function ( $state , $q ) {
1645
- stateProvider . decorator ( 'custom' , function ( state ) {
1647
+ $ stateProvider. decorator ( 'custom' , function ( state ) {
1646
1648
return function ( ) { return "Custom functionality for state '" + state + "'" } ;
1647
1649
} ) ;
1648
- stateProvider . state ( 'decoratorTest' , { } ) ;
1650
+ $ stateProvider. state ( 'decoratorTest' , { } ) ;
1649
1651
1650
1652
$state . transitionTo ( 'decoratorTest' ) ;
1651
1653
$q . flush ( ) ;
1652
1654
expect ( $state . $current . custom ( ) ) . toBe ( "Custom functionality for state 'decoratorTest'" ) ;
1653
1655
} ) ) ;
1654
1656
1655
1657
it ( 'should allow built-in decorators to be extended' , inject ( function ( $state , $q , $httpBackend ) {
1656
- stateProvider . decorator ( 'views' , function ( state , parent ) {
1658
+ $ stateProvider. decorator ( 'views' , function ( state , parent ) {
1657
1659
var result = { } ;
1658
1660
1659
1661
var views = parent ( state ) ;
@@ -1666,7 +1668,7 @@ describe('state', function () {
1666
1668
return result ;
1667
1669
} ) ;
1668
1670
1669
- stateProvider . state ( 'viewTest' , {
1671
+ $ stateProvider. state ( 'viewTest' , {
1670
1672
views : {
1671
1673
"viewA@" : { template : '<div/>' } ,
1672
1674
"viewB@" : { template : '<div/>' }
@@ -1685,10 +1687,10 @@ describe('state', function () {
1685
1687
function decorator1 ( state , parent ) { d . d1 = true ; return parent ( state ) ; }
1686
1688
function decorator2 ( state , parent ) { d . d2 = true ; return parent ( state ) ; }
1687
1689
1688
- stateProvider . decorator ( 'parent' , decorator1 ) ;
1689
- stateProvider . decorator ( 'parent' , decorator2 ) ;
1690
+ $ stateProvider. decorator ( 'parent' , decorator1 ) ;
1691
+ $ stateProvider. decorator ( 'parent' , decorator2 ) ;
1690
1692
1691
- stateProvider . state ( { name : "test" , parent : A } ) ;
1693
+ $ stateProvider. state ( { name : "test" , parent : A } ) ;
1692
1694
$state . go ( "test" ) ; $q . flush ( ) ;
1693
1695
1694
1696
expect ( $state . $current . name ) . toBe ( "test" ) ;
@@ -1702,10 +1704,10 @@ describe('state', function () {
1702
1704
function decorator1 ( state , parent ) { d . d1 = true ; return parent ( state ) ; }
1703
1705
function decorator2 ( state , parent ) { d . d2 = true ; return { } ; }
1704
1706
1705
- stateProvider . decorator ( 'data' , decorator1 ) ;
1706
- stateProvider . decorator ( 'data' , decorator2 ) ;
1707
+ $ stateProvider. decorator ( 'data' , decorator1 ) ;
1708
+ $ stateProvider. decorator ( 'data' , decorator2 ) ;
1707
1709
1708
- stateProvider . state ( { name : "test" , data : { x : 1 } } ) ;
1710
+ $ stateProvider. state ( { name : "test" , data : { x : 1 } } ) ;
1709
1711
$state . go ( "test" ) ; $q . flush ( ) ;
1710
1712
1711
1713
expect ( $state . $current . name ) . toBe ( "test" ) ;
@@ -1719,10 +1721,10 @@ describe('state', function () {
1719
1721
function decorator1 ( state , parent ) { d . d1 = true ; return angular . extend ( parent ( state ) , { y : 2 } ) ; }
1720
1722
function decorator2 ( state , parent ) { d . d2 = true ; return angular . extend ( parent ( state ) , { z : 3 } ) ; }
1721
1723
1722
- stateProvider . decorator ( 'data' , decorator1 ) ;
1723
- stateProvider . decorator ( 'data' , decorator2 ) ;
1724
+ $ stateProvider. decorator ( 'data' , decorator1 ) ;
1725
+ $ stateProvider. decorator ( 'data' , decorator2 ) ;
1724
1726
1725
- stateProvider . state ( { name : "test" , data : { x : 1 } } ) ;
1727
+ $ stateProvider. state ( { name : "test" , data : { x : 1 } } ) ;
1726
1728
$state . go ( "test" ) ; $q . flush ( ) ;
1727
1729
1728
1730
expect ( $state . $current . name ) . toBe ( "test" ) ;
0 commit comments