@@ -8,12 +8,14 @@ import { omit, pick, forEach, copy } from "../../src/core";
8
8
import Spy = jasmine . Spy ;
9
9
import { services } from "../../src/common/coreservices" ;
10
10
import { resolvablesBuilder } from "../../src/state/stateBuilder" ;
11
+ import { tree2Array } from "../testUtils.ts" ;
12
+ import { UIRouter } from "../../src/router" ;
11
13
12
14
///////////////////////////////////////////////
13
15
14
- var states , statesTree , statesMap : { [ key :string ] : State } = { } ;
15
- var vals , counts , expectCounts ;
16
- var asyncCount ;
16
+ let router , states , statesMap : { [ key :string ] : State } = { } ;
17
+ let vals , counts , expectCounts ;
18
+ let asyncCount ;
17
19
18
20
function invokeLater ( fn : Function , ctx : ResolveContext ) {
19
21
return new Resolvable ( "" , fn , services . $injector . annotate ( fn ) ) . get ( ctx )
@@ -35,7 +37,14 @@ function getStates() {
35
37
} ,
36
38
I : { resolve : { _I : function ( _I ) { return "I" ; } } }
37
39
} ,
38
- J : { resolve : { _J : function ( ) { counts [ '_J' ] ++ ; return "J" ; } , _J2 : function ( _J ) { counts [ '_J2' ] ++ ; return _J + "J2" ; } } ,
40
+ J : {
41
+ resolve : {
42
+ _J : function ( ) { counts [ '_J' ] ++ ; return "J" ; } ,
43
+ _J2 : function ( _J ) { counts [ '_J2' ] ++ ; return _J + "J2" ; }
44
+ } ,
45
+ resolvePolicy : {
46
+ _J : { when : 'EAGER' }
47
+ } ,
39
48
K : { resolve : { _K : function ( _J2 ) { counts [ '_K' ] ++ ; return _J2 + "K" ; } } ,
40
49
L : { resolve : { _L : function ( _K ) { counts [ '_L' ] ++ ; return _K + "L" ; } } ,
41
50
M : { resolve : { _M : function ( _L ) { counts [ '_M' ] ++ ; return _L + "M" ; } } }
@@ -57,35 +66,17 @@ function getStates() {
57
66
} ;
58
67
}
59
68
60
-
61
69
beforeEach ( function ( ) {
70
+ router = new UIRouter ( ) ;
71
+ router . stateRegistry . stateQueue . autoFlush ( router . stateService ) ;
72
+
62
73
counts = { _J : 0 , _J2 : 0 , _K : 0 , _L : 0 , _M : 0 , _Q : 0 } ;
63
74
vals = { _Q : null } ;
64
75
expectCounts = copy ( counts ) ;
65
- states = getStates ( ) ;
66
76
67
- var stateProps = [ "resolve" , "resolvePolicy" ] ;
68
- statesTree = loadStates ( { } , states , '' ) ;
69
-
70
- function loadStates ( parent , state , name ) {
71
- var thisState = pick . apply ( null , [ state ] . concat ( stateProps ) ) ;
72
- var substates = omit . apply ( null , [ state ] . concat ( stateProps ) ) ;
73
- var resolve = thisState . resolve || { } ;
74
-
75
- thisState . resolvables = resolvablesBuilder ( < any > { resolve } ) ;
76
- thisState . template = thisState . template || "empty" ;
77
- thisState . name = name ;
78
- thisState . parent = parent . name ;
79
- thisState . params = { } ;
80
- thisState . data = { children : [ ] } ;
81
-
82
- forEach ( substates , function ( value , key ) {
83
- thisState . data . children . push ( loadStates ( thisState , value , key ) ) ;
84
- } ) ;
85
- thisState = new State ( thisState ) ;
86
- statesMap [ name ] = thisState ;
87
- return thisState ;
88
- }
77
+ tree2Array ( getStates ( ) , false ) . forEach ( state => router . stateRegistry . register ( state ) ) ;
78
+ statesMap = router . stateRegistry . get ( )
79
+ . reduce ( ( acc , state ) => ( ( acc [ state . name ] = state . $$state ( ) ) , acc ) , { } ) ;
89
80
} ) ;
90
81
91
82
function makePath ( names : string [ ] ) : PathNode [ ] {
@@ -126,6 +117,14 @@ describe('Resolvables system:', function () {
126
117
} ) . then ( done ) ;
127
118
} ) ;
128
119
120
+ it ( 'should resolve only eager resolves when run with "eager" policy' , done => {
121
+ let path = makePath ( [ "J" , "K" ] ) ;
122
+ let ctx = new ResolveContext ( path ) ;
123
+ ctx . resolvePath ( "EAGER" ) . then ( function ( ) {
124
+ expect ( getResolvedData ( ctx ) ) . toEqualData ( { _J : "J" } ) ;
125
+ } ) . then ( done ) ;
126
+ } ) ;
127
+
129
128
it ( 'should resolve lazy and eager resolves when run with "lazy" policy' , done => {
130
129
let path = makePath ( [ "J" , "N" ] ) ;
131
130
let ctx = new ResolveContext ( path ) ;
0 commit comments