@@ -50,11 +50,45 @@ describe('MatCalendarBody', () => {
50
50
} ) ;
51
51
52
52
it ( 'highlights today' , ( ) => {
53
- const todayCell = calendarBodyNativeElement . querySelector ( '.mat-calendar-body-today' ) ! ;
53
+ const todayCells = calendarBodyNativeElement . querySelectorAll (
54
+ '.mat-calendar-body-today' ) ! ;
55
+ expect ( todayCells . length ) . toBe ( 1 ) ;
56
+
57
+ const todayCell = todayCells [ 0 ] ;
58
+
59
+ expect ( todayCell ) . not . toBeNull ( ) ;
60
+ expect ( todayCell . innerHTML . trim ( ) ) . toBe ( '3' ) ;
61
+ } ) ;
62
+
63
+ it ( 'sets aria-current="date" on today' , ( ) => {
64
+ const todayCells = calendarBodyNativeElement . querySelectorAll (
65
+ '[aria-current="date"] .mat-calendar-body-today' ) ! ;
66
+ expect ( todayCells . length ) . toBe ( 1 ) ;
67
+
68
+ const todayCell = todayCells [ 0 ] ;
69
+
54
70
expect ( todayCell ) . not . toBeNull ( ) ;
55
71
expect ( todayCell . innerHTML . trim ( ) ) . toBe ( '3' ) ;
56
72
} ) ;
57
73
74
+ it ( 'does not highlight today if today is not within the scope' , ( ) => {
75
+ testComponent . todayValue = null ;
76
+ fixture . detectChanges ( ) ;
77
+
78
+ const todayCell = calendarBodyNativeElement . querySelector ( '.mat-calendar-body-today' ) ! ;
79
+ expect ( todayCell ) . toBeNull ( ) ;
80
+ } ) ;
81
+
82
+ it ( 'does not set aria-current="date" on any cell if today is not ' +
83
+ 'the scope' , ( ) => {
84
+ testComponent . todayValue = null ;
85
+ fixture . detectChanges ( ) ;
86
+
87
+ const todayCell = calendarBodyNativeElement . querySelector (
88
+ '[aria-current="date"] .mat-calendar-body-today' ) ! ;
89
+ expect ( todayCell ) . toBeNull ( ) ;
90
+ } ) ;
91
+
58
92
it ( 'highlights selected' , ( ) => {
59
93
const selectedCell = calendarBodyNativeElement . querySelector ( '.mat-calendar-body-selected' ) ! ;
60
94
expect ( selectedCell ) . not . toBeNull ( ) ;
@@ -595,7 +629,7 @@ describe('MatCalendarBody', () => {
595
629
<table mat-calendar-body
596
630
[label]="label"
597
631
[rows]="rows"
598
- [todayValue]="todayValue"
632
+ [todayValue]="todayValue! "
599
633
[startValue]="selectedValue"
600
634
[endValue]="selectedValue"
601
635
[labelMinRequiredCells]="labelMinRequiredCells"
@@ -607,7 +641,7 @@ describe('MatCalendarBody', () => {
607
641
class StandardCalendarBody {
608
642
label = 'Jan 2017' ;
609
643
rows = createCalendarCells ( 2 ) ;
610
- todayValue = 3 ;
644
+ todayValue : number | null = 3 ;
611
645
selectedValue = 4 ;
612
646
labelMinRequiredCells = 3 ;
613
647
numCols = 7 ;
0 commit comments