@@ -9,7 +9,7 @@ function animateFlush($animate) {
99describe ( 'uiView' , function ( ) {
1010 'use strict' ;
1111
12- var scope , $compile , elem , log ;
12+ var $stateProvider , scope , $compile , elem , log ;
1313
1414 beforeEach ( function ( ) {
1515 var depends = [ 'ui.router' ] ;
@@ -120,7 +120,8 @@ describe('uiView', function () {
120120 }
121121 } ;
122122
123- beforeEach ( module ( function ( $stateProvider ) {
123+ beforeEach ( module ( function ( _$stateProvider_ ) {
124+ $stateProvider = _$stateProvider_ ;
124125 $stateProvider
125126 . state ( 'a' , aState )
126127 . state ( 'b' , bState )
@@ -338,6 +339,87 @@ describe('uiView', function () {
338339 expect ( elem . text ( ) ) . toBe ( 'mState' ) ;
339340 } ) ) ;
340341
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+ "" : {
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+ it ( 'should put resolve data on scope even if there is no controller' , inject ( function ( $state , $q , $timeout ) {
409+ var views = {
410+ "" : {
411+ template : '{{$resolve.user}}'
412+ }
413+ } ;
414+ var state = angular . extend ( { } , _state , { views : views } ) ;
415+ $stateProvider . state ( state ) ;
416+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
417+
418+ $state . transitionTo ( 'resolve' ) ; $q . flush ( ) ; $timeout . flush ( ) ;
419+ expect ( elem . text ( ) ) . toBe ( 'joeschmoe' ) ;
420+ } ) ) ;
421+ } ) ;
422+
341423 describe ( 'play nicely with other directives' , function ( ) {
342424 // related to issue #857
343425 it ( 'should work with ngIf' , inject ( function ( $state , $q , $compile ) {
0 commit comments