11import { Direction , Directionality } from '@angular/cdk/bidi' ;
2- import { ENTER , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
2+ import { ENTER , RIGHT_ARROW , SPACE } from '@angular/cdk/keycodes' ;
33import {
44 dispatchFakeEvent ,
55 dispatchKeyboardEvent ,
@@ -230,6 +230,20 @@ describe('MatCalendar', () => {
230230 expect ( calendarInstance . activeDate ) . toEqual ( new Date ( 2017 , FEB , 28 ) ) ;
231231 expect ( testComponent . selected ) . toBeUndefined ( ) ;
232232 } ) ;
233+
234+ it ( 'should return to month view on space' , ( ) => {
235+ const tableBodyEl = calendarBodyEl . querySelector ( '.mat-calendar-body' ) as HTMLElement ;
236+
237+ dispatchKeyboardEvent ( tableBodyEl , 'keydown' , RIGHT_ARROW ) ;
238+ fixture . detectChanges ( ) ;
239+
240+ dispatchKeyboardEvent ( tableBodyEl , 'keydown' , SPACE ) ;
241+ fixture . detectChanges ( ) ;
242+
243+ expect ( calendarInstance . currentView ) . toBe ( 'month' ) ;
244+ expect ( calendarInstance . activeDate ) . toEqual ( new Date ( 2017 , FEB , 28 ) ) ;
245+ expect ( testComponent . selected ) . toBeUndefined ( ) ;
246+ } ) ;
233247 } ) ;
234248
235249 describe ( 'multi-year view' , ( ) => {
@@ -253,6 +267,21 @@ describe('MatCalendar', () => {
253267 expect ( calendarInstance . activeDate ) . toEqual ( new Date ( 2018 , JAN , 31 ) ) ;
254268 expect ( testComponent . selected ) . toBeUndefined ( ) ;
255269 } ) ;
270+
271+ it ( 'should go to year view on space' , ( ) => {
272+ const tableBodyEl = calendarBodyEl . querySelector ( '.mat-calendar-body' ) as HTMLElement ;
273+
274+ dispatchKeyboardEvent ( tableBodyEl , 'keydown' , RIGHT_ARROW ) ;
275+ fixture . detectChanges ( ) ;
276+
277+ dispatchKeyboardEvent ( tableBodyEl , 'keydown' , SPACE ) ;
278+ fixture . detectChanges ( ) ;
279+
280+ expect ( calendarInstance . currentView ) . toBe ( 'year' ) ;
281+ expect ( calendarInstance . activeDate ) . toEqual ( new Date ( 2018 , JAN , 31 ) ) ;
282+ expect ( testComponent . selected ) . toBeUndefined ( ) ;
283+ } ) ;
284+
256285 } ) ;
257286
258287 } ) ;
0 commit comments