1
- import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
2
- import { Component , provideZoneChangeDetection } from '@angular/core' ;
3
- import { MatCalendarBody , MatCalendarCell , MatCalendarUserEvent } from './calendar-body' ;
4
- import { By } from '@angular/platform-browser' ;
5
1
import {
6
- dispatchMouseEvent ,
7
2
dispatchFakeEvent ,
3
+ dispatchMouseEvent ,
8
4
dispatchTouchEvent ,
9
5
} from '@angular/cdk/testing/private' ;
6
+ import { Component } from '@angular/core' ;
7
+ import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
8
+ import { By } from '@angular/platform-browser' ;
9
+ import { MatCalendarBody , MatCalendarCell , MatCalendarUserEvent } from './calendar-body' ;
10
10
11
11
describe ( 'MatCalendarBody' , ( ) => {
12
- beforeEach ( ( ) => {
13
- TestBed . configureTestingModule ( {
14
- providers : [ provideZoneChangeDetection ( ) ] ,
15
- } ) ;
16
- } ) ;
17
12
beforeEach ( waitForAsync ( ( ) => {
18
13
TestBed . configureTestingModule ( {
19
14
imports : [ MatCalendarBody , StandardCalendarBody , RangeCalendarBody ] ,
@@ -77,6 +72,7 @@ describe('MatCalendarBody', () => {
77
72
78
73
it ( 'does not highlight today if today is not within the scope' , ( ) => {
79
74
testComponent . todayValue = 100000 ;
75
+ fixture . changeDetectorRef . markForCheck ( ) ;
80
76
fixture . detectChanges ( ) ;
81
77
82
78
const todayCell = calendarBodyNativeElement . querySelector ( '.mat-calendar-body-today' ) ! ;
@@ -85,6 +81,7 @@ describe('MatCalendarBody', () => {
85
81
86
82
it ( 'does not set aria-current="date" on any cell if today is not ' + 'the scope' , ( ) => {
87
83
testComponent . todayValue = 100000 ;
84
+ fixture . changeDetectorRef . markForCheck ( ) ;
88
85
fixture . detectChanges ( ) ;
89
86
90
87
const todayCell = calendarBodyNativeElement . querySelector (
@@ -112,6 +109,7 @@ describe('MatCalendarBody', () => {
112
109
it ( 'places label in first row if space is available' , ( ) => {
113
110
testComponent . rows [ 0 ] = testComponent . rows [ 0 ] . slice ( 3 ) ;
114
111
testComponent . rows = testComponent . rows . slice ( ) ;
112
+ fixture . changeDetectorRef . markForCheck ( ) ;
115
113
fixture . detectChanges ( ) ;
116
114
refreshElementLists ( ) ;
117
115
@@ -179,6 +177,7 @@ describe('MatCalendarBody', () => {
179
177
it ( 'should render a range' , ( ) => {
180
178
testComponent . startValue = 1 ;
181
179
testComponent . endValue = 5 ;
180
+ fixture . changeDetectorRef . markForCheck ( ) ;
182
181
fixture . detectChanges ( ) ;
183
182
184
183
expect ( cells [ 0 ] . classList ) . toContain ( startClass ) ;
@@ -191,6 +190,7 @@ describe('MatCalendarBody', () => {
191
190
it ( 'should render a comparison range' , ( ) => {
192
191
testComponent . comparisonStart = 1 ;
193
192
testComponent . comparisonEnd = 5 ;
193
+ fixture . changeDetectorRef . markForCheck ( ) ;
194
194
fixture . detectChanges ( ) ;
195
195
196
196
expect ( cells [ 0 ] . classList ) . toContain ( comparisonStartClass ) ;
@@ -203,6 +203,7 @@ describe('MatCalendarBody', () => {
203
203
it ( 'should be able to render two completely overlapping ranges' , ( ) => {
204
204
testComponent . startValue = testComponent . comparisonStart = 1 ;
205
205
testComponent . endValue = testComponent . comparisonEnd = 5 ;
206
+ fixture . changeDetectorRef . markForCheck ( ) ;
206
207
fixture . detectChanges ( ) ;
207
208
208
209
expect ( cells [ 0 ] . classList ) . toContain ( startClass ) ;
@@ -229,6 +230,7 @@ describe('MatCalendarBody', () => {
229
230
testComponent . endValue = 5 ;
230
231
testComponent . comparisonStart = 5 ;
231
232
testComponent . comparisonEnd = 10 ;
233
+ fixture . changeDetectorRef . markForCheck ( ) ;
232
234
fixture . detectChanges ( ) ;
233
235
234
236
expect ( cells [ 4 ] . classList ) . toContain ( bridgeStart ) ;
@@ -240,6 +242,7 @@ describe('MatCalendarBody', () => {
240
242
testComponent . endValue = null ;
241
243
testComponent . comparisonStart = 5 ;
242
244
testComponent . comparisonEnd = 10 ;
245
+ fixture . changeDetectorRef . markForCheck ( ) ;
243
246
fixture . detectChanges ( ) ;
244
247
245
248
expect ( cells . some ( cell => cell . classList . contains ( bridgeStart ) ) ) . toBe ( false ) ;
@@ -253,6 +256,7 @@ describe('MatCalendarBody', () => {
253
256
testComponent . comparisonEnd = 5 ;
254
257
testComponent . startValue = 5 ;
255
258
testComponent . endValue = 10 ;
259
+ fixture . changeDetectorRef . markForCheck ( ) ;
256
260
fixture . detectChanges ( ) ;
257
261
258
262
expect ( cells [ 4 ] . classList ) . toContain ( bridgeEnd ) ;
@@ -264,6 +268,7 @@ describe('MatCalendarBody', () => {
264
268
testComponent . comparisonEnd = 5 ;
265
269
testComponent . startValue = 5 ;
266
270
testComponent . endValue = null ;
271
+ fixture . changeDetectorRef . markForCheck ( ) ;
267
272
fixture . detectChanges ( ) ;
268
273
269
274
expect ( cells . some ( cell => cell . classList . contains ( bridgeEnd ) ) ) . toBe ( false ) ;
@@ -274,6 +279,7 @@ describe('MatCalendarBody', () => {
274
279
testComponent . comparisonEnd = 5 ;
275
280
testComponent . startValue = 2 ;
276
281
testComponent . endValue = 4 ;
282
+ fixture . changeDetectorRef . markForCheck ( ) ;
277
283
fixture . detectChanges ( ) ;
278
284
279
285
expect ( cells [ 0 ] . classList ) . toContain ( comparisonStartClass ) ;
@@ -295,6 +301,7 @@ describe('MatCalendarBody', () => {
295
301
testComponent . endValue = 5 ;
296
302
testComponent . comparisonStart = 2 ;
297
303
testComponent . comparisonEnd = 4 ;
304
+ fixture . changeDetectorRef . markForCheck ( ) ;
298
305
fixture . detectChanges ( ) ;
299
306
300
307
expect ( cells [ 0 ] . classList ) . toContain ( startClass ) ;
@@ -314,6 +321,7 @@ describe('MatCalendarBody', () => {
314
321
it ( 'should be able to show a range that is larger than the calendar' , ( ) => {
315
322
testComponent . startValue = - 10 ;
316
323
testComponent . endValue = 100 ;
324
+ fixture . changeDetectorRef . markForCheck ( ) ;
317
325
fixture . detectChanges ( ) ;
318
326
319
327
expect ( cells . every ( cell => cell . classList . contains ( inRangeClass ) ) ) . toBe ( true ) ;
@@ -324,6 +332,7 @@ describe('MatCalendarBody', () => {
324
332
it ( 'should be able to show a comparison range that is larger than the calendar' , ( ) => {
325
333
testComponent . comparisonStart = - 10 ;
326
334
testComponent . comparisonEnd = 100 ;
335
+ fixture . changeDetectorRef . markForCheck ( ) ;
327
336
fixture . detectChanges ( ) ;
328
337
329
338
expect ( cells . every ( cell => cell . classList . contains ( inComparisonClass ) ) ) . toBe ( true ) ;
@@ -334,6 +343,8 @@ describe('MatCalendarBody', () => {
334
343
it ( 'should be able to show a range that starts before the beginning of the calendar' , ( ) => {
335
344
testComponent . startValue = - 10 ;
336
345
testComponent . endValue = 2 ;
346
+ fixture . changeDetectorRef . markForCheck ( ) ;
347
+
337
348
fixture . detectChanges ( ) ;
338
349
339
350
expect ( cells . some ( cell => cell . classList . contains ( startClass ) ) ) . toBe ( false ) ;
@@ -344,6 +355,7 @@ describe('MatCalendarBody', () => {
344
355
it ( 'should be able to show a comparison range that starts before the beginning of the calendar' , ( ) => {
345
356
testComponent . comparisonStart = - 10 ;
346
357
testComponent . comparisonEnd = 2 ;
358
+ fixture . changeDetectorRef . markForCheck ( ) ;
347
359
fixture . detectChanges ( ) ;
348
360
349
361
expect ( cells . some ( cell => cell . classList . contains ( comparisonStartClass ) ) ) . toBe ( false ) ;
@@ -354,6 +366,7 @@ describe('MatCalendarBody', () => {
354
366
it ( 'should be able to show a range that ends after the end of the calendar' , ( ) => {
355
367
testComponent . startValue = 27 ;
356
368
testComponent . endValue = 50 ;
369
+ fixture . changeDetectorRef . markForCheck ( ) ;
357
370
fixture . detectChanges ( ) ;
358
371
359
372
expect ( cells . some ( cell => cell . classList . contains ( endClass ) ) ) . toBe ( false ) ;
@@ -364,6 +377,7 @@ describe('MatCalendarBody', () => {
364
377
it ( 'should be able to show a comparison range that ends after the end of the calendar' , ( ) => {
365
378
testComponent . comparisonStart = 27 ;
366
379
testComponent . comparisonEnd = 50 ;
380
+ fixture . changeDetectorRef . markForCheck ( ) ;
367
381
fixture . detectChanges ( ) ;
368
382
369
383
expect ( cells . some ( cell => cell . classList . contains ( comparisonEndClass ) ) ) . toBe ( false ) ;
@@ -374,6 +388,7 @@ describe('MatCalendarBody', () => {
374
388
it ( 'should be able to show a range that ends after the end of the calendar' , ( ) => {
375
389
testComponent . startValue = 27 ;
376
390
testComponent . endValue = 50 ;
391
+ fixture . changeDetectorRef . markForCheck ( ) ;
377
392
fixture . detectChanges ( ) ;
378
393
379
394
expect ( cells . some ( cell => cell . classList . contains ( endClass ) ) ) . toBe ( false ) ;
@@ -384,6 +399,7 @@ describe('MatCalendarBody', () => {
384
399
it ( 'should not to mark a date as both the start and end' , ( ) => {
385
400
testComponent . startValue = 1 ;
386
401
testComponent . endValue = 1 ;
402
+ fixture . changeDetectorRef . markForCheck ( ) ;
387
403
fixture . detectChanges ( ) ;
388
404
389
405
expect ( cells [ 0 ] . classList ) . not . toContain ( startClass ) ;
@@ -394,6 +410,7 @@ describe('MatCalendarBody', () => {
394
410
it ( 'should not mark a date as both the comparison start and end' , ( ) => {
395
411
testComponent . comparisonStart = 1 ;
396
412
testComponent . comparisonEnd = 1 ;
413
+ fixture . changeDetectorRef . markForCheck ( ) ;
397
414
fixture . detectChanges ( ) ;
398
415
399
416
expect ( cells [ 0 ] . classList ) . not . toContain ( comparisonStartClass ) ;
@@ -404,6 +421,7 @@ describe('MatCalendarBody', () => {
404
421
it ( 'should not mark a date as the range end if it comes before the start' , ( ) => {
405
422
testComponent . startValue = 2 ;
406
423
testComponent . endValue = 1 ;
424
+ fixture . changeDetectorRef . markForCheck ( ) ;
407
425
fixture . detectChanges ( ) ;
408
426
409
427
expect ( cells [ 0 ] . classList ) . not . toContain ( endClass ) ;
@@ -414,6 +432,7 @@ describe('MatCalendarBody', () => {
414
432
it ( 'should not mark a date as the comparison range end if it comes before the start' , ( ) => {
415
433
testComponent . comparisonStart = 2 ;
416
434
testComponent . comparisonEnd = 1 ;
435
+ fixture . changeDetectorRef . markForCheck ( ) ;
417
436
fixture . detectChanges ( ) ;
418
437
419
438
expect ( cells [ 0 ] . classList ) . not . toContain ( comparisonEndClass ) ;
@@ -424,6 +443,7 @@ describe('MatCalendarBody', () => {
424
443
it ( 'should not show a range if there is no start' , ( ) => {
425
444
testComponent . startValue = null ;
426
445
testComponent . endValue = 10 ;
446
+ fixture . changeDetectorRef . markForCheck ( ) ;
427
447
fixture . detectChanges ( ) ;
428
448
429
449
expect ( cells . some ( cell => cell . classList . contains ( inRangeClass ) ) ) . toBe ( false ) ;
@@ -433,6 +453,7 @@ describe('MatCalendarBody', () => {
433
453
it ( 'should not show a comparison range if there is no start' , ( ) => {
434
454
testComponent . comparisonStart = null ;
435
455
testComponent . comparisonEnd = 10 ;
456
+ fixture . changeDetectorRef . markForCheck ( ) ;
436
457
fixture . detectChanges ( ) ;
437
458
438
459
expect ( cells . some ( cell => cell . classList . contains ( inComparisonClass ) ) ) . toBe ( false ) ;
@@ -442,6 +463,7 @@ describe('MatCalendarBody', () => {
442
463
it ( 'should not show a comparison range if there is no end' , ( ) => {
443
464
testComponent . comparisonStart = 10 ;
444
465
testComponent . comparisonEnd = null ;
466
+ fixture . changeDetectorRef . markForCheck ( ) ;
445
467
fixture . detectChanges ( ) ;
446
468
447
469
expect ( cells . some ( cell => cell . classList . contains ( inComparisonClass ) ) ) . toBe ( false ) ;
@@ -529,6 +551,7 @@ describe('MatCalendarBody', () => {
529
551
'while hovering' ,
530
552
( ) => {
531
553
fixture . componentInstance . startValue = - 1 ;
554
+ fixture . changeDetectorRef . markForCheck ( ) ;
532
555
fixture . detectChanges ( ) ;
533
556
534
557
dispatchMouseEvent ( cells [ 2 ] , 'mouseenter' ) ;
@@ -546,6 +569,7 @@ describe('MatCalendarBody', () => {
546
569
'while moving focus' ,
547
570
( ) => {
548
571
fixture . componentInstance . startValue = - 1 ;
572
+ fixture . changeDetectorRef . markForCheck ( ) ;
549
573
fixture . detectChanges ( ) ;
550
574
551
575
dispatchMouseEvent ( cells [ 2 ] , 'focus' ) ;
@@ -618,6 +642,7 @@ describe('MatCalendarBody', () => {
618
642
619
643
it ( 'should mark a cell as being identical to the comparison range' , ( ) => {
620
644
testComponent . comparisonStart = testComponent . comparisonEnd = 3 ;
645
+ fixture . changeDetectorRef . markForCheck ( ) ;
621
646
fixture . detectChanges ( ) ;
622
647
623
648
const comparisonIdenticalCells : NodeListOf < HTMLElement > =
@@ -645,6 +670,7 @@ describe('MatCalendarBody', () => {
645
670
// Pre-select a range to drag.
646
671
fixture . componentInstance . startValue = 4 ;
647
672
fixture . componentInstance . endValue = 6 ;
673
+ fixture . changeDetectorRef . markForCheck ( ) ;
648
674
fixture . detectChanges ( ) ;
649
675
} ) ;
650
676
0 commit comments