@@ -12,7 +12,7 @@ import {FocusMonitor} from '@angular/cdk/a11y';
12
12
import { MatDateRangeInput } from './date-range-input' ;
13
13
import { MatDateRangePicker } from './date-range-picker' ;
14
14
15
- describe ( 'MatDatepicker ' , ( ) => {
15
+ describe ( 'MatDateRangeInput ' , ( ) => {
16
16
function createComponent < T > ( component : Type < T > ) : ComponentFixture < T > {
17
17
TestBed . configureTestingModule ( {
18
18
imports : [
@@ -218,23 +218,25 @@ describe('MatDatepicker', () => {
218
218
expect ( rangeInput . empty ) . toBe ( false ) ;
219
219
} ) ;
220
220
221
- it ( 'should mark the range controls as invalid if the start value is after the end value' , ( ) => {
222
- const fixture = createComponent ( StandardRangePicker ) ;
223
- fixture . detectChanges ( ) ;
224
- const { start, end} = fixture . componentInstance . range . controls ;
221
+ it ( 'should mark the range controls as invalid if the start value is after the end value' ,
222
+ fakeAsync ( ( ) => {
223
+ const fixture = createComponent ( StandardRangePicker ) ;
224
+ fixture . detectChanges ( ) ;
225
+ tick ( ) ;
226
+ const { start, end} = fixture . componentInstance . range . controls ;
225
227
226
- expect ( fixture . componentInstance . rangeInput . errorState ) . toBe ( false ) ;
227
- expect ( start . errors ?. matStartDateInvalid ) . toBeFalsy ( ) ;
228
- expect ( end . errors ?. matEndDateInvalid ) . toBeFalsy ( ) ;
228
+ expect ( fixture . componentInstance . rangeInput . errorState ) . toBe ( false ) ;
229
+ expect ( start . errors ?. matStartDateInvalid ) . toBeFalsy ( ) ;
230
+ expect ( end . errors ?. matEndDateInvalid ) . toBeFalsy ( ) ;
229
231
230
- start . setValue ( new Date ( 2020 , 2 , 2 ) ) ;
231
- end . setValue ( new Date ( 2020 , 1 , 2 ) ) ;
232
- fixture . detectChanges ( ) ;
232
+ start . setValue ( new Date ( 2020 , 2 , 2 ) ) ;
233
+ end . setValue ( new Date ( 2020 , 1 , 2 ) ) ;
234
+ fixture . detectChanges ( ) ;
233
235
234
- expect ( fixture . componentInstance . rangeInput . errorState ) . toBe ( true ) ;
235
- expect ( start . errors ?. matStartDateInvalid ) . toBeTruthy ( ) ;
236
- expect ( end . errors ?. matEndDateInvalid ) . toBeTruthy ( ) ;
237
- } ) ;
236
+ expect ( fixture . componentInstance . rangeInput . errorState ) . toBe ( true ) ;
237
+ expect ( start . errors ?. matStartDateInvalid ) . toBeTruthy ( ) ;
238
+ expect ( end . errors ?. matEndDateInvalid ) . toBeTruthy ( ) ;
239
+ } ) ) ;
238
240
239
241
it ( 'should pass the minimum date from the range input to the inner inputs' , ( ) => {
240
242
const fixture = createComponent ( StandardRangePicker ) ;
@@ -318,22 +320,24 @@ describe('MatDatepicker', () => {
318
320
expect ( startInput . focus ) . toHaveBeenCalled ( ) ;
319
321
} ) ;
320
322
321
- it ( 'should focus the end input when clicking on the form field when start has a value' , ( ) => {
322
- const fixture = createComponent ( StandardRangePicker ) ;
323
- fixture . detectChanges ( ) ;
324
- const endInput = fixture . componentInstance . end . nativeElement ;
325
- const formFieldContainer = fixture . nativeElement . querySelector ( '.mat-form-field-flex' ) ;
323
+ it ( 'should focus the end input when clicking on the form field when start has a value' ,
324
+ fakeAsync ( ( ) => {
325
+ const fixture = createComponent ( StandardRangePicker ) ;
326
+ fixture . detectChanges ( ) ;
327
+ tick ( ) ;
328
+ const endInput = fixture . componentInstance . end . nativeElement ;
329
+ const formFieldContainer = fixture . nativeElement . querySelector ( '.mat-form-field-flex' ) ;
326
330
327
- spyOn ( endInput , 'focus' ) . and . callThrough ( ) ;
331
+ spyOn ( endInput , 'focus' ) . and . callThrough ( ) ;
328
332
329
- fixture . componentInstance . range . controls . start . setValue ( new Date ( ) ) ;
330
- fixture . detectChanges ( ) ;
333
+ fixture . componentInstance . range . controls . start . setValue ( new Date ( ) ) ;
334
+ fixture . detectChanges ( ) ;
331
335
332
- formFieldContainer . click ( ) ;
333
- fixture . detectChanges ( ) ;
336
+ formFieldContainer . click ( ) ;
337
+ fixture . detectChanges ( ) ;
334
338
335
- expect ( endInput . focus ) . toHaveBeenCalled ( ) ;
336
- } ) ;
339
+ expect ( endInput . focus ) . toHaveBeenCalled ( ) ;
340
+ } ) ) ;
337
341
338
342
it ( 'should revalidate if a validation field changes' , ( ) => {
339
343
const fixture = createComponent ( StandardRangePicker ) ;
@@ -404,7 +408,7 @@ describe('MatDatepicker', () => {
404
408
expect ( end . nativeElement . getAttribute ( 'max' ) ) . toContain ( '2020' ) ;
405
409
} ) ;
406
410
407
- it ( 'should pass the range input value through to the calendar' , ( ) => {
411
+ it ( 'should pass the range input value through to the calendar' , fakeAsync ( ( ) => {
408
412
const fixture = createComponent ( StandardRangePicker ) ;
409
413
const { start, end} = fixture . componentInstance . range . controls ;
410
414
let overlayContainerElement : HTMLElement ;
@@ -414,9 +418,11 @@ describe('MatDatepicker', () => {
414
418
overlayContainerElement = overlayContainer . getContainerElement ( ) ;
415
419
} ) ( ) ;
416
420
fixture . detectChanges ( ) ;
421
+ tick ( ) ;
417
422
418
423
fixture . componentInstance . rangePicker . open ( ) ;
419
424
fixture . detectChanges ( ) ;
425
+ tick ( ) ;
420
426
421
427
const rangeTexts = Array . from ( overlayContainerElement ! . querySelectorAll ( [
422
428
'.mat-calendar-body-range-start' ,
@@ -425,9 +431,9 @@ describe('MatDatepicker', () => {
425
431
] . join ( ',' ) ) ) . map ( cell => cell . textContent ! . trim ( ) ) ;
426
432
427
433
expect ( rangeTexts ) . toEqual ( [ '2' , '3' , '4' , '5' ] ) ;
428
- } ) ;
434
+ } ) ) ;
429
435
430
- it ( 'should pass the comparison range through to the calendar' , ( ) => {
436
+ it ( 'should pass the comparison range through to the calendar' , fakeAsync ( ( ) => {
431
437
const fixture = createComponent ( StandardRangePicker ) ;
432
438
let overlayContainerElement : HTMLElement ;
433
439
@@ -442,6 +448,7 @@ describe('MatDatepicker', () => {
442
448
443
449
fixture . componentInstance . rangePicker . open ( ) ;
444
450
fixture . detectChanges ( ) ;
451
+ tick ( ) ;
445
452
446
453
const rangeTexts = Array . from ( overlayContainerElement ! . querySelectorAll ( [
447
454
'.mat-calendar-body-comparison-start' ,
@@ -450,7 +457,7 @@ describe('MatDatepicker', () => {
450
457
] . join ( ',' ) ) ) . map ( cell => cell . textContent ! . trim ( ) ) ;
451
458
452
459
expect ( rangeTexts ) . toEqual ( [ '2' , '3' , '4' , '5' ] ) ;
453
- } ) ;
460
+ } ) ) ;
454
461
455
462
it ( 'should preserve the preselected values when assigning through ngModel' , fakeAsync ( ( ) => {
456
463
const start = new Date ( 2020 , 1 , 2 ) ;
0 commit comments