@@ -62,34 +62,13 @@ import {
62
62
/** The debounce interval when typing letters to select an option. */
63
63
const LETTER_KEY_DEBOUNCE_INTERVAL = 200 ;
64
64
65
- const platform = new Platform ( ) ;
66
-
67
-
68
65
describe ( 'MatSelect' , ( ) => {
69
66
let overlayContainer : OverlayContainer ;
70
67
let overlayContainerElement : HTMLElement ;
71
68
let dir : { value : 'ltr' | 'rtl' } ;
72
69
let scrolledSubject = new Subject ( ) ;
73
70
let viewportRuler : ViewportRuler ;
74
-
75
- // Providers used for all mat-select tests
76
- const commonProviders = [
77
- { provide : Directionality , useFactory : ( ) => dir = { value : 'ltr' } } ,
78
- {
79
- provide : ScrollDispatcher , useFactory : ( ) => ( {
80
- scrolled : ( ) => scrolledSubject . asObservable ( ) ,
81
- } ) ,
82
- } ,
83
- ] ;
84
-
85
- // NgModule imports used for all mat-select tests.
86
- const commonModuleImports = [
87
- MatFormFieldModule ,
88
- MatSelectModule ,
89
- ReactiveFormsModule ,
90
- FormsModule ,
91
- NoopAnimationsModule ,
92
- ] ;
71
+ let platform : Platform ;
93
72
94
73
/**
95
74
* Configures the test module for MatSelect with the given declarations. This is broken out so
@@ -99,14 +78,28 @@ describe('MatSelect', () => {
99
78
*/
100
79
function configureMatSelectTestingModule ( declarations ) {
101
80
TestBed . configureTestingModule ( {
102
- imports : commonModuleImports ,
81
+ imports : [
82
+ MatFormFieldModule ,
83
+ MatSelectModule ,
84
+ ReactiveFormsModule ,
85
+ FormsModule ,
86
+ NoopAnimationsModule ,
87
+ ] ,
103
88
declarations : declarations ,
104
- providers : commonProviders ,
89
+ providers : [
90
+ { provide : Directionality , useFactory : ( ) => dir = { value : 'ltr' } } ,
91
+ {
92
+ provide : ScrollDispatcher , useFactory : ( ) => ( {
93
+ scrolled : ( ) => scrolledSubject . asObservable ( ) ,
94
+ } ) ,
95
+ } ,
96
+ ] ,
105
97
} ) . compileComponents ( ) ;
106
98
107
- inject ( [ OverlayContainer ] , ( oc : OverlayContainer ) => {
99
+ inject ( [ OverlayContainer , Platform ] , ( oc : OverlayContainer , p : Platform ) => {
108
100
overlayContainer = oc ;
109
101
overlayContainerElement = oc . getContainerElement ( ) ;
102
+ platform = p ;
110
103
} ) ( ) ;
111
104
}
112
105
@@ -283,6 +276,40 @@ describe('MatSelect', () => {
283
276
expect ( formControl . value ) . toBeFalsy ( 'Expected value not to have changed.' ) ;
284
277
} ) ) ;
285
278
279
+ it ( 'should should close when pressing ALT + DOWN_ARROW' , fakeAsync ( ( ) => {
280
+ const { select : selectInstance } = fixture . componentInstance ;
281
+
282
+ selectInstance . open ( ) ;
283
+ fixture . detectChanges ( ) ;
284
+
285
+ expect ( selectInstance . panelOpen ) . toBe ( true , 'Expected select to be open.' ) ;
286
+
287
+ const event = createKeyboardEvent ( 'keydown' , DOWN_ARROW ) ;
288
+ Object . defineProperty ( event , 'altKey' , { get : ( ) => true } ) ;
289
+
290
+ dispatchEvent ( select , event ) ;
291
+
292
+ expect ( selectInstance . panelOpen ) . toBe ( false , 'Expected select to be closed.' ) ;
293
+ expect ( event . defaultPrevented ) . toBe ( true , 'Expected default action to be prevented.' ) ;
294
+ } ) ) ;
295
+
296
+ it ( 'should should close when pressing ALT + UP_ARROW' , fakeAsync ( ( ) => {
297
+ const { select : selectInstance } = fixture . componentInstance ;
298
+
299
+ selectInstance . open ( ) ;
300
+ fixture . detectChanges ( ) ;
301
+
302
+ expect ( selectInstance . panelOpen ) . toBe ( true , 'Expected select to be open.' ) ;
303
+
304
+ const event = createKeyboardEvent ( 'keydown' , UP_ARROW ) ;
305
+ Object . defineProperty ( event , 'altKey' , { get : ( ) => true } ) ;
306
+
307
+ dispatchEvent ( select , event ) ;
308
+
309
+ expect ( selectInstance . panelOpen ) . toBe ( false , 'Expected select to be closed.' ) ;
310
+ expect ( event . defaultPrevented ) . toBe ( true , 'Expected default action to be prevented.' ) ;
311
+ } ) ) ;
312
+
286
313
it ( 'should be able to select options by typing on a closed select' , fakeAsync ( ( ) => {
287
314
const formControl = fixture . componentInstance . control ;
288
315
const options = fixture . componentInstance . options . toArray ( ) ;
0 commit comments