@@ -2,6 +2,7 @@ import {A11yModule} from '@angular/cdk/a11y';
2
2
import { Direction } from '@angular/cdk/bidi' ;
3
3
import { ESCAPE } from '@angular/cdk/keycodes' ;
4
4
import { CdkScrollable } from '@angular/cdk/scrolling' ;
5
+ import { OverlayKeyboardDispatcher , OverlayRef } from '@angular/cdk/overlay' ;
5
6
import {
6
7
createKeyboardEvent ,
7
8
dispatchEvent ,
@@ -22,7 +23,13 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
22
23
import { MatDrawer , MatDrawerContainer , MatSidenavModule } from './index' ;
23
24
24
25
describe ( 'MatDrawer' , ( ) => {
26
+ let fakeKeyboardDispatcher : OverlayKeyboardDispatcher ;
27
+
25
28
beforeEach ( waitForAsync ( ( ) => {
29
+ fakeKeyboardDispatcher = {
30
+ _attachedOverlays : [ ] as OverlayRef [ ] ,
31
+ } as OverlayKeyboardDispatcher ;
32
+
26
33
TestBed . configureTestingModule ( {
27
34
imports : [
28
35
MatSidenavModule ,
@@ -39,6 +46,12 @@ describe('MatDrawer', () => {
39
46
IndirectDescendantDrawer ,
40
47
NestedDrawerContainers ,
41
48
] ,
49
+ providers : [
50
+ {
51
+ provide : OverlayKeyboardDispatcher ,
52
+ useValue : fakeKeyboardDispatcher ,
53
+ } ,
54
+ ] ,
42
55
} ) ;
43
56
} ) ) ;
44
57
@@ -237,6 +250,33 @@ describe('MatDrawer', () => {
237
250
expect ( event . defaultPrevented ) . toBe ( false ) ;
238
251
} ) ) ;
239
252
253
+ fit ( 'should not close when pressing escape while an overlay is open' , fakeAsync ( ( ) => {
254
+ const fixture = TestBed . createComponent ( BasicTestApp ) ;
255
+ fixture . detectChanges ( ) ;
256
+
257
+ const testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
258
+ const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ! ;
259
+
260
+ drawer . componentInstance . open ( ) ;
261
+ fixture . detectChanges ( ) ;
262
+ tick ( ) ;
263
+
264
+ expect ( testComponent . closeCount ) . withContext ( 'Expected no close events.' ) . toBe ( 0 ) ;
265
+ expect ( testComponent . closeStartCount ) . withContext ( 'Expected no close start events.' ) . toBe ( 0 ) ;
266
+
267
+ fakeKeyboardDispatcher . _attachedOverlays . push ( null ! ) ;
268
+ const event = createKeyboardEvent ( 'keydown' , ESCAPE ) ;
269
+ dispatchEvent ( drawer . nativeElement , event ) ;
270
+ fixture . detectChanges ( ) ;
271
+ flush ( ) ;
272
+
273
+ expect ( testComponent . closeCount ) . withContext ( 'Expected still no close events.' ) . toBe ( 0 ) ;
274
+ expect ( testComponent . closeStartCount )
275
+ . withContext ( 'Expected still no close start events.' )
276
+ . toBe ( 0 ) ;
277
+ expect ( event . defaultPrevented ) . toBe ( false ) ;
278
+ } ) ) ;
279
+
240
280
it ( 'should fire the open event when open on init' , fakeAsync ( ( ) => {
241
281
const fixture = TestBed . createComponent ( DrawerSetToOpenedTrue ) ;
242
282
0 commit comments