@@ -9,7 +9,7 @@ function animateFlush($animate) {
9
9
describe ( 'uiView' , function ( ) {
10
10
'use strict' ;
11
11
12
- var scope , $compile , elem , log ;
12
+ var $stateProvider , scope , $compile , elem , log ;
13
13
14
14
beforeEach ( function ( ) {
15
15
var depends = [ 'ui.router' ] ;
@@ -120,7 +120,8 @@ describe('uiView', function () {
120
120
}
121
121
} ;
122
122
123
- beforeEach ( module ( function ( $stateProvider ) {
123
+ beforeEach ( module ( function ( _$stateProvider_ ) {
124
+ $stateProvider = _$stateProvider_ ;
124
125
$stateProvider
125
126
. state ( 'a' , aState )
126
127
. state ( 'b' , bState )
@@ -338,6 +339,73 @@ describe('uiView', function () {
338
339
expect ( elem . text ( ) ) . toBe ( 'mState' ) ;
339
340
} ) ) ;
340
341
342
+ describe ( '(resolved data)' , function ( ) {
343
+ var _scope ;
344
+ function controller ( $scope ) { _scope = $scope ; }
345
+
346
+ var _state = {
347
+ name : 'resolve' ,
348
+ resolve : {
349
+ user : function ( $timeout ) {
350
+ return $timeout ( function ( ) { return "joeschmoe" ; } , 100 ) ;
351
+ }
352
+ }
353
+ } ;
354
+
355
+ it ( 'should provide the resolved data on the $scope' , inject ( function ( $state , $q , $timeout ) {
356
+ var state = angular . extend ( { } , _state , { template : '{{$resolve.user}}' , controller : controller } ) ;
357
+ $stateProvider . state ( state ) ;
358
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
359
+
360
+ $state . transitionTo ( 'resolve' ) ; $q . flush ( ) ; $timeout . flush ( ) ;
361
+ expect ( elem . text ( ) ) . toBe ( 'joeschmoe' ) ;
362
+ expect ( _scope . $resolve ) . toBeDefined ( ) ;
363
+ expect ( _scope . $resolve . user ) . toBe ( 'joeschmoe' )
364
+ } ) ) ;
365
+
366
+ it ( 'should put the resolved data on the resolveAs variable' , inject ( function ( $state , $q , $timeout ) {
367
+ var state = angular . extend ( { } , _state , { template : '{{$$$resolve.user}}' , resolveAs : '$$$resolve' , controller : controller } ) ;
368
+ $stateProvider . state ( state ) ;
369
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
370
+
371
+ $state . transitionTo ( 'resolve' ) ; $q . flush ( ) ; $timeout . flush ( ) ;
372
+ expect ( elem . text ( ) ) . toBe ( 'joeschmoe' ) ;
373
+ expect ( _scope . $$$resolve ) . toBeDefined ( ) ;
374
+ expect ( _scope . $$$resolve . user ) . toBe ( 'joeschmoe' )
375
+ } ) ) ;
376
+
377
+ it ( 'should put the resolved data on the controllerAs' , inject ( function ( $state , $q , $timeout ) {
378
+ var state = angular . extend ( { } , _state , { template : '{{$ctrl.$resolve.user}}' , controllerAs : '$ctrl' , controller : controller } ) ;
379
+ $stateProvider . state ( state ) ;
380
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
381
+
382
+ $state . transitionTo ( 'resolve' ) ; $q . flush ( ) ; $timeout . flush ( ) ;
383
+ expect ( elem . text ( ) ) . toBe ( 'joeschmoe' ) ;
384
+ expect ( _scope . $resolve ) . toBeDefined ( ) ;
385
+ expect ( _scope . $ctrl ) . toBeDefined ( ) ;
386
+ expect ( _scope . $ctrl . $resolve ) . toBeDefined ( ) ;
387
+ expect ( _scope . $ctrl . $resolve . user ) . toBe ( 'joeschmoe' ) ;
388
+ } ) ) ;
389
+
390
+ it ( 'should use the view-level resolveAs over the state-level resolveAs' , inject ( function ( $state , $q , $timeout ) {
391
+ var views = {
392
+ "$default" : {
393
+ controller : controller ,
394
+ template : '{{$$$resolve.user}}' ,
395
+ resolveAs : '$$$resolve'
396
+ }
397
+ } ;
398
+ var state = angular . extend ( { } , _state , { resolveAs : 'foo' , views : views } )
399
+ $stateProvider . state ( state ) ;
400
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
401
+
402
+ $state . transitionTo ( 'resolve' ) ; $q . flush ( ) ; $timeout . flush ( ) ;
403
+ expect ( elem . text ( ) ) . toBe ( 'joeschmoe' ) ;
404
+ expect ( _scope . $$$resolve ) . toBeDefined ( ) ;
405
+ expect ( _scope . $$$resolve . user ) . toBe ( 'joeschmoe' ) ;
406
+ } ) ) ;
407
+ } ) ;
408
+
341
409
describe ( 'play nicely with other directives' , function ( ) {
342
410
// related to issue #857
343
411
it ( 'should work with ngIf' , inject ( function ( $state , $q , $compile ) {
0 commit comments