@@ -27,6 +27,7 @@ import {
27
27
SEP ,
28
28
} from '@angular/material/core' ;
29
29
import { By } from '@angular/platform-browser' ;
30
+ import { Direction , Directionality } from '@angular/cdk/bidi' ;
30
31
import { MatButtonModule } from '../button/index' ;
31
32
import { MatCalendar } from './calendar' ;
32
33
import { MatCalendarBody } from './calendar-body' ;
@@ -37,6 +38,8 @@ import {MatYearView} from './year-view';
37
38
38
39
39
40
describe ( 'MatCalendar' , ( ) => {
41
+ let dir : { value : Direction } ;
42
+
40
43
beforeEach ( async ( ( ) => {
41
44
TestBed . configureTestingModule ( {
42
45
imports : [
@@ -57,6 +60,7 @@ describe('MatCalendar', () => {
57
60
] ,
58
61
providers : [
59
62
MatDatepickerIntl ,
63
+ { provide : Directionality , useFactory : ( ) => dir = { value : 'ltr' } }
60
64
] ,
61
65
} ) ;
62
66
@@ -240,6 +244,20 @@ describe('MatCalendar', () => {
240
244
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2016 , DEC , 31 ) ) ;
241
245
} ) ;
242
246
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
+
243
261
it ( 'should increment date on right arrow press' , ( ) => {
244
262
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , RIGHT_ARROW ) ;
245
263
fixture . detectChanges ( ) ;
@@ -252,6 +270,23 @@ describe('MatCalendar', () => {
252
270
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , FEB , 2 ) ) ;
253
271
} ) ;
254
272
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
+
255
290
it ( 'should go up a row on up arrow press' , ( ) => {
256
291
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , UP_ARROW ) ;
257
292
fixture . detectChanges ( ) ;
@@ -367,6 +402,20 @@ describe('MatCalendar', () => {
367
402
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2016 , NOV , 30 ) ) ;
368
403
} ) ;
369
404
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
+
370
419
it ( 'should increment month on right arrow press' , ( ) => {
371
420
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , RIGHT_ARROW ) ;
372
421
fixture . detectChanges ( ) ;
@@ -379,6 +428,20 @@ describe('MatCalendar', () => {
379
428
expect ( calendarInstance . _activeDate ) . toEqual ( new Date ( 2017 , MAR , 28 ) ) ;
380
429
} ) ;
381
430
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
+
382
445
it ( 'should go up a row on up arrow press' , ( ) => {
383
446
dispatchKeyboardEvent ( calendarBodyEl , 'keydown' , UP_ARROW ) ;
384
447
fixture . detectChanges ( ) ;
0 commit comments