1
- import { Component , DebugElement , Input , NgModuleFactoryLoader , SystemJsNgModuleLoader } from '@angular/core' ;
1
+ import { Component , Inject , Input } from '@angular/core' ;
2
2
import { 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' ;
6
4
import { By } from '@angular/platform-browser' ;
7
- import { UIRouter } from '@uirouter/core' ;
5
+ import { Resolvable , UIRouter } from '@uirouter/core' ;
8
6
9
7
describe ( 'uiView' , ( ) => {
10
8
describe ( 'should map resolve data to inputs' , ( ) => {
11
9
@Component ( { template : `<h3>hey</h3> ` } )
12
10
class ManyResolvesComponent {
11
+ constructor ( @Inject ( 'resolve1' ) foo , @Inject ( 'Resolve2' ) bar , @Inject ( 'resolve5' ) baz ) {
12
+ this . injectedValues = Array . from ( arguments ) ;
13
+ }
14
+
15
+ injectedValues : any [ ] ;
13
16
@Input ( ) resolve1 ;
14
17
@Input ( ) resolve2 ;
15
18
@Input ( 'resolve3' ) _resolve3 ;
16
19
@Input ( 'resolve4' ) _resolve4 ;
20
+ @Input ( ) resolve5 ;
17
21
}
18
22
19
23
let comp : ManyResolvesComponent ;
@@ -34,6 +38,7 @@ describe('uiView', () => {
34
38
{ token : 'Resolve2' , resolveFn : ( ) => 'resolve2' } ,
35
39
{ token : 'resolve3' , resolveFn : ( ) => 'resolve3' } ,
36
40
{ token : 'Resolve4' , resolveFn : ( ) => 'resolve4' } ,
41
+ new Resolvable ( 'resolve5' , ( ) => 'resolve5' , [ ] , { async : 'NOWAIT' } ) ,
37
42
] ,
38
43
} ;
39
44
@@ -52,6 +57,8 @@ describe('uiView', () => {
52
57
} ) ;
53
58
} ) ;
54
59
60
+ /////////////////////////////////////////
61
+
55
62
it ( 'should bind resolve by name to component input name' , ( ) => {
56
63
expect ( comp . resolve1 ) . toBe ( 'resolve1' ) ;
57
64
} ) ;
@@ -67,5 +74,26 @@ describe('uiView', () => {
67
74
it ( 'should bind resolve by name to the component input templateName specified in state `bindings`' , ( ) => {
68
75
expect ( comp . _resolve4 ) . toBe ( 'resolve4' ) ;
69
76
} ) ;
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
+ } ) ;
70
98
} ) ;
71
99
} ) ;
0 commit comments