@@ -60,6 +60,7 @@ describe('MdAutocomplete', () => {
60
60
it ( 'should open the panel when the input is focused' , ( ) => {
61
61
expect ( fixture . componentInstance . trigger . panelOpen )
62
62
. toBe ( false , `Expected panel state to start out closed.` ) ;
63
+
63
64
dispatchEvent ( 'focus' , input ) ;
64
65
fixture . detectChanges ( ) ;
65
66
@@ -74,6 +75,7 @@ describe('MdAutocomplete', () => {
74
75
it ( 'should open the panel programmatically' , ( ) => {
75
76
expect ( fixture . componentInstance . trigger . panelOpen )
76
77
. toBe ( false , `Expected panel state to start out closed.` ) ;
78
+
77
79
fixture . componentInstance . trigger . openPanel ( ) ;
78
80
fixture . detectChanges ( ) ;
79
81
@@ -85,22 +87,18 @@ describe('MdAutocomplete', () => {
85
87
. toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
86
88
} ) ;
87
89
88
- it ( 'should close the panel when a click occurs outside it ' , async ( ( ) => {
90
+ it ( 'should close the panel when blurred ' , async ( ( ) => {
89
91
dispatchEvent ( 'focus' , input ) ;
90
92
fixture . detectChanges ( ) ;
91
93
92
94
fixture . whenStable ( ) . then ( ( ) => {
93
- const backdrop =
94
- overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
95
- backdrop . click ( ) ;
95
+ dispatchEvent ( 'blur' , input ) ;
96
96
fixture . detectChanges ( ) ;
97
97
98
- fixture . whenStable ( ) . then ( ( ) => {
99
- expect ( fixture . componentInstance . trigger . panelOpen )
100
- . toBe ( false , `Expected clicking outside the panel to set its state to closed.` ) ;
101
- expect ( overlayContainerElement . textContent )
102
- . toEqual ( '' , `Expected clicking outside the panel to close the panel.` ) ;
103
- } ) ;
98
+ expect ( fixture . componentInstance . trigger . panelOpen )
99
+ . toBe ( false , `Expected clicking outside the panel to set its state to closed.` ) ;
100
+ expect ( overlayContainerElement . textContent )
101
+ . toEqual ( '' , `Expected clicking outside the panel to close the panel.` ) ;
104
102
} ) ;
105
103
} ) ) ;
106
104
@@ -113,12 +111,10 @@ describe('MdAutocomplete', () => {
113
111
option . click ( ) ;
114
112
fixture . detectChanges ( ) ;
115
113
116
- fixture . whenStable ( ) . then ( ( ) => {
117
- expect ( fixture . componentInstance . trigger . panelOpen )
118
- . toBe ( false , `Expected clicking an option to set the panel state to closed.` ) ;
119
- expect ( overlayContainerElement . textContent )
120
- . toEqual ( '' , `Expected clicking an option to close the panel.` ) ;
121
- } ) ;
114
+ expect ( fixture . componentInstance . trigger . panelOpen )
115
+ . toBe ( false , `Expected clicking an option to set the panel state to closed.` ) ;
116
+ expect ( overlayContainerElement . textContent )
117
+ . toEqual ( '' , `Expected clicking an option to close the panel.` ) ;
122
118
} ) ;
123
119
} ) ) ;
124
120
@@ -148,31 +144,26 @@ describe('MdAutocomplete', () => {
148
144
options [ 1 ] . click ( ) ;
149
145
fixture . detectChanges ( ) ;
150
146
151
- fixture . whenStable ( ) . then ( ( ) => {
152
- expect ( fixture . componentInstance . trigger . panelOpen )
153
- . toBe ( false , `Expected clicking a new option to set the panel state to closed.` ) ;
154
- expect ( overlayContainerElement . textContent )
155
- . toEqual ( '' , `Expected clicking a new option to close the panel.` ) ;
156
- } ) ;
147
+ expect ( fixture . componentInstance . trigger . panelOpen )
148
+ . toBe ( false , `Expected clicking a new option to set the panel state to closed.` ) ;
149
+ expect ( overlayContainerElement . textContent )
150
+ . toEqual ( '' , `Expected clicking a new option to close the panel.` ) ;
157
151
} ) ;
158
152
} ) ;
159
153
} ) ) ;
160
154
161
- it ( 'should close the panel programmatically' , async ( ( ) => {
155
+ it ( 'should close the panel programmatically' , ( ) => {
162
156
fixture . componentInstance . trigger . openPanel ( ) ;
163
157
fixture . detectChanges ( ) ;
164
158
165
159
fixture . componentInstance . trigger . closePanel ( ) ;
166
160
fixture . detectChanges ( ) ;
167
161
168
- fixture . whenStable ( ) . then ( ( ) => {
169
- expect ( fixture . componentInstance . trigger . panelOpen )
170
- . toBe ( false , `Expected closing programmatically to set the panel state to closed.` ) ;
171
- expect ( overlayContainerElement . textContent )
172
- . toEqual ( '' , `Expected closing programmatically to close the panel.` ) ;
173
- } ) ;
174
-
175
- } ) ) ;
162
+ expect ( fixture . componentInstance . trigger . panelOpen )
163
+ . toBe ( false , `Expected closing programmatically to set the panel state to closed.` ) ;
164
+ expect ( overlayContainerElement . textContent )
165
+ . toEqual ( '' , `Expected closing programmatically to close the panel.` ) ;
166
+ } ) ;
176
167
177
168
it ( 'should close the panel when the options list is empty' , async ( ( ) => {
178
169
dispatchEvent ( 'focus' , input ) ;
@@ -183,15 +174,13 @@ describe('MdAutocomplete', () => {
183
174
input . value = 'af' ;
184
175
dispatchEvent ( 'input' , input ) ;
185
176
fixture . detectChanges ( ) ;
186
- fixture . whenStable ( ) . then ( ( ) => {
187
- expect ( fixture . componentInstance . trigger . panelOpen )
188
- . toBe ( false , `Expected panel to close when options list is empty.` ) ;
189
- expect ( overlayContainerElement . textContent )
190
- . toEqual ( '' , `Expected panel to close when options list is empty.` ) ;
191
- } ) ;
177
+
178
+ expect ( fixture . componentInstance . trigger . panelOpen )
179
+ . toBe ( false , `Expected panel to close when options list is empty.` ) ;
180
+ expect ( overlayContainerElement . textContent )
181
+ . toEqual ( '' , `Expected panel to close when options list is empty.` ) ;
192
182
} ) ;
193
183
} ) ) ;
194
-
195
184
} ) ;
196
185
197
186
it ( 'should have the correct text direction in RTL' , ( ) => {
@@ -428,7 +417,7 @@ describe('MdAutocomplete', () => {
428
417
fixture . detectChanges ( ) ;
429
418
} ) ;
430
419
431
- it ( 'should should not focus the option when DOWN key is pressed' , async ( ( ) => {
420
+ it ( 'should not focus the option when DOWN key is pressed' , async ( ( ) => {
432
421
fixture . whenStable ( ) . then ( ( ) => {
433
422
spyOn ( fixture . componentInstance . options . first , 'focus' ) ;
434
423
@@ -437,12 +426,26 @@ describe('MdAutocomplete', () => {
437
426
} ) ;
438
427
} ) ) ;
439
428
429
+ it ( 'should not close the panel when DOWN key is pressed' , async ( ( ) => {
430
+ fixture . whenStable ( ) . then ( ( ) => {
431
+ fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
432
+
433
+ expect ( fixture . componentInstance . trigger . panelOpen )
434
+ . toBe ( true , `Expected panel state to stay open when DOWN key is pressed.` ) ;
435
+ expect ( overlayContainerElement . textContent )
436
+ . toContain ( 'Alabama' , `Expected panel to keep displaying when DOWN key is pressed.` ) ;
437
+ expect ( overlayContainerElement . textContent )
438
+ . toContain ( 'California' , `Expected panel to keep displaying when DOWN key is pressed.` ) ;
439
+ } ) ;
440
+ } ) ) ;
441
+
440
442
it ( 'should set the active item to the first option when DOWN key is pressed' , async ( ( ) => {
441
443
fixture . whenStable ( ) . then ( ( ) => {
442
444
const optionEls =
443
445
overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
444
446
445
447
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
448
+
446
449
fixture . whenStable ( ) . then ( ( ) => {
447
450
fixture . detectChanges ( ) ;
448
451
expect ( fixture . componentInstance . trigger . activeOption )
@@ -567,22 +570,20 @@ describe('MdAutocomplete', () => {
567
570
fixture . componentInstance . trigger . _handleKeydown ( ENTER_EVENT ) ;
568
571
fixture . detectChanges ( ) ;
569
572
570
- fixture . whenStable ( ) . then ( ( ) => {
571
- expect ( fixture . componentInstance . trigger . panelOpen )
572
- . toBe ( false , `Expected panel state to read closed after ENTER key.` ) ;
573
- expect ( overlayContainerElement . textContent )
574
- . toEqual ( '' , `Expected panel to close after ENTER key.` ) ;
573
+ expect ( fixture . componentInstance . trigger . panelOpen )
574
+ . toBe ( false , `Expected panel state to read closed after ENTER key.` ) ;
575
+ expect ( overlayContainerElement . textContent )
576
+ . toEqual ( '' , `Expected panel to close after ENTER key.` ) ;
575
577
576
- input . value = 'Alabam' ;
577
- dispatchEvent ( 'input' , input ) ;
578
- fixture . detectChanges ( ) ;
578
+ input . value = 'Alabam' ;
579
+ dispatchEvent ( 'input' , input ) ;
580
+ fixture . detectChanges ( ) ;
579
581
580
- expect ( fixture . componentInstance . trigger . panelOpen )
581
- . toBe ( true , `Expected panel state to read open when typing in input.` ) ;
582
- expect ( overlayContainerElement . textContent )
583
- . toContain ( 'Alabama' , `Expected panel to display when typing in input.` ) ;
582
+ expect ( fixture . componentInstance . trigger . panelOpen )
583
+ . toBe ( true , `Expected panel state to read open when typing in input.` ) ;
584
+ expect ( overlayContainerElement . textContent )
585
+ . toContain ( 'Alabama' , `Expected panel to display when typing in input.` ) ;
584
586
} ) ;
585
- } ) ;
586
587
} ) ) ;
587
588
588
589
it ( 'should scroll to active options below the fold' , async ( ( ) => {
0 commit comments