|
1 | | -import { |
2 | | - ENTER, |
3 | | - RIGHT_ARROW, |
4 | | -} from '@angular/cdk/keycodes'; |
| 1 | +import {Direction, Directionality} from '@angular/cdk/bidi'; |
| 2 | +import {ENTER, RIGHT_ARROW} from '@angular/cdk/keycodes'; |
5 | 3 | import { |
6 | 4 | dispatchFakeEvent, |
7 | 5 | dispatchKeyboardEvent, |
8 | 6 | dispatchMouseEvent, |
9 | 7 | MockNgZone, |
10 | 8 | } from '@angular/cdk/testing'; |
11 | 9 | import {Component, NgZone} from '@angular/core'; |
12 | | -import {ComponentFixture, TestBed, async, inject} from '@angular/core/testing'; |
13 | | -import {DEC, FEB, JAN, MatNativeDateModule, NOV, JUL} from '@angular/material/core'; |
| 10 | +import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing'; |
| 11 | +import {DateAdapter, DEC, FEB, JAN, JUL, MatNativeDateModule, NOV} from '@angular/material/core'; |
14 | 12 | import {By} from '@angular/platform-browser'; |
15 | | -import {Direction, Directionality} from '@angular/cdk/bidi'; |
16 | 13 | import {MatCalendar} from './calendar'; |
17 | 14 | import {MatDatepickerIntl} from './datepicker-intl'; |
18 | 15 | import {MatDatepickerModule} from './datepicker-module'; |
@@ -63,6 +60,27 @@ describe('MatCalendar', () => { |
63 | 60 | testComponent = fixture.componentInstance; |
64 | 61 | }); |
65 | 62 |
|
| 63 | + it(`should update today's date`, inject([DateAdapter], (adapter: DateAdapter<Date>) => { |
| 64 | + let fakeToday = new Date(2018, 0, 1); |
| 65 | + spyOn(adapter, 'today').and.callFake(() => fakeToday); |
| 66 | + |
| 67 | + calendarInstance.activeDate = fakeToday; |
| 68 | + calendarInstance.updateTodaysDate(); |
| 69 | + fixture.detectChanges(); |
| 70 | + |
| 71 | + let todayCell = calendarElement.querySelector('.mat-calendar-body-today')!; |
| 72 | + expect(todayCell).not.toBeNull(); |
| 73 | + expect(todayCell.innerHTML.trim()).toBe('1'); |
| 74 | + |
| 75 | + fakeToday = new Date(2018, 0, 10); |
| 76 | + calendarInstance.updateTodaysDate(); |
| 77 | + fixture.detectChanges(); |
| 78 | + |
| 79 | + todayCell = calendarElement.querySelector('.mat-calendar-body-today')!; |
| 80 | + expect(todayCell).not.toBeNull(); |
| 81 | + expect(todayCell.innerHTML.trim()).toBe('10'); |
| 82 | + })); |
| 83 | + |
66 | 84 | it('should be in month view with specified month active', () => { |
67 | 85 | expect(calendarInstance.currentView).toBe('month'); |
68 | 86 | expect(calendarInstance.activeDate).toEqual(new Date(2017, JAN, 31)); |
|
0 commit comments