@@ -15,13 +15,17 @@ import {By} from 'angular2/platform/browser';
15
15
16
16
import { MdSidenav , MdSidenavLayout , MD_SIDENAV_DIRECTIVES } from './sidenav' ;
17
17
import { AsyncTestFn , FunctionWithParamTokens } from 'angular2/testing' ;
18
- import { ComponentFixture } from "angular2/testing" ;
19
- import { EventEmitter } from "angular2/core" ;
20
- import { Predicate } from "angular2/src/facade/collection" ;
18
+ import { ComponentFixture } from 'angular2/testing' ;
19
+ import { EventEmitter } from 'angular2/core' ;
20
+ import { Predicate } from 'angular2/src/facade/collection' ;
21
+ import { PromiseWrapper } from 'angular2/src/facade/promise' ;
22
+ import { TimerWrapper } from 'angular2/src/facade/async' ;
21
23
22
24
23
25
function wait ( msec : number ) {
24
- return new Promise ( resolve => window . setTimeout ( ( ) => resolve ( ) , msec ) ) ;
26
+ let completer = PromiseWrapper . completer ( ) ;
27
+ TimerWrapper . setTimeout ( completer . resolve , msec ) ;
28
+ return completer . promise ;
25
29
}
26
30
27
31
@@ -31,10 +35,10 @@ function waitOnEvent(fixture: ComponentFixture,
31
35
fixture . detectChanges ( ) ;
32
36
33
37
// Wait for the animation end.
34
- return new Promise ( resolve => {
35
- const component : any = fixture . debugElement . query ( by ) . componentInstance ;
36
- component [ propertyName ] . subscribe ( resolve ) ;
37
- } ) ;
38
+ let completer = PromiseWrapper . completer ( ) ;
39
+ let component : any = fixture . debugElement . query ( by ) . componentInstance ;
40
+ component [ propertyName ] . subscribe ( completer . resolve ) ;
41
+ return completer . promise ;
38
42
}
39
43
40
44
@@ -56,47 +60,47 @@ export function main() {
56
60
fixture = f ;
57
61
testComponent = fixture . debugElement . componentInstance ;
58
62
59
- const openButtonElement = fixture . debugElement . query ( By . css ( '.open' ) ) ;
63
+ let openButtonElement = fixture . debugElement . query ( By . css ( '.open' ) ) ;
60
64
openButtonElement . nativeElement . click ( ) ;
61
65
} )
62
- . then ( ( ) => wait ( 1 ) )
63
- . then ( ( ) => {
66
+ . then ( ( _ : any ) => { wait ( 1 ) ; } )
67
+ . then ( ( _ : any ) => {
64
68
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
65
69
expect ( testComponent . openCount ) . toBe ( 0 ) ;
66
70
} )
67
- . then ( ( ) => waitOnEvent ( fixture , By . directive ( MdSidenav ) , 'onOpen' ) )
68
- . then ( ( ) => {
71
+ . then ( ( _ : any ) => waitOnEvent ( fixture , By . directive ( MdSidenav ) , 'onOpen' ) )
72
+ . then ( ( _ : any ) => {
69
73
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
70
74
expect ( testComponent . openCount ) . toBe ( 1 ) ;
71
75
expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
72
76
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
73
77
74
- const sidenavElement = fixture . debugElement . query ( By . css ( 'md-sidenav' ) ) ;
75
- const sidenavBackdropElement = fixture . debugElement . query ( By . css ( '.md-sidenav-backdrop' ) ) ;
78
+ let sidenavElement = fixture . debugElement . query ( By . css ( 'md-sidenav' ) ) ;
79
+ let sidenavBackdropElement = fixture . debugElement . query ( By . css ( '.md-sidenav-backdrop' ) ) ;
76
80
expect ( window . getComputedStyle ( sidenavElement . nativeElement ) . visibility ) . toEqual ( 'visible' ) ;
77
81
expect ( window . getComputedStyle ( sidenavBackdropElement . nativeElement ) . visibility ) . toEqual ( 'visible' ) ;
78
82
79
83
// Close it.
80
- const closeButtonElement = fixture . debugElement . query ( By . css ( '.close' ) ) ;
84
+ let closeButtonElement = fixture . debugElement . query ( By . css ( '.close' ) ) ;
81
85
closeButtonElement . nativeElement . click ( ) ;
82
86
} )
83
- . then ( ( ) => wait ( 1 ) )
84
- . then ( ( ) => {
87
+ . then ( ( _ : any ) => wait ( 1 ) )
88
+ . then ( ( _ : any ) => {
85
89
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
86
90
expect ( testComponent . openCount ) . toBe ( 1 ) ;
87
91
expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
88
92
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
89
93
} )
90
- . then ( ( ) => waitOnEvent ( fixture , By . directive ( MdSidenav ) , 'onClose' ) )
91
- . then ( ( ) => fixture . detectChanges ( ) )
92
- . then ( ( ) => {
94
+ . then ( ( _ : any ) => waitOnEvent ( fixture , By . directive ( MdSidenav ) , 'onClose' ) )
95
+ . then ( ( _ : any ) => fixture . detectChanges ( ) )
96
+ . then ( ( _ : any ) => {
93
97
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
94
98
expect ( testComponent . openCount ) . toBe ( 1 ) ;
95
99
expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
96
100
expect ( testComponent . closeCount ) . toBe ( 1 ) ;
97
101
98
- const sidenavElement = fixture . debugElement . query ( By . css ( 'md-sidenav' ) ) ;
99
- const sidenavBackdropElement = fixture . debugElement . query ( By . css ( '.md-sidenav-backdrop' ) ) ;
102
+ let sidenavElement = fixture . debugElement . query ( By . css ( 'md-sidenav' ) ) ;
103
+ let sidenavBackdropElement = fixture . debugElement . query ( By . css ( '.md-sidenav-backdrop' ) ) ;
100
104
expect ( window . getComputedStyle ( sidenavElement . nativeElement ) . visibility ) . toEqual ( 'hidden' ) ;
101
105
expect ( window . getComputedStyle ( sidenavBackdropElement . nativeElement ) . visibility ) . toEqual ( 'hidden' ) ;
102
106
} )
@@ -105,11 +109,10 @@ export function main() {
105
109
106
110
it ( 'open() and close() return a promise that resolves after the animation ended' ,
107
111
( done : any ) => {
108
- let testComponent : BasicTestApp ;
109
112
let fixture : ComponentFixture ;
110
113
let sidenav : MdSidenav ;
111
114
112
- let promise : Promise < { } > ;
115
+ let promise : Promise < void > ;
113
116
let called : boolean = false ;
114
117
115
118
return builder . createAsync ( BasicTestApp )
@@ -118,38 +121,36 @@ export function main() {
118
121
sidenav = fixture . debugElement . query ( By . directive ( MdSidenav ) ) . componentInstance ;
119
122
120
123
promise = sidenav . open ( ) ;
121
- promise . then ( ( ) => called = true ) ;
124
+ promise . then ( ( _ : any ) => called = true ) ;
122
125
} )
123
- . then ( ( ) => wait ( 1 ) )
124
- . then ( ( ) => fixture . detectChanges ( ) )
125
- . then ( ( ) => {
126
+ . then ( ( _ : any ) => wait ( 1 ) )
127
+ . then ( ( _ : any ) => fixture . detectChanges ( ) )
128
+ . then ( ( _ : any ) => {
126
129
expect ( called ) . toBe ( false ) ;
127
130
} )
128
- . then ( ( ) => promise )
129
- . then ( ( ) => expect ( called ) . toBe ( true ) )
130
- . then ( ( ) => {
131
+ . then ( ( _ : any ) => promise )
132
+ . then ( ( _ : any ) => expect ( called ) . toBe ( true ) )
133
+ . then ( ( _ : any ) => {
131
134
// Close it now.
132
135
called = false ;
133
136
promise = sidenav . close ( ) ;
134
- promise . then ( ( ) => called = true ) ;
137
+ promise . then ( ( _ : any ) => called = true ) ;
135
138
} )
136
- . then ( ( ) => wait ( 1 ) )
137
- . then ( ( ) => fixture . detectChanges ( ) )
138
- . then ( ( ) => {
139
+ . then ( ( _ : any ) => wait ( 1 ) )
140
+ . then ( ( _ : any ) => fixture . detectChanges ( ) )
141
+ . then ( ( _ : any ) => {
139
142
expect ( called ) . toBe ( false ) ;
140
143
} )
141
- . then ( ( ) => promise )
142
- . then ( ( ) => expect ( called ) . toBe ( true ) )
144
+ . then ( ( _ : any ) => promise )
145
+ . then ( ( _ : any ) => expect ( called ) . toBe ( true ) )
143
146
. then ( done , done . fail ) ;
144
147
} , 8000 ) ;
145
148
146
149
it ( 'open() twice returns the same promise' , ( done : any ) => {
147
- let testComponent : BasicTestApp ;
148
150
let fixture : ComponentFixture ;
149
151
let sidenav : MdSidenav ;
150
152
151
- let promise : Promise < { } > ;
152
- let called : boolean = false ;
153
+ let promise : Promise < void > ;
153
154
154
155
return builder . createAsync ( BasicTestApp )
155
156
. then ( ( f ) => {
@@ -159,12 +160,12 @@ export function main() {
159
160
promise = sidenav . open ( ) ;
160
161
expect ( sidenav . open ( ) ) . toBe ( promise ) ;
161
162
} )
162
- . then ( ( ) => wait ( 1 ) )
163
- . then ( ( ) => {
163
+ . then ( ( _ : any ) => wait ( 1 ) )
164
+ . then ( ( _ : any ) => {
164
165
fixture . detectChanges ( ) ;
165
166
return promise ;
166
167
} )
167
- . then ( ( ) => {
168
+ . then ( ( _ : any ) => {
168
169
promise = sidenav . close ( ) ;
169
170
expect ( sidenav . close ( ) ) . toBe ( promise ) ;
170
171
} )
@@ -173,12 +174,11 @@ export function main() {
173
174
174
175
it ( 'open() then close() cancel animations when called too fast' ,
175
176
( done : any ) => {
176
- let testComponent : BasicTestApp ;
177
177
let fixture : ComponentFixture ;
178
178
let sidenav : MdSidenav ;
179
179
180
- let openPromise : Promise < any > ;
181
- let closePromise : Promise < any > ;
180
+ let openPromise : Promise < void > ;
181
+ let closePromise : Promise < void > ;
182
182
let openCalled : boolean = false ;
183
183
let openCancelled : boolean = false ;
184
184
let closeCalled : boolean = false ;
@@ -188,28 +188,28 @@ export function main() {
188
188
fixture = f ;
189
189
sidenav = fixture . debugElement . query ( By . directive ( MdSidenav ) ) . componentInstance ;
190
190
191
- openPromise = sidenav . open ( ) . then ( ( ) => {
191
+ openPromise = sidenav . open ( ) . then ( ( _ : any ) => {
192
192
openCalled = true ;
193
193
} ,
194
194
( ) => {
195
195
openCancelled = true ;
196
196
} ) ;
197
197
} )
198
- . then ( ( ) => wait ( 1 ) )
199
- . then ( ( ) => fixture . detectChanges ( ) )
198
+ . then ( ( _ : any ) => wait ( 1 ) )
199
+ . then ( ( _ : any ) => fixture . detectChanges ( ) )
200
200
// We need to wait for the browser to start the transition.
201
- . then ( ( ) => wait ( 50 ) )
202
- . then ( ( ) => {
203
- closePromise = sidenav . close ( ) . then ( ( ) => {
201
+ . then ( ( _ : any ) => wait ( 50 ) )
202
+ . then ( ( _ : any ) => {
203
+ closePromise = sidenav . close ( ) . then ( ( _ : any ) => {
204
204
closeCalled = true ;
205
205
} , done . fail ) ;
206
206
return wait ( 1 ) ;
207
207
} )
208
- . then ( ( ) => {
208
+ . then ( ( _ : any ) => {
209
209
fixture . detectChanges ( ) ;
210
210
return closePromise ;
211
211
} )
212
- . then ( ( ) => {
212
+ . then ( ( _ : any ) => {
213
213
expect ( openCalled ) . toBe ( false ) ;
214
214
expect ( openCancelled ) . toBe ( true ) ;
215
215
expect ( closeCalled ) . toBe ( true ) ;
@@ -223,8 +223,8 @@ export function main() {
223
223
let fixture : ComponentFixture ;
224
224
let sidenav : MdSidenav ;
225
225
226
- let openPromise : Promise < any > ;
227
- let closePromise : Promise < any > ;
226
+ let openPromise : Promise < void > ;
227
+ let closePromise : Promise < void > ;
228
228
let closeCalled : boolean = false ;
229
229
let closeCancelled : boolean = false ;
230
230
let openCalled : boolean = false ;
@@ -237,35 +237,35 @@ export function main() {
237
237
/** First, open it. */
238
238
openPromise = sidenav . open ( ) ;
239
239
} )
240
- . then ( ( ) => wait ( 1 ) )
241
- . then ( ( ) => {
240
+ . then ( ( _ : any ) => wait ( 1 ) )
241
+ . then ( ( _ : any ) => {
242
242
fixture . detectChanges ( ) ;
243
243
return openPromise ;
244
244
} )
245
- . then ( ( ) => {
245
+ . then ( ( _ : any ) => {
246
246
// Then close and check behavior.
247
- closePromise = sidenav . close ( ) . then ( ( ) => {
247
+ closePromise = sidenav . close ( ) . then ( ( _ : any ) => {
248
248
closeCalled = true ;
249
249
} ,
250
250
( ) => {
251
251
closeCancelled = true ;
252
252
} ) ;
253
253
} )
254
- . then ( ( ) => wait ( 1 ) )
255
- . then ( ( ) => fixture . detectChanges ( ) )
254
+ . then ( ( _ : any ) => wait ( 1 ) )
255
+ . then ( ( _ : any ) => fixture . detectChanges ( ) )
256
256
// We need to wait for the browser to start the transition.
257
- . then ( ( ) => wait ( 50 ) )
258
- . then ( ( ) => {
259
- openPromise = sidenav . open ( ) . then ( ( ) => {
257
+ . then ( ( _ : any ) => wait ( 50 ) )
258
+ . then ( ( _ : any ) => {
259
+ openPromise = sidenav . open ( ) . then ( ( _ : any ) => {
260
260
openCalled = true ;
261
261
} , done . fail ) ;
262
262
return wait ( 1 ) ;
263
263
} )
264
- . then ( ( ) => {
264
+ . then ( ( _ : any ) => {
265
265
fixture . detectChanges ( ) ;
266
266
return openPromise ;
267
267
} )
268
- . then ( ( ) => {
268
+ . then ( ( _ : any ) => {
269
269
expect ( closeCalled ) . toBe ( false ) ;
270
270
expect ( closeCancelled ) . toBe ( true ) ;
271
271
expect ( openCalled ) . toBe ( true ) ;
0 commit comments