@@ -8,12 +8,14 @@ import { omit, pick, forEach, copy } from "../../src/core";
88import Spy = jasmine . Spy ;
99import { services } from "../../src/common/coreservices" ;
1010import { resolvablesBuilder } from "../../src/state/stateBuilder" ;
11+ import { tree2Array } from "../testUtils.ts" ;
12+ import { UIRouter } from "../../src/router" ;
1113
1214///////////////////////////////////////////////
1315
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 ;
1719
1820function invokeLater ( fn : Function , ctx : ResolveContext ) {
1921 return new Resolvable ( "" , fn , services . $injector . annotate ( fn ) ) . get ( ctx )
@@ -35,7 +37,14 @@ function getStates() {
3537 } ,
3638 I : { resolve : { _I : function ( _I ) { return "I" ; } } }
3739 } ,
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+ } ,
3948 K : { resolve : { _K : function ( _J2 ) { counts [ '_K' ] ++ ; return _J2 + "K" ; } } ,
4049 L : { resolve : { _L : function ( _K ) { counts [ '_L' ] ++ ; return _K + "L" ; } } ,
4150 M : { resolve : { _M : function ( _L ) { counts [ '_M' ] ++ ; return _L + "M" ; } } }
@@ -57,35 +66,17 @@ function getStates() {
5766 } ;
5867}
5968
60-
6169beforeEach ( function ( ) {
70+ router = new UIRouter ( ) ;
71+ router . stateRegistry . stateQueue . autoFlush ( router . stateService ) ;
72+
6273 counts = { _J : 0 , _J2 : 0 , _K : 0 , _L : 0 , _M : 0 , _Q : 0 } ;
6374 vals = { _Q : null } ;
6475 expectCounts = copy ( counts ) ;
65- states = getStates ( ) ;
6676
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 ) , { } ) ;
8980} ) ;
9081
9182function makePath ( names : string [ ] ) : PathNode [ ] {
@@ -126,6 +117,14 @@ describe('Resolvables system:', function () {
126117 } ) . then ( done ) ;
127118 } ) ;
128119
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+
129128 it ( 'should resolve lazy and eager resolves when run with "lazy" policy' , done => {
130129 let path = makePath ( [ "J" , "N" ] ) ;
131130 let ctx = new ResolveContext ( path ) ;
0 commit comments