@@ -314,7 +314,11 @@ describe('MdDrawerContainer', () => {
314
314
beforeEach ( async ( ( ) => {
315
315
TestBed . configureTestingModule ( {
316
316
imports : [ MdSidenavModule , A11yModule , PlatformModule , NoopAnimationsModule ] ,
317
- declarations : [ DrawerContainerTwoDrawerTestApp , DrawerDelayed ] ,
317
+ declarations : [
318
+ DrawerContainerTwoDrawerTestApp ,
319
+ DrawerDelayed ,
320
+ DrawerContainerStateChangesTestApp ,
321
+ ] ,
318
322
} ) ;
319
323
320
324
TestBed . compileComponents ( ) ;
@@ -363,6 +367,47 @@ describe('MdDrawerContainer', () => {
363
367
364
368
expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeGreaterThan ( 0 ) ;
365
369
} ) ) ;
370
+
371
+ it ( 'should recalculate the margin if a drawer is destroyed' , fakeAsync ( ( ) => {
372
+ const fixture = TestBed . createComponent ( DrawerContainerStateChangesTestApp ) ;
373
+
374
+ fixture . detectChanges ( ) ;
375
+ fixture . componentInstance . drawer . open ( ) ;
376
+ fixture . detectChanges ( ) ;
377
+ tick ( ) ;
378
+ fixture . detectChanges ( ) ;
379
+
380
+ const contentElement = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
381
+ const initialMargin = parseInt ( contentElement . style . marginLeft ) ;
382
+
383
+ expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
384
+
385
+ fixture . componentInstance . renderDrawer = false ;
386
+ fixture . detectChanges ( ) ;
387
+
388
+ expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
389
+ } ) ) ;
390
+
391
+ it ( 'should recalculate the margin if the drawer mode is changed' , fakeAsync ( ( ) => {
392
+ const fixture = TestBed . createComponent ( DrawerContainerStateChangesTestApp ) ;
393
+
394
+ fixture . detectChanges ( ) ;
395
+ fixture . componentInstance . drawer . open ( ) ;
396
+ fixture . detectChanges ( ) ;
397
+ tick ( ) ;
398
+ fixture . detectChanges ( ) ;
399
+
400
+ const contentElement = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
401
+ const initialMargin = parseInt ( contentElement . style . marginLeft ) ;
402
+
403
+ expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
404
+
405
+ fixture . componentInstance . mode = 'over' ;
406
+ fixture . detectChanges ( ) ;
407
+
408
+ expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
409
+ } ) ) ;
410
+
366
411
} ) ;
367
412
368
413
@@ -474,3 +519,19 @@ class DrawerDelayed {
474
519
@ViewChild ( MdDrawer ) drawer : MdDrawer ;
475
520
showDrawer = false ;
476
521
}
522
+
523
+
524
+ @Component ( {
525
+ template : `
526
+ <md-drawer-container>
527
+ <md-drawer *ngIf="renderDrawer" [mode]="mode"></md-drawer>
528
+ </md-drawer-container>` ,
529
+ } )
530
+ class DrawerContainerStateChangesTestApp {
531
+ @ViewChild ( MdDrawer ) drawer : MdDrawer ;
532
+ @ViewChild ( MdDrawerContainer ) drawerContainer : MdDrawerContainer ;
533
+
534
+ mode = 'side' ;
535
+ renderDrawer = true ;
536
+ }
537
+
0 commit comments