@@ -28,45 +28,98 @@ describe('MatDrawer', () => {
28
28
} ) ) ;
29
29
30
30
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 ) ;
33
33
34
34
fixture . detectChanges ( ) ;
35
35
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' ) ) ;
39
39
40
40
drawerBackdropElement . nativeElement . style . transition = 'none' ;
41
41
fixture . debugElement . query ( By . css ( '.open' ) ) . nativeElement . click ( ) ;
42
42
fixture . detectChanges ( ) ;
43
43
44
44
expect ( testComponent . openCount ) . toBe ( 0 ) ;
45
- expect ( testComponent . closeCount ) . toBe ( 0 ) ;
45
+ expect ( testComponent . openStartCount ) . toBe ( 0 ) ;
46
46
47
47
tick ( ) ;
48
+ expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
48
49
fixture . detectChanges ( ) ;
49
50
50
51
expect ( testComponent . openCount ) . toBe ( 1 ) ;
51
- expect ( testComponent . closeCount ) . toBe ( 0 ) ;
52
+ expect ( testComponent . openStartCount ) . toBe ( 1 ) ;
52
53
expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'visible' ) ;
53
54
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 ( ) ;
54
71
55
72
fixture . debugElement . query ( By . css ( '.close' ) ) . nativeElement . click ( ) ;
56
73
fixture . detectChanges ( ) ;
57
74
58
- expect ( testComponent . openCount ) . toBe ( 1 ) ;
59
75
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
76
+ expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
60
77
61
78
tick ( ) ;
79
+ expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
62
80
fixture . detectChanges ( ) ;
63
81
64
- expect ( testComponent . openCount ) . toBe ( 1 ) ;
65
82
expect ( testComponent . closeCount ) . toBe ( 1 ) ;
83
+ expect ( testComponent . closeStartCount ) . toBe ( 1 ) ;
66
84
expect ( getComputedStyle ( drawer . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
67
85
expect ( getComputedStyle ( drawerBackdropElement . nativeElement ) . visibility ) . toBe ( 'hidden' ) ;
68
86
} ) ) ;
69
87
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
+
70
123
it ( 'should be able to close while the open animation is running' , fakeAsync ( ( ) => {
71
124
const fixture = TestBed . createComponent ( BasicTestApp ) ;
72
125
fixture . detectChanges ( ) ;
@@ -139,13 +192,16 @@ describe('MatDrawer', () => {
139
192
tick ( ) ;
140
193
141
194
expect ( testComponent . openCount ) . toBe ( 1 , 'Expected one open event.' ) ;
195
+ expect ( testComponent . openStartCount ) . toBe ( 1 , 'Expected one open start event.' ) ;
142
196
expect ( testComponent . closeCount ) . toBe ( 0 , 'Expected no close events.' ) ;
197
+ expect ( testComponent . closeStartCount ) . toBe ( 0 , 'Expected no close start events.' ) ;
143
198
144
199
dispatchKeyboardEvent ( drawer . nativeElement , 'keydown' , ESCAPE ) ;
145
200
fixture . detectChanges ( ) ;
146
201
tick ( ) ;
147
202
148
203
expect ( testComponent . closeCount ) . toBe ( 1 , 'Expected one close event.' ) ;
204
+ expect ( testComponent . closeStartCount ) . toBe ( 1 , 'Expected one close start event.' ) ;
149
205
} ) ) ;
150
206
151
207
it ( 'should fire the open event when open on init' , fakeAsync ( ( ) => {
@@ -172,6 +228,7 @@ describe('MatDrawer', () => {
172
228
tick ( ) ;
173
229
174
230
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
231
+ expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
175
232
} ) ) ;
176
233
177
234
it ( 'should not close by clicking on the backdrop when disableClose is set' , fakeAsync ( ( ) => {
@@ -189,6 +246,7 @@ describe('MatDrawer', () => {
189
246
tick ( ) ;
190
247
191
248
expect ( testComponent . closeCount ) . toBe ( 0 ) ;
249
+ expect ( testComponent . closeStartCount ) . toBe ( 0 ) ;
192
250
} ) ) ;
193
251
194
252
it ( 'should restore focus on close if focus is inside drawer' , fakeAsync ( ( ) => {
@@ -490,17 +548,21 @@ class DrawerContainerTwoDrawerTestApp {
490
548
<mat-drawer-container (backdropClick)="backdropClicked()">
491
549
<mat-drawer #drawer position="start"
492
550
(opened)="open()"
493
- (closed)="close()">
551
+ (openedStart)="openStart()"
552
+ (closed)="close()"
553
+ (closedStart)="closeStart()">
494
554
<button #drawerButton>Content.</button>
495
555
</mat-drawer>
496
556
<button (click)="drawer.open()" class="open" #openButton></button>
497
557
<button (click)="drawer.close()" class="close" #closeButton></button>
498
558
</mat-drawer-container>` ,
499
559
} )
500
560
class 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 ;
504
566
505
567
@ViewChild ( 'drawerButton' ) drawerButton : ElementRef ;
506
568
@ViewChild ( 'openButton' ) openButton : ElementRef ;
@@ -510,10 +572,18 @@ class BasicTestApp {
510
572
this . openCount ++ ;
511
573
}
512
574
575
+ openStart ( ) {
576
+ this . openStartCount ++ ;
577
+ }
578
+
513
579
close ( ) {
514
580
this . closeCount ++ ;
515
581
}
516
582
583
+ closeStart ( ) {
584
+ this . closeStartCount ++ ;
585
+ }
586
+
517
587
backdropClicked ( ) {
518
588
this . backdropClickedCount ++ ;
519
589
}
0 commit comments