1
- import { async , TestBed , inject , ComponentFixture } from '@angular/core/testing' ;
1
+ import { async , ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
2
2
import { Component , ViewChild } from '@angular/core' ;
3
3
import {
4
- FormsModule ,
5
- ReactiveFormsModule ,
6
4
FormControl ,
7
- NgForm ,
8
- Validators ,
9
- FormGroupDirective ,
10
5
FormGroup ,
6
+ FormGroupDirective ,
7
+ FormsModule ,
8
+ NgForm ,
9
+ ReactiveFormsModule ,
10
+ Validators
11
11
} from '@angular/forms' ;
12
12
import { By } from '@angular/platform-browser' ;
13
13
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -18,52 +18,53 @@ import {PlatformModule} from '../core/platform/index';
18
18
import { wrappedErrorMessage } from '../core/testing/wrapped-error-message' ;
19
19
import { dispatchFakeEvent } from '../core/testing/dispatch-events' ;
20
20
import {
21
+ MdInputContainerDuplicatedHintError ,
21
22
MdInputContainerMissingMdInputError ,
22
- MdInputContainerPlaceholderConflictError ,
23
- MdInputContainerDuplicatedHintError
23
+ MdInputContainerPlaceholderConflictError
24
24
} from './input-container-errors' ;
25
25
26
26
27
27
describe ( 'MdInputContainer' , function ( ) {
28
28
beforeEach ( async ( ( ) => {
29
29
TestBed . configureTestingModule ( {
30
30
imports : [
31
- MdInputModule . forRoot ( ) ,
32
- PlatformModule . forRoot ( ) ,
33
31
FormsModule ,
32
+ MdInputModule ,
33
+ NoopAnimationsModule ,
34
+ PlatformModule ,
34
35
ReactiveFormsModule ,
35
- NoopAnimationsModule
36
36
] ,
37
37
declarations : [
38
- MdInputContainerPlaceholderRequiredTestComponent ,
39
- MdInputContainerPlaceholderElementTestComponent ,
40
- MdInputContainerPlaceholderAttrTestComponent ,
38
+ MdInputContainerBaseTestController ,
39
+ MdInputContainerDateTestController ,
41
40
MdInputContainerHintLabel2TestController ,
42
41
MdInputContainerHintLabelTestController ,
43
- MdInputContainerInvalidTypeTestController ,
44
- MdInputContainerInvalidPlaceholderTestController ,
45
42
MdInputContainerInvalidHint2TestController ,
46
43
MdInputContainerInvalidHintTestController ,
47
- MdInputContainerBaseTestController ,
48
- MdInputContainerWithId ,
49
- MdInputContainerDateTestController ,
50
- MdInputContainerTextTestController ,
51
- MdInputContainerPasswordTestController ,
44
+ MdInputContainerInvalidPlaceholderTestController ,
45
+ MdInputContainerInvalidTypeTestController ,
46
+ MdInputContainerMissingMdInputTestController ,
47
+ MdInputContainerMultipleHintMixedTestController ,
48
+ MdInputContainerMultipleHintTestController ,
52
49
MdInputContainerNumberTestController ,
53
- MdInputContainerZeroTestController ,
54
- MdTextareaWithBindings ,
50
+ MdInputContainerPasswordTestController ,
51
+ MdInputContainerPlaceholderAttrTestComponent ,
52
+ MdInputContainerPlaceholderElementTestComponent ,
53
+ MdInputContainerPlaceholderRequiredTestComponent ,
54
+ MdInputContainerTextTestController ,
55
55
MdInputContainerWithDisabled ,
56
+ MdInputContainerWithDynamicPlaceholder ,
57
+ MdInputContainerWithFormControl ,
58
+ MdInputContainerWithFormErrorMessages ,
59
+ MdInputContainerWithFormGroupErrorMessages ,
60
+ MdInputContainerWithId ,
61
+ MdInputContainerWithPrefixAndSuffix ,
56
62
MdInputContainerWithRequired ,
63
+ MdInputContainerWithStaticPlaceholder ,
57
64
MdInputContainerWithType ,
58
65
MdInputContainerWithValueBinding ,
59
- MdInputContainerWithFormControl ,
60
- MdInputContainerWithStaticPlaceholder ,
61
- MdInputContainerMissingMdInputTestController ,
62
- MdInputContainerMultipleHintTestController ,
63
- MdInputContainerMultipleHintMixedTestController ,
64
- MdInputContainerWithDynamicPlaceholder ,
65
- MdInputContainerWithFormErrorMessages ,
66
- MdInputContainerWithFormGroupErrorMessages
66
+ MdInputContainerZeroTestController ,
67
+ MdTextareaWithBindings ,
67
68
] ,
68
69
} ) ;
69
70
@@ -685,6 +686,29 @@ describe('MdInputContainer', function () {
685
686
686
687
} ) ;
687
688
689
+ it ( 'should not have prefix and suffix elements when none are specified' , ( ) => {
690
+ let fixture = TestBed . createComponent ( MdInputContainerWithId ) ;
691
+ fixture . detectChanges ( ) ;
692
+
693
+ let prefixEl = fixture . debugElement . query ( By . css ( '.mat-input-prefix' ) ) ;
694
+ let suffixEl = fixture . debugElement . query ( By . css ( '.mat-input-suffix' ) ) ;
695
+
696
+ expect ( prefixEl ) . toBeNull ( ) ;
697
+ expect ( suffixEl ) . toBeNull ( ) ;
698
+ } ) ;
699
+
700
+ it ( 'should add prefix and suffix elements when specified' , ( ) => {
701
+ let fixture = TestBed . createComponent ( MdInputContainerWithPrefixAndSuffix ) ;
702
+ fixture . detectChanges ( ) ;
703
+
704
+ let prefixEl = fixture . debugElement . query ( By . css ( '.mat-input-prefix' ) ) ;
705
+ let suffixEl = fixture . debugElement . query ( By . css ( '.mat-input-suffix' ) ) ;
706
+
707
+ expect ( prefixEl ) . not . toBeNull ( ) ;
708
+ expect ( suffixEl ) . not . toBeNull ( ) ;
709
+ expect ( prefixEl . nativeElement . innerText . trim ( ) ) . toEqual ( 'Prefix' ) ;
710
+ expect ( suffixEl . nativeElement . innerText . trim ( ) ) . toEqual ( 'Suffix' ) ;
711
+ } ) ;
688
712
} ) ;
689
713
690
714
@Component ( {
@@ -927,7 +951,6 @@ class MdInputContainerWithFormErrorMessages {
927
951
renderError = true ;
928
952
}
929
953
930
-
931
954
@Component ( {
932
955
template : `
933
956
<form [formGroup]="formGroup" novalidate>
@@ -945,3 +968,14 @@ class MdInputContainerWithFormGroupErrorMessages {
945
968
name : new FormControl ( '' , Validators . required )
946
969
} ) ;
947
970
}
971
+
972
+ @Component ( {
973
+ template : `
974
+ <md-input-container>
975
+ <div mdPrefix>Prefix</div>
976
+ <input mdInput>
977
+ <div mdSuffix>Suffix</div>
978
+ </md-input-container>
979
+ `
980
+ } )
981
+ class MdInputContainerWithPrefixAndSuffix { }
0 commit comments