@@ -27,6 +27,7 @@ import {
2727  SEP , 
2828}  from  '@angular/material/core' ; 
2929import  { By }  from  '@angular/platform-browser' ; 
30+ import  { Direction ,  Directionality }  from  '@angular/cdk/bidi' ; 
3031import  { MatButtonModule }  from  '../button/index' ; 
3132import  { MatCalendar }  from  './calendar' ; 
3233import  { MatCalendarBody }  from  './calendar-body' ; 
@@ -37,6 +38,8 @@ import {MatYearView} from './year-view';
3738
3839
3940describe ( 'MatCalendar' ,  ( )  =>  { 
41+   let  dir : { value : Direction } ; 
42+ 
4043  beforeEach ( async ( ( )  =>  { 
4144    TestBed . configureTestingModule ( { 
4245      imports : [ 
@@ -57,6 +60,7 @@ describe('MatCalendar', () => {
5760      ] , 
5861      providers : [ 
5962        MatDatepickerIntl , 
63+         { provide : Directionality ,  useFactory : ( )  =>  dir  =  { value : 'ltr' } } 
6064      ] , 
6165    } ) ; 
6266
@@ -240,6 +244,20 @@ describe('MatCalendar', () => {
240244            expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2016 ,  DEC ,  31 ) ) ; 
241245          } ) ; 
242246
247+           it ( 'should increment date on left arrow press in rtl' ,  ( )  =>  { 
248+             dir . value  =  'rtl' ; 
249+ 
250+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  LEFT_ARROW ) ; 
251+             fixture . detectChanges ( ) ; 
252+ 
253+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  FEB ,  1 ) ) ; 
254+ 
255+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  LEFT_ARROW ) ; 
256+             fixture . detectChanges ( ) ; 
257+ 
258+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  FEB ,  2 ) ) ; 
259+           } ) ; 
260+ 
243261          it ( 'should increment date on right arrow press' ,  ( )  =>  { 
244262            dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  RIGHT_ARROW ) ; 
245263            fixture . detectChanges ( ) ; 
@@ -252,6 +270,23 @@ describe('MatCalendar', () => {
252270            expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  FEB ,  2 ) ) ; 
253271          } ) ; 
254272
273+           it ( 'should decrement date on right arrow press in rtl' ,  ( )  =>  { 
274+             dir . value  =  'rtl' ; 
275+ 
276+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  RIGHT_ARROW ) ; 
277+             fixture . detectChanges ( ) ; 
278+ 
279+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  JAN ,  30 ) ) ; 
280+ 
281+             calendarInstance . _activeDate  =  new  Date ( 2017 ,  JAN ,  1 ) ; 
282+             fixture . detectChanges ( ) ; 
283+ 
284+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  RIGHT_ARROW ) ; 
285+             fixture . detectChanges ( ) ; 
286+ 
287+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2016 ,  DEC ,  31 ) ) ; 
288+           } ) ; 
289+ 
255290          it ( 'should go up a row on up arrow press' ,  ( )  =>  { 
256291            dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  UP_ARROW ) ; 
257292            fixture . detectChanges ( ) ; 
@@ -367,6 +402,20 @@ describe('MatCalendar', () => {
367402            expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2016 ,  NOV ,  30 ) ) ; 
368403          } ) ; 
369404
405+           it ( 'should increment month on left arrow press in rtl' ,  ( )  =>  { 
406+             dir . value  =  'rtl' ; 
407+ 
408+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  LEFT_ARROW ) ; 
409+             fixture . detectChanges ( ) ; 
410+ 
411+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  FEB ,  28 ) ) ; 
412+ 
413+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  LEFT_ARROW ) ; 
414+             fixture . detectChanges ( ) ; 
415+ 
416+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  MAR ,  28 ) ) ; 
417+           } ) ; 
418+ 
370419          it ( 'should increment month on right arrow press' ,  ( )  =>  { 
371420            dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  RIGHT_ARROW ) ; 
372421            fixture . detectChanges ( ) ; 
@@ -379,6 +428,20 @@ describe('MatCalendar', () => {
379428            expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2017 ,  MAR ,  28 ) ) ; 
380429          } ) ; 
381430
431+           it ( 'should decrement month on right arrow press in rtl' ,  ( )  =>  { 
432+             dir . value  =  'rtl' ; 
433+ 
434+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  RIGHT_ARROW ) ; 
435+             fixture . detectChanges ( ) ; 
436+ 
437+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2016 ,  DEC ,  31 ) ) ; 
438+ 
439+             dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  RIGHT_ARROW ) ; 
440+             fixture . detectChanges ( ) ; 
441+ 
442+             expect ( calendarInstance . _activeDate ) . toEqual ( new  Date ( 2016 ,  NOV ,  30 ) ) ; 
443+           } ) ; 
444+ 
382445          it ( 'should go up a row on up arrow press' ,  ( )  =>  { 
383446            dispatchKeyboardEvent ( calendarBodyEl ,  'keydown' ,  UP_ARROW ) ; 
384447            fixture . detectChanges ( ) ; 
0 commit comments