@@ -10,12 +10,11 @@ import {Subscription} from 'rxjs/Subscription';
10
10
import { ENTER , DOWN_ARROW , SPACE } from '../core/keyboard/keycodes' ;
11
11
import { MdOption } from '../core/option/option' ;
12
12
import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
13
+ import { MdInputContainer } from '../input/input-container' ;
13
14
14
15
describe ( 'MdAutocomplete' , ( ) => {
15
16
let overlayContainerElement : HTMLElement ;
16
17
let dir : LayoutDirection ;
17
- let fixture : ComponentFixture < SimpleAutocomplete > ;
18
- let input : HTMLInputElement ;
19
18
20
19
beforeEach ( async ( ( ) => {
21
20
dir = 'ltr' ;
@@ -45,14 +44,17 @@ describe('MdAutocomplete', () => {
45
44
TestBed . compileComponents ( ) ;
46
45
} ) ) ;
47
46
48
- beforeEach ( ( ) => {
49
- fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
50
- fixture . detectChanges ( ) ;
47
+ describe ( 'panel toggling' , ( ) => {
48
+ let fixture : ComponentFixture < SimpleAutocomplete > ;
49
+ let input : HTMLInputElement ;
51
50
52
- input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
53
- } ) ;
51
+ beforeEach ( ( ) => {
52
+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
53
+ fixture . detectChanges ( ) ;
54
+
55
+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
56
+ } ) ;
54
57
55
- describe ( 'panel toggling' , ( ) => {
56
58
it ( 'should open the panel when the input is focused' , ( ) => {
57
59
expect ( fixture . componentInstance . trigger . panelOpen ) . toBe ( false ) ;
58
60
dispatchEvent ( 'focus' , input ) ;
@@ -171,23 +173,52 @@ describe('MdAutocomplete', () => {
171
173
} ) ;
172
174
} ) ) ;
173
175
176
+ it ( 'should keep the label floating until the panel closes' , ( ) => {
177
+ fixture . componentInstance . trigger . openPanel ( ) ;
178
+ fixture . detectChanges ( ) ;
179
+
180
+ dispatchEvent ( 'blur' , input ) ;
181
+ fixture . detectChanges ( ) ;
182
+
183
+ expect ( fixture . componentInstance . inputContainer . floatPlaceholder )
184
+ . toEqual ( 'always' , 'Expected placeholder to keep floating on blur.' ) ;
185
+
186
+ const backdrop =
187
+ overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
188
+ backdrop . click ( ) ;
189
+ fixture . detectChanges ( ) ;
190
+
191
+ expect ( fixture . componentInstance . inputContainer . floatPlaceholder )
192
+ . toEqual ( 'auto' , 'Expected placeholder to return to auto state after panel closes.' ) ;
193
+ } ) ;
194
+
174
195
} ) ;
175
196
176
197
it ( 'should have the correct text direction in RTL' , ( ) => {
177
198
dir = 'rtl' ;
178
199
179
- const fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
180
- fixture . detectChanges ( ) ;
200
+ const rtlFixture = TestBed . createComponent ( SimpleAutocomplete ) ;
201
+ rtlFixture . detectChanges ( ) ;
181
202
182
- fixture . componentInstance . trigger . openPanel ( ) ;
183
- fixture . detectChanges ( ) ;
203
+ rtlFixture . componentInstance . trigger . openPanel ( ) ;
204
+ rtlFixture . detectChanges ( ) ;
184
205
185
206
const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
186
207
expect ( overlayPane . getAttribute ( 'dir' ) ) . toEqual ( 'rtl' ) ;
187
208
188
209
} ) ;
189
210
190
211
describe ( 'forms integration' , ( ) => {
212
+ let fixture : ComponentFixture < SimpleAutocomplete > ;
213
+ let input : HTMLInputElement ;
214
+
215
+
216
+ beforeEach ( ( ) => {
217
+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
218
+ fixture . detectChanges ( ) ;
219
+
220
+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
221
+ } ) ;
191
222
192
223
it ( 'should fill the text field when an option is selected' , ( ) => {
193
224
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -228,7 +259,19 @@ describe('MdAutocomplete', () => {
228
259
. toBe ( false , `Expected control to stay pristine if value is set programmatically.` ) ;
229
260
} ) ;
230
261
262
+ } ) ;
263
+
231
264
describe ( 'aria' , ( ) => {
265
+ let fixture : ComponentFixture < SimpleAutocomplete > ;
266
+ let input : HTMLInputElement ;
267
+
268
+
269
+ beforeEach ( ( ) => {
270
+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
271
+ fixture . detectChanges ( ) ;
272
+
273
+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
274
+ } ) ;
232
275
233
276
it ( 'should set role of input to combobox' , ( ) => {
234
277
expect ( input . getAttribute ( 'role' ) )
@@ -307,10 +350,16 @@ describe('MdAutocomplete', () => {
307
350
} ) ;
308
351
309
352
describe ( 'keyboard events' , ( ) => {
353
+ let fixture : ComponentFixture < SimpleAutocomplete > ;
354
+ let input : HTMLInputElement ;
310
355
let DOWN_ARROW_EVENT : KeyboardEvent ;
311
356
let ENTER_EVENT : KeyboardEvent ;
312
357
313
358
beforeEach ( ( ) => {
359
+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
360
+ fixture . detectChanges ( ) ;
361
+
362
+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
314
363
DOWN_ARROW_EVENT = new FakeKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
315
364
ENTER_EVENT = new FakeKeyboardEvent ( ENTER ) as KeyboardEvent ;
316
365
} ) ;
@@ -462,9 +511,10 @@ describe('MdAutocomplete', () => {
462
511
expect ( scrollContainer . scrollTop ) . toEqual ( 0 , `Expected panel not to scroll.` ) ;
463
512
464
513
// These down arrows will set the 6th option active, below the fold.
465
- [ 1 , 2 , 3 , 4 , 5 ] . forEach ( ( ) => {
514
+ [ 1 , 2 , 3 , 4 , 5 ] . forEach ( ( ) => {
466
515
fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
467
516
} ) ;
517
+
468
518
fixture . detectChanges ( ) ;
469
519
470
520
// Expect option bottom minus the panel height (288 - 256 = 32)
@@ -474,6 +524,15 @@ describe('MdAutocomplete', () => {
474
524
} ) ;
475
525
476
526
describe ( 'Fallback positions' , ( ) => {
527
+ let fixture : ComponentFixture < SimpleAutocomplete > ;
528
+ let input : HTMLInputElement ;
529
+
530
+ beforeEach ( ( ) => {
531
+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
532
+ fixture . detectChanges ( ) ;
533
+
534
+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
535
+ } ) ;
477
536
478
537
it ( 'should use below positioning by default' , ( ) => {
479
538
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -532,6 +591,7 @@ class SimpleAutocomplete implements OnDestroy {
532
591
valueSub : Subscription ;
533
592
534
593
@ViewChild ( MdAutocompleteTrigger ) trigger : MdAutocompleteTrigger ;
594
+ @ViewChild ( MdInputContainer ) inputContainer : MdInputContainer ;
535
595
@ViewChildren ( MdOption ) options : QueryList < MdOption > ;
536
596
537
597
states = [
0 commit comments