@@ -6,14 +6,15 @@ import {
6
6
TestBed ,
7
7
discardPeriodicTasks ,
8
8
flush ,
9
+ inject ,
9
10
} from '@angular/core/testing' ;
10
11
import { Component , ElementRef , ViewChild } from '@angular/core' ;
11
12
import { By } from '@angular/platform-browser' ;
12
13
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
13
14
import { MatDrawer , MatSidenavModule , MatDrawerContainer } from './index' ;
14
15
import { Direction } from '@angular/cdk/bidi' ;
15
16
import { A11yModule } from '@angular/cdk/a11y' ;
16
- import { PlatformModule } from '@angular/cdk/platform' ;
17
+ import { PlatformModule , Platform } from '@angular/cdk/platform' ;
17
18
import { ESCAPE } from '@angular/cdk/keycodes' ;
18
19
import { dispatchKeyboardEvent , createKeyboardEvent , dispatchEvent } from '@angular/cdk/testing' ;
19
20
import { CdkScrollable } from '@angular/cdk/scrolling' ;
@@ -41,40 +42,34 @@ describe('MatDrawer', () => {
41
42
describe ( 'methods' , ( ) => {
42
43
it ( 'should be able to open' , fakeAsync ( ( ) => {
43
44
const fixture = TestBed . createComponent ( BasicTestApp ) ;
44
-
45
45
fixture . detectChanges ( ) ;
46
46
47
47
const testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
48
- const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
49
- const drawerBackdropElement = fixture . debugElement . query ( By . css ( '.mat-drawer-backdrop' ) ) ;
48
+ const container = fixture . debugElement . query ( By . css ( 'mat-drawer-container' ) ) . nativeElement ;
50
49
51
- drawerBackdropElement . nativeElement . style . transition = 'none' ;
52
50
fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
53
51
fixture . detectChanges ( ) ;
54
52
55
53
expect ( testComponent . openCount ) . toBe ( 0 ) ;
56
54
expect ( testComponent . openStartCount ) . toBe ( 0 ) ;
55
+ expect ( container . classList ) . not . toContain ( 'mat-drawer-opened' ) ;
57
56
58
57
tick ( ) ;
59
58
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
60
59
fixture . detectChanges ( ) ;
61
60
62
61
expect ( testComponent . openCount ) . toBe ( 1 ) ;
63
62
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
64
- expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
65
- expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
63
+ expect ( container . classList ) . toContain ( 'mat-drawer-opened' ) ;
66
64
} ) ) ;
67
65
68
66
it ( 'should be able to close' , fakeAsync ( ( ) => {
69
67
const fixture = TestBed . createComponent ( BasicTestApp ) ;
70
-
71
68
fixture . detectChanges ( ) ;
72
69
73
70
const testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
74
- const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
75
- const drawerBackdropElement = fixture . debugElement . query ( By . css ( '.mat-drawer-backdrop' ) ) ;
71
+ const container = fixture . debugElement . query ( By . css ( 'mat-drawer-container' ) ) . nativeElement ;
76
72
77
- drawerBackdropElement . nativeElement . style . transition = 'none' ;
78
73
fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
79
74
fixture . detectChanges ( ) ;
80
75
flush ( ) ;
@@ -85,15 +80,15 @@ describe('MatDrawer', () => {
85
80
86
81
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
87
82
expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
83
+ expect ( container . classList ) . toContain ( 'mat-drawer-opened' ) ;
88
84
89
85
flush ( ) ;
90
86
expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
91
87
fixture . detectChanges ( ) ;
92
88
93
89
expect ( testComponent . closeCount ) . toBe ( 1 ) ;
94
90
expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
95
- expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
96
- expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
91
+ expect ( container . classList ) . not . toContain ( 'mat-drawer-opened' ) ;
97
92
} ) ) ;
98
93
99
94
it ( 'should resolve the open method promise with the new state of the drawer' , fakeAsync ( ( ) => {
@@ -642,7 +637,7 @@ describe('MatDrawerContainer', () => {
642
637
expect ( parseInt ( contentElement . style . marginRight ) ) . toBe ( margin ) ;
643
638
} ) ) ;
644
639
645
- it ( 'should not animate when the sidenav is open on load ' , fakeAsync ( ( ) => {
640
+ it ( 'should not animate when the sidenav is open on load' , fakeAsync ( ( ) => {
646
641
TestBed
647
642
. resetTestingModule ( )
648
643
. configureTestingModule ( {
@@ -662,7 +657,7 @@ describe('MatDrawerContainer', () => {
662
657
} ) ) ;
663
658
664
659
it ( 'should recalculate the margin if a drawer changes size while open in autosize mode' ,
665
- fakeAsync ( ( ) => {
660
+ fakeAsync ( inject ( [ Platform ] , ( platform : Platform ) => {
666
661
const fixture = TestBed . createComponent ( AutosizeDrawer ) ;
667
662
668
663
fixture . detectChanges ( ) ;
@@ -671,19 +666,31 @@ describe('MatDrawerContainer', () => {
671
666
tick ( ) ;
672
667
fixture . detectChanges ( ) ;
673
668
669
+ // IE and Edge are flaky in when they update the styles.
670
+ // For them we fall back to checking whether the proper method was called.
671
+ const isFlaky = platform . EDGE || platform . TRIDENT ;
674
672
const contentEl = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
675
673
const initialMargin = parseInt ( contentEl . style . marginLeft ) ;
676
674
677
- expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
675
+ if ( isFlaky ) {
676
+ spyOn ( fixture . componentInstance . drawerContainer , 'updateContentMargins' ) ;
677
+ } else {
678
+ expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
679
+ }
678
680
679
681
fixture . componentInstance . fillerWidth = 200 ;
680
682
fixture . detectChanges ( ) ;
681
683
tick ( 10 ) ;
682
684
fixture . detectChanges ( ) ;
683
685
684
- expect ( parseInt ( contentEl . style . marginLeft ) ) . toBeGreaterThan ( initialMargin ) ;
686
+ if ( isFlaky ) {
687
+ expect ( fixture . componentInstance . drawerContainer . updateContentMargins ) . toHaveBeenCalled ( ) ;
688
+ } else {
689
+ expect ( parseInt ( contentEl . style . marginLeft ) ) . toBeGreaterThan ( initialMargin ) ;
690
+ }
691
+
685
692
discardPeriodicTasks ( ) ;
686
- } ) ) ;
693
+ } ) ) ) ;
687
694
688
695
it ( 'should not set a style property if it would be zero' , fakeAsync ( ( ) => {
689
696
const fixture = TestBed . createComponent ( AutosizeDrawer ) ;
@@ -945,15 +952,16 @@ class DrawerContainerStateChangesTestApp {
945
952
946
953
@Component ( {
947
954
template : `
948
- <mat-drawer-container autosize>
955
+ <mat-drawer-container autosize style="min-height: 200px;" >
949
956
<mat-drawer mode="push" [position]="drawer1Position">
950
957
Text
951
- <div [style.width.px]="fillerWidth"></div>
958
+ <div [style.width.px]="fillerWidth" style="height: 200px; background: red;" ></div>
952
959
</mat-drawer>
953
960
</mat-drawer-container>` ,
954
961
} )
955
962
class AutosizeDrawer {
956
963
@ViewChild ( MatDrawer , { static : false } ) drawer : MatDrawer ;
964
+ @ViewChild ( MatDrawerContainer , { static : false } ) drawerContainer : MatDrawerContainer ;
957
965
fillerWidth = 0 ;
958
966
}
959
967
0 commit comments