1
1
import {
2
+ iit ,
2
3
it ,
3
4
describe ,
4
5
expect ,
@@ -13,6 +14,7 @@ import {
13
14
import { XHR } from 'angular2/src/compiler/xhr' ;
14
15
import {
15
16
Component ,
17
+ Type ,
16
18
ViewMetadata
17
19
} from 'angular2/core' ;
18
20
@@ -28,7 +30,7 @@ function fakeAsyncAdaptor(fn: () => void) {
28
30
/**
29
31
* Create a ComponentFixture from the builder. This takes a template and a style for sidenav.
30
32
*/
31
- function createFixture ( builder : TestComponentBuilder ,
33
+ function createFixture ( appType : Type , builder : TestComponentBuilder ,
32
34
template : string , style : string ) : ComponentFixture {
33
35
let fixture : ComponentFixture = null ;
34
36
// Remove the styles (which remove the animations/transitions).
@@ -38,7 +40,7 @@ function createFixture(builder: TestComponentBuilder,
38
40
styles : [ style ] ,
39
41
directives : [ MdSidenav ] ,
40
42
} ) )
41
- . createAsync ( BasicTestApp ) . then ( ( f : ComponentFixture ) => { fixture = f ; } ) ;
43
+ . createAsync ( appType ) . then ( ( f : ComponentFixture ) => { fixture = f ; } ) ;
42
44
tick ( ) ;
43
45
44
46
return fixture ;
@@ -81,7 +83,7 @@ export function main() {
81
83
82
84
describe ( 'methods' , ( ) => {
83
85
it ( 'should be able to open and close' , fakeAsyncAdaptor ( ( ) => {
84
- let fixture = createFixture ( builder , template , style ) ;
86
+ let fixture = createFixture ( BasicTestApp , builder , template , style ) ;
85
87
86
88
let testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
87
89
let openButtonElement = fixture . debugElement . query ( By . css ( '.open' ) ) ;
@@ -130,12 +132,12 @@ export function main() {
130
132
} ) ) ;
131
133
132
134
it ( 'open/close() return a promise that resolves after animation end' , fakeAsyncAdaptor ( ( ) => {
133
- let fixture = createFixture ( builder , template , style ) ;
135
+ let fixture = createFixture ( BasicTestApp , builder , template , style ) ;
134
136
let sidenav : MdSidenav = fixture . debugElement
135
137
. query ( By . directive ( MdSidenav ) ) . componentInstance ;
136
138
let called = false ;
137
139
138
- sidenav . open ( ) . then ( ( _ : any ) => {
140
+ sidenav . open ( ) . then ( ( ) => {
139
141
called = true ;
140
142
} ) ;
141
143
@@ -145,7 +147,7 @@ export function main() {
145
147
expect ( called ) . toBe ( true ) ;
146
148
147
149
called = false ;
148
- sidenav . close ( ) . then ( ( _ : any ) => {
150
+ sidenav . close ( ) . then ( ( ) => {
149
151
called = true ;
150
152
} ) ;
151
153
@@ -157,7 +159,7 @@ export function main() {
157
159
} ) ) ;
158
160
159
161
it ( 'open/close() twice returns the same promise' , fakeAsyncAdaptor ( ( ) => {
160
- let fixture = createFixture ( builder , template , style ) ;
162
+ let fixture = createFixture ( BasicTestApp , builder , template , style ) ;
161
163
let sidenav : MdSidenav = fixture . debugElement
162
164
. query ( By . directive ( MdSidenav ) ) . componentInstance ;
163
165
@@ -172,19 +174,18 @@ export function main() {
172
174
} ) ) ;
173
175
174
176
it ( 'open() then close() cancel animations when called too fast' , fakeAsyncAdaptor ( ( ) => {
175
- let fixture = createFixture ( builder , template , style ) ;
177
+ let fixture = createFixture ( BasicTestApp , builder , template , style ) ;
176
178
let sidenav : MdSidenav = fixture . debugElement
177
179
. query ( By . directive ( MdSidenav ) ) . componentInstance ;
178
180
179
- let closePromise : Promise < void > ;
180
181
let openCalled = false ;
181
182
let openCancelled = false ;
182
183
let closeCalled = false ;
183
184
184
- sidenav . open ( ) . then ( ( _ : any ) => { openCalled = true ; } , ( ) => { openCancelled = true ; } ) ;
185
+ sidenav . open ( ) . then ( ( ) => { openCalled = true ; } , ( ) => { openCancelled = true ; } ) ;
185
186
186
187
// We do not call transition end, close directly.
187
- closePromise = sidenav . close ( ) . then ( ( _ : any ) => { closeCalled = true ; } ) ;
188
+ sidenav . close ( ) . then ( ( ) => { closeCalled = true ; } ) ;
188
189
189
190
endSidenavTransition ( fixture ) ;
190
191
tick ( ) ;
@@ -196,7 +197,7 @@ export function main() {
196
197
} ) ) ;
197
198
198
199
it ( 'close() then open() cancel animations when called too fast' , fakeAsyncAdaptor ( ( ) => {
199
- let fixture = createFixture ( builder , template , style ) ;
200
+ let fixture = createFixture ( BasicTestApp , builder , template , style ) ;
200
201
let sidenav : MdSidenav = fixture . debugElement
201
202
. query ( By . directive ( MdSidenav ) ) . componentInstance ;
202
203
@@ -210,9 +211,9 @@ export function main() {
210
211
tick ( ) ;
211
212
212
213
// Then close and check behavior.
213
- sidenav . close ( ) . then ( ( _ : any ) => { closeCalled = true ; } , ( ) => { closeCancelled = true ; } ) ;
214
+ sidenav . close ( ) . then ( ( ) => { closeCalled = true ; } , ( ) => { closeCancelled = true ; } ) ;
214
215
// We do not call transition end, open directly.
215
- sidenav . open ( ) . then ( ( _ : any ) => { openCalled = true ; } ) ;
216
+ sidenav . open ( ) . then ( ( ) => { openCalled = true ; } ) ;
216
217
217
218
endSidenavTransition ( fixture ) ;
218
219
tick ( ) ;
@@ -222,10 +223,55 @@ export function main() {
222
223
expect ( openCalled ) . toBe ( true ) ;
223
224
tick ( ) ;
224
225
} ) ) ;
226
+
227
+ it ( 'does not throw when created without a sidenav' , fakeAsyncAdaptor ( ( ) => {
228
+ expect ( ( ) => {
229
+ let fixture = createFixture ( SidenavLayoutNoSidenavTestApp , builder , template , style ) ;
230
+ fixture . detectChanges ( ) ;
231
+ tick ( ) ;
232
+ } ) . not . toThrow ( ) ;
233
+ } ) ) ;
234
+
235
+ it ( 'does throw when created with two sidenav on the same side' , fakeAsyncAdaptor ( ( ) => {
236
+ expect ( ( ) => {
237
+ let fixture = createFixture ( SidenavLayoutTwoSidenavTestApp , builder , template , style ) ;
238
+ fixture . detectChanges ( ) ;
239
+ tick ( ) ;
240
+ } ) . toThrow ( ) ;
241
+ } ) ) ;
225
242
} ) ;
226
243
} ) ;
227
244
}
228
245
246
+
247
+ /** Test component that contains an MdSidenavLayout but no MdSidenav. */
248
+ @Component ( {
249
+ selector : 'test-app' ,
250
+ directives : [ MD_SIDENAV_DIRECTIVES ] ,
251
+ template : `
252
+ <md-sidenav-layout>
253
+ </md-sidenav-layout>
254
+ ` ,
255
+ } )
256
+ class SidenavLayoutNoSidenavTestApp {
257
+ }
258
+
259
+
260
+ /** Test component that contains an MdSidenavLayout and 2 MdSidenav on the same side. */
261
+ @Component ( {
262
+ selector : 'test-app' ,
263
+ directives : [ MD_SIDENAV_DIRECTIVES ] ,
264
+ template : `
265
+ <md-sidenav-layout>
266
+ <md-sidenav> </md-sidenav>
267
+ <md-sidenav> </md-sidenav>
268
+ </md-sidenav-layout>
269
+ ` ,
270
+ } )
271
+ class SidenavLayoutTwoSidenavTestApp {
272
+ }
273
+
274
+
229
275
/** Test component that contains an MdSidenavLayout and one MdSidenav. */
230
276
@Component ( {
231
277
selector : 'test-app' ,
0 commit comments