@@ -14,7 +14,7 @@ import {
1414 NativeDateModule ,
1515 SEP ,
1616} from '@angular/material/core' ;
17- import { MatFormFieldModule } from '@angular/material/form-field' ;
17+ import { MatFormFieldModule , MatFormField } from '@angular/material/form-field' ;
1818import { By } from '@angular/platform-browser' ;
1919import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
2020import { MatInputModule } from '../input/index' ;
@@ -98,6 +98,29 @@ describe('MatDatepicker', () => {
9898 . not . toBeNull ( ) ;
9999 } ) ;
100100
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+
101124 it ( 'should open datepicker if opened input is set to true' , ( ) => {
102125 testComponent . opened = true ;
103126 fixture . detectChanges ( ) ;
@@ -137,19 +160,21 @@ describe('MatDatepicker', () => {
137160 expect ( document . querySelector ( '.cdk-overlay-pane' ) ) . not . toBeNull ( ) ;
138161 } ) ;
139162
140- it ( 'close should close popup' , ( ) => {
163+ it ( 'close should close popup' , fakeAsync ( ( ) => {
141164 testComponent . datepicker . open ( ) ;
142165 fixture . detectChanges ( ) ;
166+ flush ( ) ;
143167
144168 let popup = document . querySelector ( '.cdk-overlay-pane' ) ! ;
145169 expect ( popup ) . not . toBeNull ( ) ;
146170 expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . not . toBe ( 0 ) ;
147171
148172 testComponent . datepicker . close ( ) ;
149173 fixture . detectChanges ( ) ;
174+ flush ( ) ;
150175
151176 expect ( parseInt ( getComputedStyle ( popup ) . height as string ) ) . toBe ( 0 ) ;
152- } ) ;
177+ } ) ) ;
153178
154179 it ( 'should close the popup when pressing ESCAPE' , fakeAsync ( ( ) => {
155180 testComponent . datepicker . open ( ) ;
@@ -848,13 +873,13 @@ describe('MatDatepicker', () => {
848873 beforeEach ( fakeAsync ( ( ) => {
849874 fixture = createComponent ( FormFieldDatepicker , [ MatNativeDateModule ] ) ;
850875 fixture . detectChanges ( ) ;
851-
852876 testComponent = fixture . componentInstance ;
853877 } ) ) ;
854878
855879 afterEach ( fakeAsync ( ( ) => {
856880 testComponent . datepicker . close ( ) ;
857881 fixture . detectChanges ( ) ;
882+ flush ( ) ;
858883 } ) ) ;
859884
860885 it ( 'should float the placeholder when an invalid value is entered' , ( ) => {
@@ -865,6 +890,41 @@ describe('MatDatepicker', () => {
865890 expect ( fixture . debugElement . nativeElement . querySelector ( 'mat-form-field' ) . classList )
866891 . toContain ( 'mat-form-field-should-float' ) ;
867892 } ) ;
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+ } ) ) ;
868928 } ) ;
869929
870930 describe ( 'datepicker with min and max dates and validation' , ( ) => {
@@ -1423,6 +1483,7 @@ class DatepickerWithCustomIcon {}
14231483class FormFieldDatepicker {
14241484 @ViewChild ( 'd' ) datepicker : MatDatepicker < Date > ;
14251485 @ViewChild ( MatDatepickerInput ) datepickerInput : MatDatepickerInput < Date > ;
1486+ @ViewChild ( MatFormField ) formField : MatFormField ;
14261487}
14271488
14281489
0 commit comments