1
- /*
2
1
import {
3
2
DOWN_ARROW ,
4
3
END ,
@@ -21,9 +20,10 @@ import {
21
20
JUL ,
22
21
JUN ,
23
22
MAR ,
24
- MAY,
25
23
MatNativeDateModule ,
24
+ MAY ,
26
25
NOV ,
26
+ OCT ,
27
27
SEP ,
28
28
} from '@angular/material/core' ;
29
29
import { By } from '@angular/platform-browser' ;
@@ -32,6 +32,7 @@ import {MatCalendar} from './calendar';
32
32
import { MatCalendarBody } from './calendar-body' ;
33
33
import { MatDatepickerIntl } from './datepicker-intl' ;
34
34
import { MatMonthView } from './month-view' ;
35
+ import { MatMultiYearView } from './multi-year-view' ;
35
36
import { MatYearView } from './year-view' ;
36
37
37
38
@@ -47,6 +48,7 @@ describe('MatCalendar', () => {
47
48
MatCalendarBody ,
48
49
MatMonthView ,
49
50
MatYearView ,
51
+ MatMultiYearView ,
50
52
51
53
// Test components.
52
54
StandardCalendar ,
@@ -85,22 +87,22 @@ describe('MatCalendar', () => {
85
87
} ) ;
86
88
87
89
it ( 'should be in month view with specified month active' , ( ) => {
88
- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
90
+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
89
91
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
90
92
} ) ;
91
93
92
94
it ( 'should toggle view when period clicked' , ( ) => {
93
- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
95
+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
94
96
95
97
periodButton . click ( ) ;
96
98
fixture . detectChanges ( ) ;
97
99
98
- expect(calendarInstance._monthView ).toBe(false, 'should be in year view ');
100
+ expect ( calendarInstance . _currentView ) . toBe ( 'multi- year') ;
99
101
100
102
periodButton . click ( ) ;
101
103
fixture . detectChanges ( ) ;
102
104
103
- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
105
+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
104
106
} ) ;
105
107
106
108
it ( 'should go to next and previous month' , ( ) => {
@@ -121,9 +123,14 @@ describe('MatCalendar', () => {
121
123
periodButton . click ( ) ;
122
124
fixture . detectChanges ( ) ;
123
125
124
- expect(calendarInstance._monthView ).toBe(false, 'should be in year view ');
126
+ expect ( calendarInstance . _currentView ) . toBe ( 'multi- year') ;
125
127
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
126
128
129
+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
130
+ fixture . detectChanges ( ) ;
131
+
132
+ expect ( calendarInstance . _currentView ) . toBe ( 'year' ) ;
133
+
127
134
nextButton . click ( ) ;
128
135
fixture . detectChanges ( ) ;
129
136
@@ -135,19 +142,26 @@ describe('MatCalendar', () => {
135
142
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
136
143
} ) ;
137
144
138
- it('should go back to month view after selecting month in year view ', () => {
145
+ it ( 'should go back to month view after selecting year and month ' , ( ) => {
139
146
periodButton . click ( ) ;
140
147
fixture . detectChanges ( ) ;
141
148
142
- expect(calendarInstance._monthView ).toBe(false, 'should be in year view ');
149
+ expect ( calendarInstance . _currentView ) . toBe ( 'multi- year') ;
143
150
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
144
151
152
+ let yearCells = calendarElement . querySelectorAll ( '.mat-calendar-body-cell' ) ;
153
+ ( < HTMLElement > yearCells [ 0 ] ) . click ( ) ;
154
+ fixture . detectChanges ( ) ;
155
+
156
+ expect ( calendarInstance . _currentView ) . toBe ( 'year' ) ;
157
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2016 , JAN , 31 ) ) ;
158
+
145
159
let monthCells = calendarElement . querySelectorAll ( '.mat-calendar-body-cell' ) ;
146
160
( monthCells [ monthCells . length - 1 ] as HTMLElement ) . click ( ) ;
147
161
fixture . detectChanges ( ) ;
148
162
149
- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
150
- expect(calendarInstance._activeDate).toEqual(new Date(2017 , DEC, 31));
163
+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
164
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2016 , DEC , 31 ) ) ;
151
165
expect ( testComponent . selected ) . toBeFalsy ( 'no date should be selected yet' ) ;
152
166
} ) ;
153
167
@@ -156,7 +170,7 @@ describe('MatCalendar', () => {
156
170
( monthCells [ monthCells . length - 1 ] as HTMLElement ) . click ( ) ;
157
171
fixture . detectChanges ( ) ;
158
172
159
- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
173
+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
160
174
expect ( testComponent . selected ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
161
175
} ) ;
162
176
@@ -165,11 +179,11 @@ describe('MatCalendar', () => {
165
179
const button = fixture . debugElement . nativeElement
166
180
. querySelector ( '.mat-calendar-period-button' ) ;
167
181
168
- intl.switchToYearViewLabel = 'Go to year view?';
182
+ intl . switchToMultiYearViewLabel = 'Go to multi- year view?' ;
169
183
intl . changes . next ( ) ;
170
184
fixture . detectChanges ( ) ;
171
185
172
- expect(button.getAttribute('aria-label')).toBe('Go to year view?');
186
+ expect ( button . getAttribute ( 'aria-label' ) ) . toBe ( 'Go to multi- year view?' ) ;
173
187
} ) ) ;
174
188
175
189
describe ( 'a11y' , ( ) => {
@@ -311,7 +325,12 @@ describe('MatCalendar', () => {
311
325
dispatchMouseEvent ( periodButton , 'click' ) ;
312
326
fixture . detectChanges ( ) ;
313
327
314
- expect(calendarInstance._monthView).toBe(false);
328
+ expect ( calendarInstance . _currentView ) . toBe ( 'multi-year' ) ;
329
+
330
+ ( < HTMLElement > calendarBodyEl . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
331
+ fixture . detectChanges ( ) ;
332
+
333
+ expect ( calendarInstance . _currentView ) . toBe ( 'year' ) ;
315
334
} ) ;
316
335
317
336
it ( 'should decrement month on left arrow press' , ( ) => {
@@ -342,46 +361,46 @@ describe('MatCalendar', () => {
342
361
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , UP_ARROW ) ;
343
362
fixture . detectChanges ( ) ;
344
363
345
- expect(calendarInstance._activeDate).toEqual(new Date(2016, AUG, 31 ));
364
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2016 , SEP , 30 ) ) ;
346
365
347
366
calendarInstance . _activeDate = new Date ( 2017 , JUL , 1 ) ;
348
367
fixture . detectChanges ( ) ;
349
368
350
369
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , UP_ARROW ) ;
351
370
fixture . detectChanges ( ) ;
352
371
353
- expect(calendarInstance._activeDate).toEqual(new Date(2016, JUL , 1));
372
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , MAR , 1 ) ) ;
354
373
355
374
calendarInstance . _activeDate = new Date ( 2017 , DEC , 10 ) ;
356
375
fixture . detectChanges ( ) ;
357
376
358
377
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , UP_ARROW ) ;
359
378
fixture . detectChanges ( ) ;
360
379
361
- expect(calendarInstance._activeDate).toEqual(new Date(2017, MAY , 10));
380
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , AUG , 10 ) ) ;
362
381
} ) ;
363
382
364
383
it ( 'should go down a row on down arrow press' , ( ) => {
365
384
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , DOWN_ARROW ) ;
366
385
fixture . detectChanges ( ) ;
367
386
368
- expect(calendarInstance._activeDate).toEqual(new Date(2017, AUG , 31));
387
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , MAY , 31 ) ) ;
369
388
370
389
calendarInstance . _activeDate = new Date ( 2017 , JUN , 1 ) ;
371
390
fixture . detectChanges ( ) ;
372
391
373
392
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , DOWN_ARROW ) ;
374
393
fixture . detectChanges ( ) ;
375
394
376
- expect(calendarInstance._activeDate).toEqual(new Date(2018, JUN , 1));
395
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , OCT , 1 ) ) ;
377
396
378
397
calendarInstance . _activeDate = new Date ( 2017 , SEP , 30 ) ;
379
398
fixture . detectChanges ( ) ;
380
399
381
400
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , DOWN_ARROW ) ;
382
401
fixture . detectChanges ( ) ;
383
402
384
- expect(calendarInstance._activeDate).toEqual(new Date(2018, FEB, 28 ));
403
+ expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2018 , JAN , 30 ) ) ;
385
404
} ) ;
386
405
387
406
it ( 'should go to first month of the year on home press' , ( ) => {
@@ -448,7 +467,7 @@ describe('MatCalendar', () => {
448
467
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
449
468
fixture . detectChanges ( ) ;
450
469
451
- expect(calendarInstance._monthView ).toBe(true );
470
+ expect ( calendarInstance . _currentView ) . toBe ( 'month' ) ;
452
471
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , FEB , 28 ) ) ;
453
472
expect ( testComponent . selected ) . toBeUndefined ( ) ;
454
473
} ) ;
@@ -557,6 +576,9 @@ describe('MatCalendar', () => {
557
576
periodButton . click ( ) ;
558
577
fixture . detectChanges ( ) ;
559
578
579
+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
580
+ fixture . detectChanges ( ) ;
581
+
560
582
spyOn ( calendarInstance . yearView , '_init' ) . and . callThrough ( ) ;
561
583
562
584
testComponent . minDate = new Date ( 2017 , NOV , 1 ) ;
@@ -572,6 +594,9 @@ describe('MatCalendar', () => {
572
594
periodButton . click ( ) ;
573
595
fixture . detectChanges ( ) ;
574
596
597
+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
598
+ fixture . detectChanges ( ) ;
599
+
575
600
spyOn ( calendarInstance . yearView , '_init' ) . and . callThrough ( ) ;
576
601
577
602
testComponent . maxDate = new Date ( 2017 , DEC , 1 ) ;
@@ -623,7 +648,7 @@ describe('MatCalendar', () => {
623
648
} ) ;
624
649
625
650
it ( 'should not allow selection of disabled date in month view' , ( ) => {
626
- expect(calendarInstance._monthView ).toBe(true );
651
+ expect ( calendarInstance . _currentView ) . toBe ( 'month' ) ;
627
652
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 1 ) ) ;
628
653
629
654
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
@@ -638,15 +663,18 @@ describe('MatCalendar', () => {
638
663
dispatchMouseEvent ( periodButton , 'click' ) ;
639
664
fixture . detectChanges ( ) ;
640
665
666
+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
667
+ fixture . detectChanges ( ) ;
668
+
641
669
calendarInstance . _activeDate = new Date ( 2017 , NOV , 1 ) ;
642
670
fixture . detectChanges ( ) ;
643
671
644
- expect(calendarInstance._monthView ).toBe(false );
672
+ expect ( calendarInstance . _currentView ) . toBe ( 'year' ) ;
645
673
646
674
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
647
675
fixture . detectChanges ( ) ;
648
676
649
- expect(calendarInstance._monthView ).toBe(true );
677
+ expect ( calendarInstance . _currentView ) . toBe ( 'month' ) ;
650
678
expect ( testComponent . selected ) . toBeUndefined ( ) ;
651
679
} ) ;
652
680
} ) ;
@@ -689,4 +717,3 @@ class CalendarWithDateFilter {
689
717
return date . getDate ( ) % 2 == 0 && date . getMonth ( ) != NOV ;
690
718
}
691
719
}
692
- */
0 commit comments