@@ -10,12 +10,11 @@ import {Subscription} from 'rxjs/Subscription';
1010import { ENTER , DOWN_ARROW , SPACE } from '../core/keyboard/keycodes' ;
1111import { MdOption } from '../core/option/option' ;
1212import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
13+ import { MdInputContainer } from '../input/input-container' ;
1314
1415describe ( 'MdAutocomplete' , ( ) => {
1516 let overlayContainerElement : HTMLElement ;
1617 let dir : LayoutDirection ;
17- let fixture : ComponentFixture < SimpleAutocomplete > ;
18- let input : HTMLInputElement ;
1918
2019 beforeEach ( async ( ( ) => {
2120 dir = 'ltr' ;
@@ -45,14 +44,17 @@ describe('MdAutocomplete', () => {
4544 TestBed . compileComponents ( ) ;
4645 } ) ) ;
4746
48- beforeEach ( ( ) => {
49- fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
50- fixture . detectChanges ( ) ;
47+ describe ( 'panel toggling' , ( ) => {
48+ let fixture : ComponentFixture < SimpleAutocomplete > ;
49+ let input : HTMLInputElement ;
5150
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+ } ) ;
5457
55- describe ( 'panel toggling' , ( ) => {
5658 it ( 'should open the panel when the input is focused' , ( ) => {
5759 expect ( fixture . componentInstance . trigger . panelOpen ) . toBe ( false ) ;
5860 dispatchEvent ( 'focus' , input ) ;
@@ -171,23 +173,52 @@ describe('MdAutocomplete', () => {
171173 } ) ;
172174 } ) ) ;
173175
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+
174195 } ) ;
175196
176197 it ( 'should have the correct text direction in RTL' , ( ) => {
177198 dir = 'rtl' ;
178199
179- const fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
180- fixture . detectChanges ( ) ;
200+ const rtlFixture = TestBed . createComponent ( SimpleAutocomplete ) ;
201+ rtlFixture . detectChanges ( ) ;
181202
182- fixture . componentInstance . trigger . openPanel ( ) ;
183- fixture . detectChanges ( ) ;
203+ rtlFixture . componentInstance . trigger . openPanel ( ) ;
204+ rtlFixture . detectChanges ( ) ;
184205
185206 const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
186207 expect ( overlayPane . getAttribute ( 'dir' ) ) . toEqual ( 'rtl' ) ;
187208
188209 } ) ;
189210
190211 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+ } ) ;
191222
192223 it ( 'should fill the text field when an option is selected' , ( ) => {
193224 fixture . componentInstance . trigger . openPanel ( ) ;
@@ -228,7 +259,19 @@ describe('MdAutocomplete', () => {
228259 . toBe ( false , `Expected control to stay pristine if value is set programmatically.` ) ;
229260 } ) ;
230261
262+ } ) ;
263+
231264 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+ } ) ;
232275
233276 it ( 'should set role of input to combobox' , ( ) => {
234277 expect ( input . getAttribute ( 'role' ) )
@@ -307,10 +350,16 @@ describe('MdAutocomplete', () => {
307350 } ) ;
308351
309352 describe ( 'keyboard events' , ( ) => {
353+ let fixture : ComponentFixture < SimpleAutocomplete > ;
354+ let input : HTMLInputElement ;
310355 let DOWN_ARROW_EVENT : KeyboardEvent ;
311356 let ENTER_EVENT : KeyboardEvent ;
312357
313358 beforeEach ( ( ) => {
359+ fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
360+ fixture . detectChanges ( ) ;
361+
362+ input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
314363 DOWN_ARROW_EVENT = new FakeKeyboardEvent ( DOWN_ARROW ) as KeyboardEvent ;
315364 ENTER_EVENT = new FakeKeyboardEvent ( ENTER ) as KeyboardEvent ;
316365 } ) ;
@@ -462,9 +511,10 @@ describe('MdAutocomplete', () => {
462511 expect ( scrollContainer . scrollTop ) . toEqual ( 0 , `Expected panel not to scroll.` ) ;
463512
464513 // 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 ( ( ) => {
466515 fixture . componentInstance . trigger . _handleKeydown ( DOWN_ARROW_EVENT ) ;
467516 } ) ;
517+
468518 fixture . detectChanges ( ) ;
469519
470520 // Expect option bottom minus the panel height (288 - 256 = 32)
@@ -474,6 +524,15 @@ describe('MdAutocomplete', () => {
474524 } ) ;
475525
476526 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+ } ) ;
477536
478537 it ( 'should use below positioning by default' , ( ) => {
479538 fixture . componentInstance . trigger . openPanel ( ) ;
@@ -532,6 +591,7 @@ class SimpleAutocomplete implements OnDestroy {
532591 valueSub : Subscription ;
533592
534593 @ViewChild ( MdAutocompleteTrigger ) trigger : MdAutocompleteTrigger ;
594+ @ViewChild ( MdInputContainer ) inputContainer : MdInputContainer ;
535595 @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
536596
537597 states = [
0 commit comments