@@ -46,7 +46,8 @@ describe('MdInputContainer', function () {
4646 MdInputContainerWithValueBinding ,
4747 MdInputContainerWithFormControl ,
4848 MdInputContainerWithStaticPlaceholder ,
49- MdInputContainerMissingMdInputTestController
49+ MdInputContainerMissingMdInputTestController ,
50+ MdInputContainerWithDynamicPlaceholder
5051 ] ,
5152 } ) ;
5253
@@ -383,6 +384,78 @@ describe('MdInputContainer', function () {
383384 const textarea : HTMLTextAreaElement = fixture . nativeElement . querySelector ( 'textarea' ) ;
384385 expect ( textarea ) . not . toBeNull ( ) ;
385386 } ) ;
387+
388+ it ( 'should float when floatingPlaceholder is set to default and text is entered' , ( ) => {
389+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
390+ fixture . detectChanges ( ) ;
391+
392+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
393+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
394+
395+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
396+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
397+
398+ fixture . componentInstance . shouldFloat = null ;
399+ fixture . detectChanges ( ) ;
400+
401+ expect ( labelEl . classList ) . toContain ( 'md-empty' ) ;
402+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
403+
404+ // Update the value of the input.
405+ inputEl . nativeElement . value = 'Text' ;
406+
407+ // Fake behavior of the `(input)` event which should trigger a change detection.
408+ fixture . detectChanges ( ) ;
409+
410+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
411+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
412+ } ) ;
413+
414+ it ( 'should always float the placeholder when floatingPlaceholder is set to true' , ( ) => {
415+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
416+ fixture . detectChanges ( ) ;
417+
418+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
419+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
420+
421+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
422+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
423+
424+ fixture . detectChanges ( ) ;
425+
426+ // Update the value of the input.
427+ inputEl . nativeElement . value = 'Text' ;
428+
429+ // Fake behavior of the `(input)` event which should trigger a change detection.
430+ fixture . detectChanges ( ) ;
431+
432+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
433+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
434+ } ) ;
435+
436+
437+ it ( 'should never float the placeholder when floatingPlaceholder is set to false' , ( ) => {
438+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
439+
440+ fixture . componentInstance . shouldFloat = false ;
441+ fixture . detectChanges ( ) ;
442+
443+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
444+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
445+
446+ expect ( labelEl . classList ) . toContain ( 'md-empty' ) ;
447+ expect ( labelEl . classList ) . not . toContain ( 'md-float' ) ;
448+
449+ // Update the value of the input.
450+ inputEl . nativeElement . value = 'Text' ;
451+
452+ // Fake behavior of the `(input)` event which should trigger a change detection.
453+ fixture . detectChanges ( ) ;
454+
455+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
456+ expect ( labelEl . classList ) . not . toContain ( 'md-float' ) ;
457+ } ) ;
458+
386459} ) ;
387460
388461@Component ( {
@@ -559,6 +632,16 @@ class MdInputContainerWithValueBinding {
559632} )
560633class MdInputContainerWithStaticPlaceholder { }
561634
635+ @Component ( {
636+ template : `
637+ <md-input-container [floatingPlaceholder]="shouldFloat">
638+ <input md-input placeholder="Label">
639+ </md-input-container>`
640+ } )
641+ class MdInputContainerWithDynamicPlaceholder {
642+ shouldFloat : boolean = true ;
643+ }
644+
562645@Component ( {
563646 template : `
564647 <md-input-container>
0 commit comments