@@ -14,7 +14,7 @@ import {
14
14
NativeDateModule ,
15
15
SEP ,
16
16
} from '@angular/material/core' ;
17
- import { MatFormFieldModule } from '@angular/material/form-field' ;
17
+ import { MatFormFieldModule , MatFormField } from '@angular/material/form-field' ;
18
18
import { By } from '@angular/platform-browser' ;
19
19
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
20
20
import { MatInputModule } from '../input/index' ;
@@ -98,6 +98,29 @@ describe('MatDatepicker', () => {
98
98
. not . toBeNull ( ) ;
99
99
} ) ;
100
100
101
+ it ( 'should pass the datepicker theme color to the overlay' , fakeAsync ( ( ) => {
102
+ testComponent . datepicker . color = 'primary' ;
103
+ testComponent . datepicker . open ( ) ;
104
+ fixture . detectChanges ( ) ;
105
+
106
+ let contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
107
+
108
+ expect ( contentEl . classList ) . toContain ( 'mat-primary' ) ;
109
+
110
+ testComponent . datepicker . close ( ) ;
111
+ fixture . detectChanges ( ) ;
112
+ flush ( ) ;
113
+
114
+ testComponent . datepicker . color = 'warn' ;
115
+ testComponent . datepicker . open ( ) ;
116
+
117
+ contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
118
+ fixture . detectChanges ( ) ;
119
+
120
+ expect ( contentEl . classList ) . toContain ( 'mat-warn' ) ;
121
+ expect ( contentEl . classList ) . not . toContain ( 'mat-primary' ) ;
122
+ } ) ) ;
123
+
101
124
it ( 'should open datepicker if opened input is set to true' , ( ) => {
102
125
testComponent . opened = true ;
103
126
fixture . detectChanges ( ) ;
@@ -137,19 +160,21 @@ describe('MatDatepicker', () => {
137
160
expect ( document . querySelector ( '.cdk-overlay-pane' ) ) . not . toBeNull ( ) ;
138
161
} ) ;
139
162
140
- it ( 'close should close popup' , ( ) => {
163
+ it ( 'close should close popup' , fakeAsync ( ( ) => {
141
164
testComponent . datepicker . open ( ) ;
142
165
fixture . detectChanges ( ) ;
166
+ flush ( ) ;
143
167
144
168
let popup = document . querySelector ( '.cdk-overlay-pane' ) ! ;
145
169
expect ( popup ) . not . toBeNull ( ) ;
146
170
expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . not . toBe ( 0 ) ;
147
171
148
172
testComponent . datepicker . close ( ) ;
149
173
fixture . detectChanges ( ) ;
174
+ flush ( ) ;
150
175
151
176
expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . toBe ( 0 ) ;
152
- } ) ;
177
+ } ) ) ;
153
178
154
179
it ( 'should close the popup when pressing ESCAPE' , fakeAsync ( ( ) => {
155
180
testComponent . datepicker . open ( ) ;
@@ -848,13 +873,13 @@ describe('MatDatepicker', () => {
848
873
beforeEach ( fakeAsync ( ( ) => {
849
874
fixture = createComponent ( FormFieldDatepicker , [ MatNativeDateModule ] ) ;
850
875
fixture . detectChanges ( ) ;
851
-
852
876
testComponent = fixture . componentInstance ;
853
877
} ) ) ;
854
878
855
879
afterEach ( fakeAsync ( ( ) => {
856
880
testComponent . datepicker . close ( ) ;
857
881
fixture . detectChanges ( ) ;
882
+ flush ( ) ;
858
883
} ) ) ;
859
884
860
885
it ( 'should float the placeholder when an invalid value is entered' , ( ) => {
@@ -865,6 +890,41 @@ describe('MatDatepicker', () => {
865
890
expect ( fixture . debugElement . nativeElement . querySelector ( 'mat-form-field' ) . classList )
866
891
. toContain ( 'mat-form-field-should-float' ) ;
867
892
} ) ;
893
+
894
+ it ( 'should pass the form field theme color to the overlay' , fakeAsync ( ( ) => {
895
+ testComponent . formField . color = 'primary' ;
896
+ testComponent . datepicker . open ( ) ;
897
+ fixture . detectChanges ( ) ;
898
+
899
+ let contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
900
+
901
+ expect ( contentEl . classList ) . toContain ( 'mat-primary' ) ;
902
+
903
+ testComponent . datepicker . close ( ) ;
904
+ fixture . detectChanges ( ) ;
905
+ flush ( ) ;
906
+
907
+ testComponent . formField . color = 'warn' ;
908
+ testComponent . datepicker . open ( ) ;
909
+
910
+ contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
911
+ fixture . detectChanges ( ) ;
912
+
913
+ expect ( contentEl . classList ) . toContain ( 'mat-warn' ) ;
914
+ expect ( contentEl . classList ) . not . toContain ( 'mat-primary' ) ;
915
+ } ) ) ;
916
+
917
+ it ( 'should prefer the datepicker color over the form field one' , fakeAsync ( ( ) => {
918
+ testComponent . datepicker . color = 'accent' ;
919
+ testComponent . formField . color = 'warn' ;
920
+ testComponent . datepicker . open ( ) ;
921
+ fixture . detectChanges ( ) ;
922
+
923
+ const contentEl = document . querySelector ( '.mat-datepicker-content' ) ! ;
924
+
925
+ expect ( contentEl . classList ) . toContain ( 'mat-accent' ) ;
926
+ expect ( contentEl . classList ) . not . toContain ( 'mat-warn' ) ;
927
+ } ) ) ;
868
928
} ) ;
869
929
870
930
describe ( 'datepicker with min and max dates and validation' , ( ) => {
@@ -1423,6 +1483,7 @@ class DatepickerWithCustomIcon {}
1423
1483
class FormFieldDatepicker {
1424
1484
@ViewChild ( 'd' ) datepicker : MatDatepicker < Date > ;
1425
1485
@ViewChild ( MatDatepickerInput ) datepickerInput : MatDatepickerInput < Date > ;
1486
+ @ViewChild ( MatFormField ) formField : MatFormField ;
1426
1487
}
1427
1488
1428
1489
0 commit comments