@@ -41,40 +41,34 @@ describe('MatDrawer', () => {
41
41
describe ( 'methods' , ( ) => {
42
42
it ( 'should be able to open' , fakeAsync ( ( ) => {
43
43
const fixture = TestBed . createComponent ( BasicTestApp ) ;
44
-
45
44
fixture . detectChanges ( ) ;
46
45
47
46
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' ) ) ;
47
+ const container = fixture . debugElement . query ( By . css ( 'mat-drawer-container' ) ) . nativeElement ;
50
48
51
- drawerBackdropElement . nativeElement . style . transition = 'none' ;
52
49
fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
53
50
fixture . detectChanges ( ) ;
54
51
55
52
expect ( testComponent . openCount ) . toBe ( 0 ) ;
56
53
expect ( testComponent . openStartCount ) . toBe ( 0 ) ;
54
+ expect ( container . classList ) . not . toContain ( 'mat-drawer-opened' ) ;
57
55
58
56
tick ( ) ;
59
57
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
60
58
fixture . detectChanges ( ) ;
61
59
62
60
expect ( testComponent . openCount ) . toBe ( 1 ) ;
63
61
expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
64
- expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
65
- expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
62
+ expect ( container . classList ) . toContain ( 'mat-drawer-opened' ) ;
66
63
} ) ) ;
67
64
68
65
it ( 'should be able to close' , fakeAsync ( ( ) => {
69
66
const fixture = TestBed . createComponent ( BasicTestApp ) ;
70
-
71
67
fixture . detectChanges ( ) ;
72
68
73
69
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' ) ) ;
70
+ const container = fixture . debugElement . query ( By . css ( 'mat-drawer-container' ) ) . nativeElement ;
76
71
77
- drawerBackdropElement . nativeElement . style . transition = 'none' ;
78
72
fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
79
73
fixture . detectChanges ( ) ;
80
74
flush ( ) ;
@@ -85,15 +79,15 @@ describe('MatDrawer', () => {
85
79
86
80
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
87
81
expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
82
+ expect ( container . classList ) . toContain ( 'mat-drawer-opened' ) ;
88
83
89
84
flush ( ) ;
90
85
expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
91
86
fixture . detectChanges ( ) ;
92
87
93
88
expect ( testComponent . closeCount ) . toBe ( 1 ) ;
94
89
expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
95
- expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
96
- expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
90
+ expect ( container . classList ) . not . toContain ( 'mat-drawer-opened' ) ;
97
91
} ) ) ;
98
92
99
93
it ( 'should resolve the open method promise with the new state of the drawer' , fakeAsync ( ( ) => {
@@ -642,7 +636,7 @@ describe('MatDrawerContainer', () => {
642
636
expect ( parseInt ( contentElement . style . marginRight ) ) . toBe ( margin ) ;
643
637
} ) ) ;
644
638
645
- it ( 'should not animate when the sidenav is open on load ' , fakeAsync ( ( ) => {
639
+ it ( 'should not animate when the sidenav is open on load' , fakeAsync ( ( ) => {
646
640
TestBed
647
641
. resetTestingModule ( )
648
642
. configureTestingModule ( {
@@ -661,29 +655,32 @@ describe('MatDrawerContainer', () => {
661
655
expect ( container . classList ) . not . toContain ( 'mat-drawer-transition' ) ;
662
656
} ) ) ;
663
657
664
- it ( 'should recalculate the margin if a drawer changes size while open in autosize mode' ,
665
- fakeAsync ( ( ) => {
666
- const fixture = TestBed . createComponent ( AutosizeDrawer ) ;
658
+ it ( 'should recalculate the margin if drawer changes size while open in autosize mode' , done => {
659
+ const fixture = TestBed . createComponent ( AutosizeDrawer ) ;
667
660
668
- fixture . detectChanges ( ) ;
669
- fixture . componentInstance . drawer . open ( ) ;
670
- fixture . detectChanges ( ) ;
671
- tick ( ) ;
672
- fixture . detectChanges ( ) ;
661
+ fixture . detectChanges ( ) ;
662
+ fixture . componentInstance . drawer . open ( ) ;
663
+ fixture . detectChanges ( ) ;
673
664
665
+ fixture . whenStable ( ) . then ( ( ) => {
666
+ fixture . detectChanges ( ) ;
674
667
const contentEl = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
675
668
const initialMargin = parseInt ( contentEl . style . marginLeft ) ;
676
669
677
670
expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
678
671
679
672
fixture . componentInstance . fillerWidth = 200 ;
680
673
fixture . detectChanges ( ) ;
681
- tick ( 10 ) ;
682
- fixture . detectChanges ( ) ;
683
674
684
- expect ( parseInt ( contentEl . style . marginLeft ) ) . toBeGreaterThan ( initialMargin ) ;
685
- discardPeriodicTasks ( ) ;
686
- } ) ) ;
675
+ // Note that these 15ms are very slow for a unit test, but that how much the autosize
676
+ // is debounced and we need to give the browser some time to recalculate the styles.
677
+ setTimeout ( ( ) => {
678
+ fixture . detectChanges ( ) ;
679
+ expect ( parseInt ( contentEl . style . marginLeft ) ) . toBeGreaterThan ( initialMargin ) ;
680
+ done ( ) ;
681
+ } , 15 ) ;
682
+ } ) ;
683
+ } ) ;
687
684
688
685
it ( 'should not set a style property if it would be zero' , fakeAsync ( ( ) => {
689
686
const fixture = TestBed . createComponent ( AutosizeDrawer ) ;
@@ -945,10 +942,10 @@ class DrawerContainerStateChangesTestApp {
945
942
946
943
@Component ( {
947
944
template : `
948
- <mat-drawer-container autosize>
945
+ <mat-drawer-container autosize style="min-height: 200px;" >
949
946
<mat-drawer mode="push" [position]="drawer1Position">
950
947
Text
951
- <div [style.width.px]="fillerWidth"></div>
948
+ <div [style.width.px]="fillerWidth" style="height: 200px; background: red;" ></div>
952
949
</mat-drawer>
953
950
</mat-drawer-container>` ,
954
951
} )
0 commit comments