-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
month-view.spec.ts
644 lines (517 loc) · 24.7 KB
/
month-view.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
import {Direction, Directionality} from '@angular/cdk/bidi';
import {
DOWN_ARROW,
END,
ENTER,
HOME,
LEFT_ARROW,
PAGE_DOWN,
PAGE_UP,
RIGHT_ARROW,
SPACE,
UP_ARROW,
ESCAPE,
} from '@angular/cdk/keycodes';
import {
dispatchFakeEvent,
dispatchKeyboardEvent,
dispatchMouseEvent,
createKeyboardEvent,
dispatchEvent,
} from '@angular/cdk/testing/private';
import {Component} from '@angular/core';
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
import {MAT_DATE_FORMATS, MatNativeDateModule} from '@angular/material/core';
import {DEC, FEB, JAN, MAR, NOV} from '@angular/material/testing';
import {By} from '@angular/platform-browser';
import {MatCalendarBody} from './calendar-body';
import {MatMonthView} from './month-view';
import {DateRange} from './date-selection-model';
import {
MAT_DATE_RANGE_SELECTION_STRATEGY,
DefaultMatCalendarRangeStrategy,
} from './date-range-selection-strategy';
describe('MatMonthView', () => {
describe('standard providers', () => {
let dir: {value: Direction};
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
MatNativeDateModule,
],
declarations: [
MatCalendarBody,
MatMonthView,
// Test components.
StandardMonthView,
MonthViewWithDateFilter,
MonthViewWithDateClass,
],
providers: [
{provide: Directionality, useFactory: () => dir = {value: 'ltr'}},
{provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: DefaultMatCalendarRangeStrategy}
]
});
TestBed.compileComponents();
}));
describe('standard month view', () => {
let fixture: ComponentFixture<StandardMonthView>;
let testComponent: StandardMonthView;
let monthViewNativeElement: Element;
beforeEach(() => {
fixture = TestBed.createComponent(StandardMonthView);
fixture.detectChanges();
let monthViewDebugElement = fixture.debugElement.query(By.directive(MatMonthView))!;
monthViewNativeElement = monthViewDebugElement.nativeElement;
testComponent = fixture.componentInstance;
});
it('has correct month label', () => {
let labelEl = monthViewNativeElement.querySelector('.mat-calendar-body-label')!;
expect(labelEl.innerHTML.trim()).toBe('JAN');
});
it('has 31 days', () => {
let cellEls = monthViewNativeElement.querySelectorAll('.mat-calendar-body-cell')!;
expect(cellEls.length).toBe(31);
});
it('shows selected date if in same month', () => {
let selectedEl = monthViewNativeElement.querySelector('.mat-calendar-body-selected')!;
expect(selectedEl.innerHTML.trim()).toBe('10');
});
it('does not show selected date if in different month', () => {
testComponent.selected = new Date(2017, MAR, 10);
fixture.detectChanges();
let selectedEl = monthViewNativeElement.querySelector('.mat-calendar-body-selected');
expect(selectedEl).toBeNull();
});
it('fires selected change event on cell clicked', () => {
let cellEls = monthViewNativeElement.querySelectorAll('.mat-calendar-body-cell');
(cellEls[cellEls.length - 1] as HTMLElement).click();
fixture.detectChanges();
let selectedEl = monthViewNativeElement.querySelector('.mat-calendar-body-selected')!;
expect(selectedEl.innerHTML.trim()).toBe('31');
});
it('should mark active date', () => {
let cellEls = monthViewNativeElement.querySelectorAll('.mat-calendar-body-cell');
expect((cellEls[4] as HTMLElement).innerText.trim()).toBe('5');
expect(cellEls[4].classList).toContain('mat-calendar-body-active');
});
describe('a11y', () => {
it('should set the correct role on the internal table node', () => {
const table = monthViewNativeElement.querySelector('table')!;
expect(table.getAttribute('role')).toBe('grid');
});
it('should set the correct scope on the table headers', () => {
const nonDividerHeaders = monthViewNativeElement.querySelectorAll(
'.mat-calendar-table-header th:not(.mat-calendar-table-header-divider)');
const dividerHeader =
monthViewNativeElement.querySelector('.mat-calendar-table-header-divider')!;
expect(Array.from(nonDividerHeaders).every(header => {
return header.getAttribute('scope') === 'col';
})).toBe(true);
expect(dividerHeader.hasAttribute('scope')).toBe(false);
});
describe('calendar body', () => {
let calendarBodyEl: HTMLElement;
let calendarInstance: StandardMonthView;
beforeEach(() => {
calendarInstance = fixture.componentInstance;
calendarBodyEl =
fixture.debugElement.nativeElement.querySelector(
'.mat-calendar-body') as HTMLElement;
expect(calendarBodyEl).not.toBeNull();
dir.value = 'ltr';
fixture.componentInstance.date = new Date(2017, JAN, 5);
dispatchFakeEvent(calendarBodyEl, 'focus');
fixture.detectChanges();
});
it('should decrement date on left arrow press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 4));
calendarInstance.date = new Date(2017, JAN, 1);
fixture.detectChanges();
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2016, DEC, 31));
});
it('should increment date on left arrow press in rtl', () => {
dir.value = 'rtl';
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 6));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 7));
});
it('should increment date on right arrow press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 6));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 7));
});
it('should decrement date on right arrow press in rtl', () => {
dir.value = 'rtl';
dispatchKeyboardEvent(calendarBodyEl, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 4));
calendarInstance.date = new Date(2017, JAN, 1);
fixture.detectChanges();
dispatchKeyboardEvent(calendarBodyEl, 'keydown', RIGHT_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2016, DEC, 31));
});
it('should go up a row on up arrow press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', UP_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2016, DEC, 29));
calendarInstance.date = new Date(2017, JAN, 7);
fixture.detectChanges();
dispatchKeyboardEvent(calendarBodyEl, 'keydown', UP_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2016, DEC, 31));
});
it('should go down a row on down arrow press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', DOWN_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 12));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', DOWN_ARROW);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 19));
});
it('should go to beginning of the month on home press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', HOME);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 1));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', HOME);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 1));
});
it('should go to end of the month on end press', () => {
calendarInstance.date = new Date(2017, JAN, 10);
dispatchKeyboardEvent(calendarBodyEl, 'keydown', END);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 31));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', END);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, JAN, 31));
});
it('should go back one month on page up press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', PAGE_UP);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2016, DEC, 5));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', PAGE_UP);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2016, NOV, 5));
});
it('should go forward one month on page down press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', PAGE_DOWN);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, FEB, 5));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', PAGE_DOWN);
fixture.detectChanges();
expect(calendarInstance.date).toEqual(new Date(2017, MAR, 5));
});
it('should select active date on enter', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.selected).toEqual(new Date(2017, JAN, 10));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', ENTER);
fixture.detectChanges();
expect(testComponent.selected).toEqual(new Date(2017, JAN, 4));
});
it('should select active date on space', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
fixture.detectChanges();
expect(testComponent.selected).toEqual(new Date(2017, JAN, 10));
dispatchKeyboardEvent(calendarBodyEl, 'keydown', SPACE);
fixture.detectChanges();
expect(testComponent.selected).toEqual(new Date(2017, JAN, 4));
});
it('should cancel the current range selection when pressing escape', () => {
const cellEls = monthViewNativeElement.querySelectorAll('.mat-calendar-body-cell');
testComponent.selected = new DateRange(new Date(2017, JAN, 10), null);
fixture.detectChanges();
dispatchMouseEvent(cellEls[15], 'mouseenter');
fixture.detectChanges();
// Note that here we only care that _some_ kind of range is rendered. There are
// plenty of tests in the calendar body which assert that everything is correct.
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-start').length).toBeGreaterThan(0);
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-in-preview').length).toBeGreaterThan(0);
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-end').length).toBeGreaterThan(0);
const event = createKeyboardEvent('keydown', ESCAPE, 'Escape');
spyOn(event, 'stopPropagation');
dispatchEvent(calendarBodyEl, event);
fixture.detectChanges();
// Expect the range range to have been cleared.
expect(monthViewNativeElement.querySelectorAll([
'.mat-calendar-body-preview-start',
'.mat-calendar-body-in-preview',
'.mat-calendar-body-preview-end'
].join(',')).length).toBe(0);
expect(event.stopPropagation).toHaveBeenCalled();
expect(event.defaultPrevented).toBe(true);
expect(testComponent.selected).toBeFalsy();
});
it('should not cancel the current range selection when pressing escape with a '
+ 'modifier key', () => {
const cellEls = monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-cell');
testComponent.selected = new DateRange(new Date(2017, JAN, 10), null);
fixture.detectChanges();
dispatchMouseEvent(cellEls[15], 'mouseenter');
fixture.detectChanges();
const rangeStarts =
monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-start').length;
const rangeMids =
monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-in-preview').length;
const rangeEnds =
monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-end').length;
// Note that here we only care that _some_ kind of range is rendered. There are
// plenty of tests in the calendar body which assert that everything is correct.
expect(rangeStarts).toBeGreaterThan(0);
expect(rangeMids).toBeGreaterThan(0);
expect(rangeEnds).toBeGreaterThan(0);
const event = createKeyboardEvent(
'keydown', ESCAPE, 'Escape', {alt: true});
spyOn(event, 'stopPropagation');
dispatchEvent(calendarBodyEl, event);
fixture.detectChanges();
expect(
monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-start').length
).toBe(rangeStarts);
expect(
monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-in-preview').length
).toBe(rangeMids);
expect(
monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-end').length
).toBe(rangeEnds);
expect(event.stopPropagation).not.toHaveBeenCalled();
expect(event.defaultPrevented).toBe(false);
expect(testComponent.selected).toBeTruthy();
});
it('should clear the preview range when the user is done selecting', () => {
const cellEls = monthViewNativeElement.querySelectorAll<HTMLElement>(
'.mat-calendar-body-cell');
testComponent.selected = new DateRange(new Date(2017, JAN, 10), null);
fixture.detectChanges();
dispatchMouseEvent(cellEls[15], 'mouseenter');
fixture.detectChanges();
// Note that here we only care that _some_ kind of range is rendered. There are
// plenty of tests in the calendar body which assert that everything is correct.
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-start').length).toBeGreaterThan(0);
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-in-preview').length).toBeGreaterThan(0);
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-end').length).toBeGreaterThan(0);
cellEls[15].click();
fixture.detectChanges();
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-start').length).toBe(0);
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-in-preview').length).toBe(0);
expect(monthViewNativeElement.querySelectorAll(
'.mat-calendar-body-preview-end').length).toBe(0);
});
it('should not clear the range when pressing escape while there is no preview', () => {
const getRangeElements = () => monthViewNativeElement.querySelectorAll([
'.mat-calendar-body-range-start',
'.mat-calendar-body-in-range',
'.mat-calendar-body-range-end'
].join(','));
testComponent.selected = new DateRange(
new Date(2017, JAN, 10), new Date(2017, JAN, 15));
fixture.detectChanges();
expect(getRangeElements().length)
.toBeGreaterThan(0, 'Expected range to be present on init.');
dispatchKeyboardEvent(calendarBodyEl, 'keydown', ESCAPE);
fixture.detectChanges();
expect(getRangeElements().length)
.toBeGreaterThan(0, 'Expected range to be present after pressing the escape key.');
});
it('should not fire the selected change event when clicking on an already-selected ' +
'date while selecting a single date', () => {
testComponent.selected = new Date(2017, JAN, 10);
fixture.detectChanges();
expect(fixture.componentInstance.selectedChangeSpy).not.toHaveBeenCalled();
const selectedCell =
monthViewNativeElement.querySelector(
'.mat-calendar-body-selected') as HTMLElement;
selectedCell.click();
fixture.detectChanges();
expect(fixture.componentInstance.selectedChangeSpy).not.toHaveBeenCalled();
});
it('should fire the selected change event when clicking on an already-selected ' +
'date while selecting a range', () => {
const selectedDate = new Date(2017, JAN, 10);
testComponent.selected = new DateRange(selectedDate, null);
fixture.detectChanges();
expect(fixture.componentInstance.selectedChangeSpy).not.toHaveBeenCalled();
const selectedCell =
monthViewNativeElement.querySelector('.mat-calendar-body-selected') as HTMLElement;
selectedCell.click();
fixture.detectChanges();
expect(fixture.componentInstance.selectedChangeSpy).toHaveBeenCalledWith(selectedDate);
});
it('should fire the _userSelection event with the correct value when clicking ' +
'on a selected date', () => {
const date = new Date(2017, JAN, 10);
testComponent.selected = date;
fixture.detectChanges();
expect(fixture.componentInstance.userSelectionSpy).not.toHaveBeenCalled();
const selectedCell =
monthViewNativeElement.querySelector('.mat-calendar-body-selected') as HTMLElement;
selectedCell.click();
fixture.detectChanges();
expect(fixture.componentInstance.userSelectionSpy).toHaveBeenCalledWith(
jasmine.objectContaining({value: date}));
});
});
});
});
describe('month view with date filter', () => {
it('should disable filtered dates', () => {
const fixture = TestBed.createComponent(MonthViewWithDateFilter);
fixture.detectChanges();
let cells = fixture.nativeElement.querySelectorAll('.mat-calendar-body-cell');
expect(cells[0].classList).toContain('mat-calendar-body-disabled');
expect(cells[1].classList).not.toContain('mat-calendar-body-disabled');
});
it('should not call the date filter function if the date is before the min date', () => {
const fixture = TestBed.createComponent(MonthViewWithDateFilter);
const activeDate = fixture.componentInstance.activeDate;
const spy = spyOn(fixture.componentInstance, 'dateFilter').and.callThrough();
fixture.componentInstance.minDate =
new Date(activeDate.getFullYear() + 1, activeDate.getMonth(), activeDate.getDate());
fixture.detectChanges();
expect(spy).not.toHaveBeenCalled();
});
it('should not call the date filter function if the date is after the max date', () => {
const fixture = TestBed.createComponent(MonthViewWithDateFilter);
const activeDate = fixture.componentInstance.activeDate;
const spy = spyOn(fixture.componentInstance, 'dateFilter').and.callThrough();
fixture.componentInstance.maxDate =
new Date(activeDate.getFullYear() - 1, activeDate.getMonth(), activeDate.getDate());
fixture.detectChanges();
expect(spy).not.toHaveBeenCalled();
});
});
describe('month view with custom date classes', () => {
let fixture: ComponentFixture<MonthViewWithDateClass>;
let monthViewNativeElement: Element;
let dateClassSpy: jasmine.Spy;
beforeEach(() => {
fixture = TestBed.createComponent(MonthViewWithDateClass);
dateClassSpy = spyOn(fixture.componentInstance, 'dateClass').and.callThrough();
fixture.detectChanges();
let monthViewDebugElement = fixture.debugElement.query(By.directive(MatMonthView))!;
monthViewNativeElement = monthViewDebugElement.nativeElement;
});
it('should be able to add a custom class to some dates', () => {
let cells = monthViewNativeElement.querySelectorAll('.mat-calendar-body-cell');
expect(cells[0].classList).not.toContain('even');
expect(cells[1].classList).toContain('even');
});
it('should call dateClass with the correct view name', () => {
expect(dateClassSpy).toHaveBeenCalledWith(jasmine.any(Date), 'month');
});
});
});
describe('month view with custom date formats', () => {
let fixture: ComponentFixture<StandardMonthView>;
let monthViewNativeElement: Element;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
MatNativeDateModule,
],
declarations: [
MatCalendarBody,
MatMonthView,
// Test components.
StandardMonthView,
MonthViewWithDateFilter,
MonthViewWithDateClass,
],
providers: [
{provide: Directionality, useFactory: () => ({value: 'ltr'})},
{provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: DefaultMatCalendarRangeStrategy},
{
provide: MAT_DATE_FORMATS,
useValue: {
parse: {
dateInput: null,
},
display: {
dateInput: {year: 'numeric', month: 'numeric', day: 'numeric'},
monthLabel: {year: 'numeric', month: 'short'},
monthYearLabel: {year: 'numeric', month: 'short'},
dateA11yLabel: {year: 'numeric', month: 'long', day: 'numeric'},
monthYearA11yLabel: {year: 'numeric', month: 'long'},
}
}
},
]
});
TestBed.compileComponents();
fixture = TestBed.createComponent(StandardMonthView);
fixture.detectChanges();
let monthViewDebugElement = fixture.debugElement.query(By.directive(MatMonthView))!;
monthViewNativeElement = monthViewDebugElement.nativeElement;
}));
it('has correct month label', () => {
let labelEl = monthViewNativeElement.querySelector('.mat-calendar-body-label')!;
expect(labelEl.innerHTML.trim()).toBe('Jan 2017');
});
});
});
@Component({
template: `
<mat-month-view
[(activeDate)]="date"
[(selected)]="selected"
(selectedChange)="selectedChangeSpy($event)"
(_userSelection)="userSelectionSpy($event)"></mat-month-view>`,
})
class StandardMonthView {
date = new Date(2017, JAN, 5);
selected: Date | DateRange<Date> = new Date(2017, JAN, 10);
selectedChangeSpy = jasmine.createSpy('selectedChange');
userSelectionSpy = jasmine.createSpy('userSelection');
}
@Component({
template: `
<mat-month-view
[activeDate]="activeDate"
[dateFilter]="dateFilter"
[minDate]="minDate"
[maxDate]="maxDate"></mat-month-view>`
})
class MonthViewWithDateFilter {
activeDate = new Date(2017, JAN, 1);
minDate: Date | null = null;
maxDate: Date | null = null;
dateFilter(date: Date) {
return date.getDate() % 2 == 0;
}
}
@Component({
template: `<mat-month-view [activeDate]="activeDate" [dateClass]="dateClass"></mat-month-view>`
})
class MonthViewWithDateClass {
activeDate = new Date(2017, JAN, 1);
dateClass(date: Date) {
return date.getDate() % 2 == 0 ? 'even' : undefined;
}
}