@@ -21,7 +21,7 @@ describe('md-datepicker', function() {
21
21
'ng-disabled="isDisabled">' +
22
22
'</md-datepicker>' ;
23
23
24
- beforeEach ( module ( 'material.components.datepicker' , 'ngAnimateMock' ) ) ;
24
+ beforeEach ( module ( 'material.components.datepicker' , 'material.components.input' , ' ngAnimateMock') ) ;
25
25
26
26
beforeEach ( inject ( function ( $rootScope , $injector ) {
27
27
$compile = $injector . get ( '$compile' ) ;
@@ -115,17 +115,6 @@ describe('md-datepicker', function() {
115
115
} ) . not . toThrow ( ) ;
116
116
} ) ;
117
117
118
- it ( 'should work inside of md-input-container' , function ( ) {
119
- var template =
120
- '<md-input-container>' +
121
- '<md-datepicker ng-model="myDate"></md-datepicker>' +
122
- '</md-input-container>' ;
123
-
124
- expect ( function ( ) {
125
- $compile ( template ) ( pageScope ) ;
126
- } ) . not . toThrow ( ) ;
127
- } ) ;
128
-
129
118
describe ( 'ngMessages support' , function ( ) {
130
119
it ( 'should set the `required` $error flag' , function ( ) {
131
120
pageScope . isRequired = true ;
@@ -623,4 +612,68 @@ describe('md-datepicker', function() {
623
612
expect ( element . querySelector ( triangleSelector ) ) . toBeNull ( ) ;
624
613
} ) ;
625
614
} ) ;
615
+
616
+ describe ( 'md-input-container integration' , function ( ) {
617
+ var element ;
618
+
619
+ it ( 'should register the element with the mdInputContainer controller' , function ( ) {
620
+ compileElement ( ) ;
621
+
622
+ var inputContainer = element . controller ( 'mdInputContainer' ) ;
623
+
624
+ expect ( inputContainer . input [ 0 ] ) . toBe ( element [ 0 ] . querySelector ( 'md-datepicker' ) ) ;
625
+ expect ( inputContainer . element ) . toHaveClass ( '_md-datepicker-floating-label' ) ;
626
+ } ) ;
627
+
628
+ it ( 'should notify the input container that the element has a placeholder' , function ( ) {
629
+ compileElement ( 'md-placeholder="Enter a date"' ) ;
630
+ expect ( element ) . toHaveClass ( 'md-input-has-placeholder' ) ;
631
+ } ) ;
632
+
633
+ it ( 'should add the asterisk if the element is required' , function ( ) {
634
+ compileElement ( 'ng-required="isRequired"' ) ;
635
+ var label = element . find ( 'label' ) ;
636
+
637
+ expect ( label ) . not . toHaveClass ( 'md-required' ) ;
638
+ pageScope . $apply ( 'isRequired = true' ) ;
639
+ expect ( label ) . toHaveClass ( 'md-required' ) ;
640
+ } ) ;
641
+
642
+ it ( 'should not add the asterisk if the element has md-no-asterisk' , function ( ) {
643
+ compileElement ( 'required md-no-asterisk' ) ;
644
+ expect ( element . find ( 'label' ) ) . not . toHaveClass ( 'md-required' ) ;
645
+ } ) ;
646
+
647
+ it ( 'should pass the error state to the input container' , inject ( function ( $material ) {
648
+ compileElement ( 'required' ) ;
649
+
650
+ var ngModelCtrl = element . find ( 'md-datepicker' ) . controller ( 'ngModel' ) ;
651
+ var invalidClass = 'md-input-invalid' ;
652
+
653
+ expect ( ngModelCtrl . $valid ) . toBe ( true ) ;
654
+ expect ( element ) . not . toHaveClass ( invalidClass ) ;
655
+
656
+ ngModelCtrl . $setViewValue ( null ) ;
657
+ ngModelCtrl . $setTouched ( true ) ;
658
+ $material . flushOutstandingAnimations ( ) ;
659
+
660
+ expect ( ngModelCtrl . $valid ) . toBe ( false ) ;
661
+ expect ( element ) . toHaveClass ( invalidClass ) ;
662
+ } ) ) ;
663
+
664
+ afterEach ( function ( ) {
665
+ element . remove ( ) ;
666
+ } ) ;
667
+
668
+ function compileElement ( attrs ) {
669
+ var template =
670
+ '<md-input-container>' +
671
+ '<label>Enter a date</label>' +
672
+ '<md-datepicker ng-model="myDate" ' + attrs + '></md-datepicker>' +
673
+ '</md-input-container>' ;
674
+
675
+ element = $compile ( template ) ( pageScope ) ;
676
+ pageScope . $digest ( ) ;
677
+ }
678
+ } ) ;
626
679
} ) ;
0 commit comments