11import { Component , ElementRef , Type , ViewChild } from '@angular/core' ;
2- import { ComponentFixture , TestBed , flush , fakeAsync } from '@angular/core/testing' ;
2+ import { ComponentFixture , TestBed , flush , fakeAsync , tick } from '@angular/core/testing' ;
33import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
44import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
55import { MatNativeDateModule } from '@angular/material/core' ;
@@ -28,37 +28,42 @@ describe('MatDatepickerActions', () => {
2828 return TestBed . createComponent ( component ) ;
2929 }
3030
31- it ( 'should render the actions inside calendar panel in popup mode' , ( ) => {
31+ it ( 'should render the actions inside calendar panel in popup mode' , fakeAsync ( ( ) => {
3232 const fixture = createComponent ( DatepickerWithActions ) ;
3333 fixture . detectChanges ( ) ;
3434 fixture . componentInstance . datepicker . open ( ) ;
3535 fixture . detectChanges ( ) ;
36+ tick ( ) ;
37+ flush ( ) ;
3638
3739 const actions = document . querySelector ( '.mat-datepicker-content .mat-datepicker-actions' ) ;
3840 expect ( actions ) . toBeTruthy ( ) ;
3941 expect ( actions ?. querySelector ( '.cancel' ) ) . toBeTruthy ( ) ;
4042 expect ( actions ?. querySelector ( '.apply' ) ) . toBeTruthy ( ) ;
41- } ) ;
43+ } ) ) ;
4244
43- it ( 'should render the actions inside calendar panel in touch UI mode' , ( ) => {
45+ it ( 'should render the actions inside calendar panel in touch UI mode' , fakeAsync ( ( ) => {
4446 const fixture = createComponent ( DatepickerWithActions ) ;
4547 fixture . componentInstance . touchUi = true ;
4648 fixture . detectChanges ( ) ;
4749 fixture . componentInstance . datepicker . open ( ) ;
4850 fixture . detectChanges ( ) ;
51+ tick ( ) ;
52+ flush ( ) ;
4953
5054 const actions = document . querySelector ( '.mat-datepicker-content .mat-datepicker-actions' ) ;
5155 expect ( actions ) . toBeTruthy ( ) ;
5256 expect ( actions ?. querySelector ( '.cancel' ) ) . toBeTruthy ( ) ;
5357 expect ( actions ?. querySelector ( '.apply' ) ) . toBeTruthy ( ) ;
54- } ) ;
58+ } ) ) ;
5559
5660 it ( 'should not assign the value or close the datepicker when a value is selected' , fakeAsync ( ( ) => {
5761 const fixture = createComponent ( DatepickerWithActions ) ;
5862 fixture . detectChanges ( ) ;
5963 const { control, datepicker, onDateChange, input} = fixture . componentInstance ;
6064 datepicker . open ( ) ;
6165 fixture . detectChanges ( ) ;
66+ tick ( ) ;
6267
6368 const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
6469 const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -86,6 +91,8 @@ describe('MatDatepickerActions', () => {
8691 const { control, datepicker, onDateChange, input} = fixture . componentInstance ;
8792 datepicker . open ( ) ;
8893 fixture . detectChanges ( ) ;
94+ tick ( ) ;
95+ flush ( ) ;
8996
9097 const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
9198 const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -98,6 +105,7 @@ describe('MatDatepickerActions', () => {
98105
99106 cells [ 10 ] . click ( ) ;
100107 fixture . detectChanges ( ) ;
108+ tick ( ) ;
101109 flush ( ) ;
102110
103111 expect ( datepicker . opened ) . toBe ( true ) ;
@@ -125,6 +133,8 @@ describe('MatDatepickerActions', () => {
125133 fixture . detectChanges ( ) ;
126134 datepicker . open ( ) ;
127135 fixture . detectChanges ( ) ;
136+ tick ( ) ;
137+ flush ( ) ;
128138
129139 const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
130140 const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -135,6 +145,7 @@ describe('MatDatepickerActions', () => {
135145
136146 cells [ 10 ] . click ( ) ;
137147 fixture . detectChanges ( ) ;
148+ tick ( ) ;
138149 flush ( ) ;
139150
140151 expect ( datepicker . opened ) . toBe ( true ) ;
@@ -156,6 +167,8 @@ describe('MatDatepickerActions', () => {
156167 const { control, datepicker, onDateChange, input} = fixture . componentInstance ;
157168 datepicker . open ( ) ;
158169 fixture . detectChanges ( ) ;
170+ tick ( ) ;
171+ flush ( ) ;
159172
160173 const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
161174 const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -168,6 +181,7 @@ describe('MatDatepickerActions', () => {
168181
169182 cells [ 10 ] . click ( ) ;
170183 fixture . detectChanges ( ) ;
184+ tick ( ) ;
171185 flush ( ) ;
172186
173187 expect ( datepicker . opened ) . toBe ( true ) ;
@@ -192,6 +206,8 @@ describe('MatDatepickerActions', () => {
192206 const { control, datepicker, onDateChange} = fixture . componentInstance ;
193207 datepicker . open ( ) ;
194208 fixture . detectChanges ( ) ;
209+ tick ( ) ;
210+ flush ( ) ;
195211
196212 let content = document . querySelector ( '.mat-datepicker-content' ) ! ;
197213 let actions = content . querySelector ( '.mat-datepicker-actions' ) ! ;
@@ -204,6 +220,7 @@ describe('MatDatepickerActions', () => {
204220
205221 cells [ 10 ] . click ( ) ;
206222 fixture . detectChanges ( ) ;
223+ tick ( ) ;
207224 flush ( ) ;
208225
209226 expect ( datepicker . opened ) . toBe ( true ) ;
@@ -233,6 +250,7 @@ describe('MatDatepickerActions', () => {
233250
234251 cells [ 10 ] . click ( ) ;
235252 fixture . detectChanges ( ) ;
253+ tick ( ) ;
236254 flush ( ) ;
237255
238256 expect ( datepicker . opened ) . toBe ( false ) ;
0 commit comments