@@ -28,45 +28,98 @@ describe('MatDrawer', () => {
2828 } ) ) ;
2929
3030 describe ( 'methods' , ( ) => {
31- it ( 'should be able to open and close ' , fakeAsync ( ( ) => {
32- let fixture = TestBed . createComponent ( BasicTestApp ) ;
31+ it ( 'should be able to open' , fakeAsync ( ( ) => {
32+ const fixture = TestBed . createComponent ( BasicTestApp ) ;
3333
3434 fixture . detectChanges ( ) ;
3535
36- let testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
37- let drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
38- let drawerBackdropElement = fixture . debugElement . query ( By . css ( '.mat-drawer-backdrop' ) ) ;
36+ const testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
37+ const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
38+ const drawerBackdropElement = fixture . debugElement . query ( By . css ( '.mat-drawer-backdrop' ) ) ;
3939
4040 drawerBackdropElement . nativeElement . style . transition = 'none' ;
4141 fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
4242 fixture . detectChanges ( ) ;
4343
4444 expect ( testComponent . openCount ) . toBe ( 0 ) ;
45- expect ( testComponent . closeCount ) . toBe ( 0 ) ;
45+ expect ( testComponent . openStartCount ) . toBe ( 0 ) ;
4646
4747 tick ( ) ;
48+ expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
4849 fixture . detectChanges ( ) ;
4950
5051 expect ( testComponent . openCount ) . toBe ( 1 ) ;
51- expect ( testComponent . closeCount ) . toBe ( 0 ) ;
52+ expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
5253 expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
5354 expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
55+ } ) ) ;
56+
57+ it ( 'should be able to close' , fakeAsync ( ( ) => {
58+ const fixture = TestBed . createComponent ( BasicTestApp ) ;
59+
60+ fixture . detectChanges ( ) ;
61+
62+ const testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
63+ const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
64+ const drawerBackdropElement = fixture . debugElement . query ( By . css ( '.mat-drawer-backdrop' ) ) ;
65+
66+ drawerBackdropElement . nativeElement . style . transition = 'none' ;
67+ fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
68+ fixture . detectChanges ( ) ;
69+ tick ( ) ;
70+ fixture . detectChanges ( ) ;
5471
5572 fixture . debugElement . query ( By . css ( '.close' ) ) . nativeElement . click ( ) ;
5673 fixture . detectChanges ( ) ;
5774
58- expect ( testComponent . openCount ) . toBe ( 1 ) ;
5975 expect ( testComponent . closeCount ) . toBe ( 0 ) ;
76+ expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
6077
6178 tick ( ) ;
79+ expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
6280 fixture . detectChanges ( ) ;
6381
64- expect ( testComponent . openCount ) . toBe ( 1 ) ;
6582 expect ( testComponent . closeCount ) . toBe ( 1 ) ;
83+ expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
6684 expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
6785 expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
6886 } ) ) ;
6987
88+ it ( 'should resolve the open method promise with an object' , fakeAsync ( ( ) => {
89+ const fixture = TestBed . createComponent ( BasicTestApp ) ;
90+ fixture . detectChanges ( ) ;
91+ const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
92+
93+ drawer . componentInstance . open ( ) . then ( result => {
94+ expect ( result ) . toBeTruthy ( ) ;
95+ expect ( result . type ) . toBe ( 'open' ) ;
96+ expect ( result . animationFinished ) . toBe ( true ) ;
97+ } ) ;
98+ fixture . detectChanges ( ) ;
99+ tick ( ) ;
100+ fixture . detectChanges ( ) ;
101+ } ) ) ;
102+
103+ it ( 'should resolve the close method promise with an object' , fakeAsync ( ( ) => {
104+ const fixture = TestBed . createComponent ( BasicTestApp ) ;
105+ fixture . detectChanges ( ) ;
106+ const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
107+
108+ drawer . componentInstance . open ( ) ;
109+ fixture . detectChanges ( ) ;
110+ tick ( ) ;
111+ fixture . detectChanges ( ) ;
112+
113+ drawer . componentInstance . close ( ) . then ( result => {
114+ expect ( result ) . toBeTruthy ( ) ;
115+ expect ( result . type ) . toBe ( 'close' ) ;
116+ expect ( result . animationFinished ) . toBe ( true ) ;
117+ } ) ;
118+ fixture . detectChanges ( ) ;
119+ tick ( ) ;
120+ fixture . detectChanges ( ) ;
121+ } ) ) ;
122+
70123 it ( 'should be able to close while the open animation is running' , fakeAsync ( ( ) => {
71124 const fixture = TestBed . createComponent ( BasicTestApp ) ;
72125 fixture . detectChanges ( ) ;
@@ -139,13 +192,16 @@ describe('MatDrawer', () => {
139192 tick ( ) ;
140193
141194 expect ( testComponent . openCount ) . toBe ( 1 , 'Expected one open event.' ) ;
195+ expect ( testComponent . openStartCount ) . toBe ( 1 , 'Expected one open start event.' ) ;
142196 expect ( testComponent . closeCount ) . toBe ( 0 , 'Expected no close events.' ) ;
197+ expect ( testComponent . closeStartCount ) . toBe ( 0 , 'Expected no close start events.' ) ;
143198
144199 dispatchKeyboardEvent ( drawer . nativeElement , 'keydown' , ESCAPE ) ;
145200 fixture . detectChanges ( ) ;
146201 tick ( ) ;
147202
148203 expect ( testComponent . closeCount ) . toBe ( 1 , 'Expected one close event.' ) ;
204+ expect ( testComponent . closeStartCount ) . toBe ( 1 , 'Expected one close start event.' ) ;
149205 } ) ) ;
150206
151207 it ( 'should fire the open event when open on init' , fakeAsync ( ( ) => {
@@ -172,6 +228,7 @@ describe('MatDrawer', () => {
172228 tick ( ) ;
173229
174230 expect ( testComponent . closeCount ) . toBe ( 0 ) ;
231+ expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
175232 } ) ) ;
176233
177234 it ( 'should not close by clicking on the backdrop when disableClose is set' , fakeAsync ( ( ) => {
@@ -189,6 +246,7 @@ describe('MatDrawer', () => {
189246 tick ( ) ;
190247
191248 expect ( testComponent . closeCount ) . toBe ( 0 ) ;
249+ expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
192250 } ) ) ;
193251
194252 it ( 'should restore focus on close if focus is inside drawer' , fakeAsync ( ( ) => {
@@ -490,17 +548,21 @@ class DrawerContainerTwoDrawerTestApp {
490548 <mat-drawer-container (backdropClick)="backdropClicked()">
491549 <mat-drawer #drawer position="start"
492550 (opened)="open()"
493- (closed)="close()">
551+ (openedStart)="openStart()"
552+ (closed)="close()"
553+ (closedStart)="closeStart()">
494554 <button #drawerButton>Content.</button>
495555 </mat-drawer>
496556 <button (click)="drawer.open()" class="open" #openButton></button>
497557 <button (click)="drawer.close()" class="close" #closeButton></button>
498558 </mat-drawer-container>` ,
499559} )
500560class BasicTestApp {
501- openCount : number = 0 ;
502- closeCount : number = 0 ;
503- backdropClickedCount : number = 0 ;
561+ openCount = 0 ;
562+ openStartCount = 0 ;
563+ closeCount = 0 ;
564+ closeStartCount = 0 ;
565+ backdropClickedCount = 0 ;
504566
505567 @ViewChild ( 'drawerButton' ) drawerButton : ElementRef ;
506568 @ViewChild ( 'openButton' ) openButton : ElementRef ;
@@ -510,10 +572,18 @@ class BasicTestApp {
510572 this . openCount ++ ;
511573 }
512574
575+ openStart ( ) {
576+ this . openStartCount ++ ;
577+ }
578+
513579 close ( ) {
514580 this . closeCount ++ ;
515581 }
516582
583+ closeStart ( ) {
584+ this . closeStartCount ++ ;
585+ }
586+
517587 backdropClicked ( ) {
518588 this . backdropClickedCount ++ ;
519589 }
0 commit comments