@@ -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' , ( ) => {
@@ -443,6 +432,7 @@ describe('MdAutocomplete', () => {
443
432
overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
444
433
445
434
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
435
+
446
436
fixture . whenStable ( ) . then ( ( ) => {
447
437
fixture . detectChanges ( ) ;
448
438
expect ( fixture . componentInstance . trigger . activeOption )
@@ -567,22 +557,20 @@ describe('MdAutocomplete', () => {
567
557
fixture . componentInstance . trigger . _handleKeydown ( ENTER_EVENT ) ;
568
558
fixture . detectChanges ( ) ;
569
559
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.` ) ;
560
+ expect ( fixture . componentInstance . trigger . panelOpen )
561
+ . toBe ( false , `Expected panel state to read closed after ENTER key.` ) ;
562
+ expect ( overlayContainerElement . textContent )
563
+ . toEqual ( '' , `Expected panel to close after ENTER key.` ) ;
575
564
576
- input . value = 'Alabam' ;
577
- dispatchEvent ( 'input' , input ) ;
578
- fixture . detectChanges ( ) ;
565
+ input . value = 'Alabam' ;
566
+ dispatchEvent ( 'input' , input ) ;
567
+ fixture . detectChanges ( ) ;
579
568
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.` ) ;
569
+ expect ( fixture . componentInstance . trigger . panelOpen )
570
+ . toBe ( true , `Expected panel state to read open when typing in input.` ) ;
571
+ expect ( overlayContainerElement . textContent )
572
+ . toContain ( 'Alabama' , `Expected panel to display when typing in input.` ) ;
584
573
} ) ;
585
- } ) ;
586
574
} ) ) ;
587
575
588
576
it ( 'should scroll to active options below the fold' , async ( ( ) => {
0 commit comments