1- /*
21import {
32 DOWN_ARROW ,
43 END ,
@@ -33,6 +32,7 @@ import {MatCalendar} from './calendar';
3332import { MatCalendarBody } from './calendar-body' ;
3433import { MatDatepickerIntl } from './datepicker-intl' ;
3534import { MatMonthView } from './month-view' ;
35+ import { MatMultiYearView } from './multi-year-view' ;
3636import { MatYearView } from './year-view' ;
3737
3838
@@ -48,6 +48,7 @@ describe('MatCalendar', () => {
4848 MatCalendarBody ,
4949 MatMonthView ,
5050 MatYearView ,
51+ MatMultiYearView ,
5152
5253 // Test components.
5354 StandardCalendar ,
@@ -86,22 +87,22 @@ describe('MatCalendar', () => {
8687 } ) ;
8788
8889 it ( 'should be in month view with specified month active' , ( ) => {
89- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
90+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
9091 expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
9192 } ) ;
9293
9394 it ( 'should toggle view when period clicked' , ( ) => {
94- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
95+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
9596
9697 periodButton . click ( ) ;
9798 fixture . detectChanges ( ) ;
9899
99- expect(calendarInstance._monthView ).toBe(false, 'should be in year view ');
100+ expect ( calendarInstance . _currentView ) . toBe ( 'multi- year') ;
100101
101102 periodButton . click ( ) ;
102103 fixture . detectChanges ( ) ;
103104
104- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
105+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
105106 } ) ;
106107
107108 it ( 'should go to next and previous month' , ( ) => {
@@ -122,9 +123,14 @@ describe('MatCalendar', () => {
122123 periodButton . click ( ) ;
123124 fixture . detectChanges ( ) ;
124125
125- expect(calendarInstance._monthView ).toBe(false, 'should be in year view ');
126+ expect ( calendarInstance . _currentView ) . toBe ( 'multi- year') ;
126127 expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
127128
129+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
130+ fixture . detectChanges ( ) ;
131+
132+ expect ( calendarInstance . _currentView ) . toBe ( 'year' ) ;
133+
128134 nextButton . click ( ) ;
129135 fixture . detectChanges ( ) ;
130136
@@ -136,19 +142,26 @@ describe('MatCalendar', () => {
136142 expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
137143 } ) ;
138144
139- 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 ' , ( ) => {
140146 periodButton . click ( ) ;
141147 fixture . detectChanges ( ) ;
142148
143- expect(calendarInstance._monthView ).toBe(false, 'should be in year view ');
149+ expect ( calendarInstance . _currentView ) . toBe ( 'multi- year') ;
144150 expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
145151
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+
146159 let monthCells = calendarElement . querySelectorAll ( '.mat-calendar-body-cell' ) ;
147160 ( monthCells [ monthCells . length - 1 ] as HTMLElement ) . click ( ) ;
148161 fixture . detectChanges ( ) ;
149162
150- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
151- 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 ) ) ;
152165 expect ( testComponent . selected ) . toBeFalsy ( 'no date should be selected yet' ) ;
153166 } ) ;
154167
@@ -157,7 +170,7 @@ describe('MatCalendar', () => {
157170 ( monthCells [ monthCells . length - 1 ] as HTMLElement ) . click ( ) ;
158171 fixture . detectChanges ( ) ;
159172
160- expect(calendarInstance._monthView ).toBe(true, 'should be in month view ');
173+ expect ( calendarInstance . _currentView ) . toBe ( ' month') ;
161174 expect ( testComponent . selected ) . toEqual ( new Date ( 2017 , JAN , 31 ) ) ;
162175 } ) ;
163176
@@ -166,11 +179,11 @@ describe('MatCalendar', () => {
166179 const button = fixture . debugElement . nativeElement
167180 . querySelector ( '.mat-calendar-period-button' ) ;
168181
169- intl.switchToYearViewLabel = 'Go to year view?';
182+ intl . switchToMultiYearViewLabel = 'Go to multi- year view?' ;
170183 intl . changes . next ( ) ;
171184 fixture . detectChanges ( ) ;
172185
173- expect(button.getAttribute('aria-label')).toBe('Go to year view?');
186+ expect ( button . getAttribute ( 'aria-label' ) ) . toBe ( 'Go to multi- year view?' ) ;
174187 } ) ) ;
175188
176189 describe ( 'a11y' , ( ) => {
@@ -312,7 +325,12 @@ describe('MatCalendar', () => {
312325 dispatchMouseEvent ( periodButton , 'click' ) ;
313326 fixture . detectChanges ( ) ;
314327
315- 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' ) ;
316334 } ) ;
317335
318336 it ( 'should decrement month on left arrow press' , ( ) => {
@@ -449,7 +467,7 @@ describe('MatCalendar', () => {
449467 dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
450468 fixture . detectChanges ( ) ;
451469
452- expect(calendarInstance._monthView ).toBe(true );
470+ expect ( calendarInstance . _currentView ) . toBe ( 'month' ) ;
453471 expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , FEB , 28 ) ) ;
454472 expect ( testComponent . selected ) . toBeUndefined ( ) ;
455473 } ) ;
@@ -558,6 +576,9 @@ describe('MatCalendar', () => {
558576 periodButton . click ( ) ;
559577 fixture . detectChanges ( ) ;
560578
579+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
580+ fixture . detectChanges ( ) ;
581+
561582 spyOn ( calendarInstance . yearView , '_init' ) . and . callThrough ( ) ;
562583
563584 testComponent . minDate = new Date ( 2017 , NOV , 1 ) ;
@@ -573,6 +594,9 @@ describe('MatCalendar', () => {
573594 periodButton . click ( ) ;
574595 fixture . detectChanges ( ) ;
575596
597+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
598+ fixture . detectChanges ( ) ;
599+
576600 spyOn ( calendarInstance . yearView , '_init' ) . and . callThrough ( ) ;
577601
578602 testComponent . maxDate = new Date ( 2017 , DEC , 1 ) ;
@@ -624,7 +648,7 @@ describe('MatCalendar', () => {
624648 } ) ;
625649
626650 it ( 'should not allow selection of disabled date in month view' , ( ) => {
627- expect(calendarInstance._monthView ).toBe(true );
651+ expect ( calendarInstance . _currentView ) . toBe ( 'month' ) ;
628652 expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , JAN , 1 ) ) ;
629653
630654 dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
@@ -639,15 +663,18 @@ describe('MatCalendar', () => {
639663 dispatchMouseEvent ( periodButton , 'click' ) ;
640664 fixture . detectChanges ( ) ;
641665
666+ ( < HTMLElement > calendarElement . querySelector ( '.mat-calendar-body-active' ) ) . click ( ) ;
667+ fixture . detectChanges ( ) ;
668+
642669 calendarInstance . _activeDate = new Date ( 2017 , NOV , 1 ) ;
643670 fixture . detectChanges ( ) ;
644671
645- expect(calendarInstance._monthView ).toBe(false );
672+ expect ( calendarInstance . _currentView ) . toBe ( 'year' ) ;
646673
647674 dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , ENTER ) ;
648675 fixture . detectChanges ( ) ;
649676
650- expect(calendarInstance._monthView ).toBe(true );
677+ expect ( calendarInstance . _currentView ) . toBe ( 'month' ) ;
651678 expect ( testComponent . selected ) . toBeUndefined ( ) ;
652679 } ) ;
653680 } ) ;
@@ -690,4 +717,3 @@ class CalendarWithDateFilter {
690717 return date . getDate ( ) % 2 == 0 && date . getMonth ( ) != NOV ;
691718 }
692719}
693- */
0 commit comments