1- import { Component , DebugElement , Input , NgModuleFactoryLoader , SystemJsNgModuleLoader } from '@angular/core' ;
1+ import { Component , Inject , Input } from '@angular/core' ;
22import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3- import { UIRouterModule } from '../../src/uiRouterNgModule' ;
4- import { Ng2StateDeclaration } from '../../src/interface' ;
5- import { UIView } from '../../src/directives/uiView' ;
3+ import { Ng2StateDeclaration , UIRouterModule , UIView } from '../../src' ;
64import { By } from '@angular/platform-browser' ;
7- import { UIRouter } from '@uirouter/core' ;
5+ import { Resolvable , UIRouter } from '@uirouter/core' ;
86
97describe ( 'uiView' , ( ) => {
108 describe ( 'should map resolve data to inputs' , ( ) => {
119 @Component ( { template : `<h3>hey</h3> ` } )
1210 class ManyResolvesComponent {
11+ constructor ( @Inject ( 'resolve1' ) foo , @Inject ( 'Resolve2' ) bar , @Inject ( 'resolve5' ) baz ) {
12+ this . injectedValues = Array . from ( arguments ) ;
13+ }
14+
15+ injectedValues : any [ ] ;
1316 @Input ( ) resolve1 ;
1417 @Input ( ) resolve2 ;
1518 @Input ( 'resolve3' ) _resolve3 ;
1619 @Input ( 'resolve4' ) _resolve4 ;
20+ @Input ( ) resolve5 ;
1721 }
1822
1923 let comp : ManyResolvesComponent ;
@@ -34,6 +38,7 @@ describe('uiView', () => {
3438 { token : 'Resolve2' , resolveFn : ( ) => 'resolve2' } ,
3539 { token : 'resolve3' , resolveFn : ( ) => 'resolve3' } ,
3640 { token : 'Resolve4' , resolveFn : ( ) => 'resolve4' } ,
41+ new Resolvable ( 'resolve5' , ( ) => 'resolve5' , [ ] , { async : 'NOWAIT' } ) ,
3742 ] ,
3843 } ;
3944
@@ -52,6 +57,8 @@ describe('uiView', () => {
5257 } ) ;
5358 } ) ;
5459
60+ /////////////////////////////////////////
61+
5562 it ( 'should bind resolve by name to component input name' , ( ) => {
5663 expect ( comp . resolve1 ) . toBe ( 'resolve1' ) ;
5764 } ) ;
@@ -67,5 +74,26 @@ describe('uiView', () => {
6774 it ( 'should bind resolve by name to the component input templateName specified in state `bindings`' , ( ) => {
6875 expect ( comp . _resolve4 ) . toBe ( 'resolve4' ) ;
6976 } ) ;
77+
78+ it ( 'should bind NOWAIT resolve as a promise object' , ( ) => {
79+ expect ( comp . resolve5 ) . toBeDefined ( ) ;
80+ expect ( typeof comp . resolve5 . then ) . toBe ( 'function' ) ;
81+ } ) ;
82+
83+ /////////////////////////////////////////
84+
85+ it ( 'should inject resolve by name to constructor' , ( ) => {
86+ expect ( comp . injectedValues [ 0 ] ) . toBe ( 'resolve1' ) ;
87+ } ) ;
88+
89+ it ( 'should inject resolve by resolve name (not binding name) to the constructor' , ( ) => {
90+ expect ( comp . injectedValues [ 1 ] ) . toBe ( 'resolve2' ) ;
91+ } ) ;
92+
93+ it ( 'should inject NOWAIT resolve as a promise object' , ( ) => {
94+ expect ( comp . injectedValues [ 2 ] ) . toBeDefined ( ) ;
95+ expect ( typeof comp . injectedValues [ 2 ] ) . toBe ( 'object' ) ;
96+ expect ( typeof comp . injectedValues [ 2 ] . then ) . toBe ( 'function' ) ;
97+ } ) ;
7098 } ) ;
7199} ) ;
0 commit comments