@@ -298,26 +298,31 @@ describe('future state', function () {
298
298
} ) ;
299
299
300
300
describe ( 'that resolves to multiple states' , ( ) => {
301
- let lazyStateDefA = { name : 'A' , url : '/a/:id' , params : { id : "default" } } ;
302
- let lazyStateDefAB = { name : 'A.B' , url : '/b' } ;
303
- let futureStateDef ;
301
+ let futureA , futureB ;
302
+ let lazyA = { name : 'A' , url : '/a/:id' , params : { id : "default" } } ;
303
+ let lazyAB = { name : 'A.B' , url : '/b' } ;
304
+
305
+
306
+ let lazyB = { name : 'B' , url : '/b' } ;
307
+ let lazyBA = { name : 'B.A' , url : '/A' } ;
308
+ let lazyBB = { name : 'B.B' , url : '/B' } ;
304
309
305
310
beforeEach ( ( ) => {
306
- futureStateDef = {
307
- name : 'A.**' , url : '/a' ,
308
- lazyLoad : ( ) => new Promise ( resolve => { resolve ( { states : [ lazyStateDefA , lazyStateDefAB ] } ) ; } )
309
- } ;
310
- $registry . register ( futureStateDef )
311
+ // Re-create each time because the state is mutated: the lazyLoad function is removed after success
312
+ futureA = { name : 'A.**' , url : '/a' , lazyLoad : ( ) => new Promise ( resolve => { resolve ( { states : [ lazyA , lazyAB ] } ) ; } ) } ;
313
+ futureB = { name : 'B.**' , url : '/b' , lazyLoad : ( ) => null , } ;
314
+
315
+ $registry . register ( futureA )
311
316
} ) ;
312
317
313
318
it ( 'should register all returned states and remove the placeholder' , ( done ) => {
314
319
expect ( $state . get ( ) . map ( x => x . name ) ) . toEqual ( [ "" , "A.**" ] ) ;
315
- expect ( $state . get ( 'A' ) ) . toBe ( futureStateDef ) ;
320
+ expect ( $state . get ( 'A' ) ) . toBe ( futureA ) ;
316
321
expect ( $state . get ( 'A' ) . lazyLoad ) . toBeDefined ( ) ;
317
322
318
323
$state . go ( 'A' ) . then ( ( ) => {
319
324
expect ( $state . get ( ) . map ( x => x . name ) ) . toEqual ( [ "" , "A" , "A.B" ] ) ;
320
- expect ( $state . get ( 'A' ) ) . toBe ( lazyStateDefA ) ;
325
+ expect ( $state . get ( 'A' ) ) . toBe ( lazyA ) ;
321
326
expect ( $state . get ( 'A' ) . lazyLoad ) . toBeUndefined ( ) ;
322
327
expect ( $state . current . name ) . toBe ( 'A' ) ;
323
328
done ( ) ;
@@ -341,6 +346,36 @@ describe('future state', function () {
341
346
done ( ) ;
342
347
} ) ;
343
348
} ) ;
349
+
350
+ it ( 'should not care about the order of lazy loaded states (1)' , ( done ) => {
351
+ futureB . lazyLoad = ( ) => new Promise ( resolve => { resolve ( { states : [ lazyB , lazyBA , lazyBB ] } ) ; } ) ;
352
+ $registry . register ( futureB ) ;
353
+
354
+ $state . go ( 'B.A' ) . then ( ( ) => {
355
+ expect ( $state . current . name ) . toBe ( 'B.A' ) ;
356
+ done ( ) ;
357
+ } ) ;
358
+ } ) ;
359
+
360
+ it ( 'should not care about the order of lazy loaded states (2)' , ( done ) => {
361
+ futureB . lazyLoad = ( ) => new Promise ( resolve => { resolve ( { states : [ lazyBA , lazyB , lazyBB ] } ) ; } ) ;
362
+ $registry . register ( futureB ) ;
363
+
364
+ $state . go ( 'B.A' ) . then ( ( ) => {
365
+ expect ( $state . current . name ) . toBe ( 'B.A' ) ;
366
+ done ( ) ;
367
+ } ) ;
368
+ } ) ;
369
+
370
+ it ( 'should not care about the order of lazy loaded states (3)' , ( done ) => {
371
+ futureB . lazyLoad = ( ) => new Promise ( resolve => { resolve ( { states : [ lazyBB , lazyBA , lazyB ] } ) ; } ) ;
372
+ $registry . register ( futureB ) ;
373
+
374
+ $state . go ( 'B.A' ) . then ( ( ) => {
375
+ expect ( $state . current . name ) . toBe ( 'B.A' ) ;
376
+ done ( ) ;
377
+ } ) ;
378
+ } ) ;
344
379
} ) ;
345
380
346
381
it ( 'should not invoke lazyLoad twice' , ( done ) => {
0 commit comments