1
1
import { 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' ;
3
3
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
4
4
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5
5
import { MatNativeDateModule } from '@angular/material/core' ;
@@ -28,37 +28,42 @@ describe('MatDatepickerActions', () => {
28
28
return TestBed . createComponent ( component ) ;
29
29
}
30
30
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 ( ( ) => {
32
32
const fixture = createComponent ( DatepickerWithActions ) ;
33
33
fixture . detectChanges ( ) ;
34
34
fixture . componentInstance . datepicker . open ( ) ;
35
35
fixture . detectChanges ( ) ;
36
+ tick ( ) ;
37
+ flush ( ) ;
36
38
37
39
const actions = document . querySelector ( '.mat-datepicker-content .mat-datepicker-actions' ) ;
38
40
expect ( actions ) . toBeTruthy ( ) ;
39
41
expect ( actions ?. querySelector ( '.cancel' ) ) . toBeTruthy ( ) ;
40
42
expect ( actions ?. querySelector ( '.apply' ) ) . toBeTruthy ( ) ;
41
- } ) ;
43
+ } ) ) ;
42
44
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 ( ( ) => {
44
46
const fixture = createComponent ( DatepickerWithActions ) ;
45
47
fixture . componentInstance . touchUi = true ;
46
48
fixture . detectChanges ( ) ;
47
49
fixture . componentInstance . datepicker . open ( ) ;
48
50
fixture . detectChanges ( ) ;
51
+ tick ( ) ;
52
+ flush ( ) ;
49
53
50
54
const actions = document . querySelector ( '.mat-datepicker-content .mat-datepicker-actions' ) ;
51
55
expect ( actions ) . toBeTruthy ( ) ;
52
56
expect ( actions ?. querySelector ( '.cancel' ) ) . toBeTruthy ( ) ;
53
57
expect ( actions ?. querySelector ( '.apply' ) ) . toBeTruthy ( ) ;
54
- } ) ;
58
+ } ) ) ;
55
59
56
60
it ( 'should not assign the value or close the datepicker when a value is selected' , fakeAsync ( ( ) => {
57
61
const fixture = createComponent ( DatepickerWithActions ) ;
58
62
fixture . detectChanges ( ) ;
59
63
const { control, datepicker, onDateChange, input} = fixture . componentInstance ;
60
64
datepicker . open ( ) ;
61
65
fixture . detectChanges ( ) ;
66
+ tick ( ) ;
62
67
63
68
const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
64
69
const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -86,6 +91,8 @@ describe('MatDatepickerActions', () => {
86
91
const { control, datepicker, onDateChange, input} = fixture . componentInstance ;
87
92
datepicker . open ( ) ;
88
93
fixture . detectChanges ( ) ;
94
+ tick ( ) ;
95
+ flush ( ) ;
89
96
90
97
const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
91
98
const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -98,6 +105,7 @@ describe('MatDatepickerActions', () => {
98
105
99
106
cells [ 10 ] . click ( ) ;
100
107
fixture . detectChanges ( ) ;
108
+ tick ( ) ;
101
109
flush ( ) ;
102
110
103
111
expect ( datepicker . opened ) . toBe ( true ) ;
@@ -125,6 +133,8 @@ describe('MatDatepickerActions', () => {
125
133
fixture . detectChanges ( ) ;
126
134
datepicker . open ( ) ;
127
135
fixture . detectChanges ( ) ;
136
+ tick ( ) ;
137
+ flush ( ) ;
128
138
129
139
const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
130
140
const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -135,6 +145,7 @@ describe('MatDatepickerActions', () => {
135
145
136
146
cells [ 10 ] . click ( ) ;
137
147
fixture . detectChanges ( ) ;
148
+ tick ( ) ;
138
149
flush ( ) ;
139
150
140
151
expect ( datepicker . opened ) . toBe ( true ) ;
@@ -156,6 +167,8 @@ describe('MatDatepickerActions', () => {
156
167
const { control, datepicker, onDateChange, input} = fixture . componentInstance ;
157
168
datepicker . open ( ) ;
158
169
fixture . detectChanges ( ) ;
170
+ tick ( ) ;
171
+ flush ( ) ;
159
172
160
173
const content = document . querySelector ( '.mat-datepicker-content' ) ! ;
161
174
const cells = content . querySelectorAll < HTMLElement > ( '.mat-calendar-body-cell' ) ;
@@ -168,6 +181,7 @@ describe('MatDatepickerActions', () => {
168
181
169
182
cells [ 10 ] . click ( ) ;
170
183
fixture . detectChanges ( ) ;
184
+ tick ( ) ;
171
185
flush ( ) ;
172
186
173
187
expect ( datepicker . opened ) . toBe ( true ) ;
@@ -192,6 +206,8 @@ describe('MatDatepickerActions', () => {
192
206
const { control, datepicker, onDateChange} = fixture . componentInstance ;
193
207
datepicker . open ( ) ;
194
208
fixture . detectChanges ( ) ;
209
+ tick ( ) ;
210
+ flush ( ) ;
195
211
196
212
let content = document . querySelector ( '.mat-datepicker-content' ) ! ;
197
213
let actions = content . querySelector ( '.mat-datepicker-actions' ) ! ;
@@ -204,6 +220,7 @@ describe('MatDatepickerActions', () => {
204
220
205
221
cells [ 10 ] . click ( ) ;
206
222
fixture . detectChanges ( ) ;
223
+ tick ( ) ;
207
224
flush ( ) ;
208
225
209
226
expect ( datepicker . opened ) . toBe ( true ) ;
@@ -233,6 +250,7 @@ describe('MatDatepickerActions', () => {
233
250
234
251
cells [ 10 ] . click ( ) ;
235
252
fixture . detectChanges ( ) ;
253
+ tick ( ) ;
236
254
flush ( ) ;
237
255
238
256
expect ( datepicker . opened ) . toBe ( false ) ;
0 commit comments