@@ -46,7 +46,8 @@ describe('MdInputContainer', function () {
4646 MdInputContainerWithValueBinding ,
4747 MdInputContainerWithFormControl ,
4848 MdInputContainerWithStaticPlaceholder ,
49- MdInputContainerMissingMdInputTestController
49+ MdInputContainerMissingMdInputTestController ,
50+ MdInputContainerWithDynamicPlaceholder
5051 ] ,
5152 } ) ;
5253
@@ -404,6 +405,78 @@ describe('MdInputContainer', function () {
404405 const textarea : HTMLTextAreaElement = fixture . nativeElement . querySelector ( 'textarea' ) ;
405406 expect ( textarea ) . not . toBeNull ( ) ;
406407 } ) ;
408+
409+ it ( 'should float when floatingPlaceholder is set to default and text is entered' , ( ) => {
410+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
411+ fixture . detectChanges ( ) ;
412+
413+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
414+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
415+
416+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
417+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
418+
419+ fixture . componentInstance . shouldFloat = null ;
420+ fixture . detectChanges ( ) ;
421+
422+ expect ( labelEl . classList ) . toContain ( 'md-empty' ) ;
423+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
424+
425+ // Update the value of the input.
426+ inputEl . nativeElement . value = 'Text' ;
427+
428+ // Fake behavior of the `(input)` event which should trigger a change detection.
429+ fixture . detectChanges ( ) ;
430+
431+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
432+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
433+ } ) ;
434+
435+ it ( 'should always float the placeholder when floatingPlaceholder is set to true' , ( ) => {
436+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
437+ fixture . detectChanges ( ) ;
438+
439+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
440+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
441+
442+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
443+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
444+
445+ fixture . detectChanges ( ) ;
446+
447+ // Update the value of the input.
448+ inputEl . nativeElement . value = 'Text' ;
449+
450+ // Fake behavior of the `(input)` event which should trigger a change detection.
451+ fixture . detectChanges ( ) ;
452+
453+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
454+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
455+ } ) ;
456+
457+
458+ it ( 'should never float the placeholder when floatingPlaceholder is set to false' , ( ) => {
459+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
460+
461+ fixture . componentInstance . shouldFloat = false ;
462+ fixture . detectChanges ( ) ;
463+
464+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
465+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
466+
467+ expect ( labelEl . classList ) . toContain ( 'md-empty' ) ;
468+ expect ( labelEl . classList ) . not . toContain ( 'md-float' ) ;
469+
470+ // Update the value of the input.
471+ inputEl . nativeElement . value = 'Text' ;
472+
473+ // Fake behavior of the `(input)` event which should trigger a change detection.
474+ fixture . detectChanges ( ) ;
475+
476+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
477+ expect ( labelEl . classList ) . not . toContain ( 'md-float' ) ;
478+ } ) ;
479+
407480} ) ;
408481
409482@Component ( {
@@ -580,6 +653,16 @@ class MdInputContainerWithValueBinding {
580653} )
581654class MdInputContainerWithStaticPlaceholder { }
582655
656+ @Component ( {
657+ template : `
658+ <md-input-container [floatingPlaceholder]="shouldFloat">
659+ <input md-input placeholder="Label">
660+ </md-input-container>`
661+ } )
662+ class MdInputContainerWithDynamicPlaceholder {
663+ shouldFloat : boolean = true ;
664+ }
665+
583666@Component ( {
584667 template : `
585668 <md-input-container>
0 commit comments