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