@@ -174,7 +174,8 @@ describe('IgxCalendar - ', () => {
174174 configureTestSuite ( ) ;
175175 beforeAll ( async ( ( ) => {
176176 TestBed . configureTestingModule ( {
177- declarations : [ IgxCalendarSampleComponent , IgxCalendarRangeComponent , IgxCalendarDisabledSpecialDatesComponent ] ,
177+ declarations : [ IgxCalendarSampleComponent , IgxCalendarRangeComponent , IgxCalendarDisabledSpecialDatesComponent ,
178+ IgxCalendarValueComponent ] ,
178179 imports : [ IgxCalendarModule , FormsModule , NoopAnimationsModule ]
179180 } ) . compileComponents ( ) ;
180181 } ) ) ;
@@ -291,6 +292,27 @@ describe('IgxCalendar - ', () => {
291292 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( '8' ) ;
292293 } ) ;
293294
295+ it ( 'Should show right month when value is set' , ( ) => {
296+ fixture = TestBed . createComponent ( IgxCalendarValueComponent ) ;
297+ fixture . detectChanges ( ) ;
298+ calendar = fixture . componentInstance . calendar ;
299+
300+ expect ( calendar . weekStart ) . toEqual ( WEEKDAYS . SUNDAY ) ;
301+ expect ( calendar . selection ) . toEqual ( 'single' ) ;
302+ expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( calendar . value . getMonth ( ) ) ;
303+
304+ const date = new Date ( 2020 , 8 , 28 ) ;
305+ calendar . viewDate = date ;
306+ fixture . detectChanges ( ) ;
307+
308+ expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( date . getMonth ( ) ) ;
309+
310+ calendar . value = new Date ( 2020 , 9 , 15 ) ;
311+ fixture . detectChanges ( ) ;
312+
313+ expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( date . getMonth ( ) ) ;
314+ } ) ;
315+
294316 it ( 'Should properly set locale' , ( ) => {
295317 fixture . componentInstance . viewDate = new Date ( 2018 , 8 , 17 ) ;
296318 fixture . componentInstance . model = new Date ( ) ;
@@ -1998,6 +2020,16 @@ export class IgxCalendarDisabledSpecialDatesComponent {
19982020 @ViewChild ( IgxCalendarComponent , { static : true } ) public calendar : IgxCalendarComponent ;
19992021}
20002022
2023+ @Component ( {
2024+ template : `
2025+ <igx-calendar [value]="value"></igx-calendar>
2026+ `
2027+ } )
2028+ export class IgxCalendarValueComponent {
2029+ public value = new Date ( 2020 , 7 , 13 ) ;
2030+ @ViewChild ( IgxCalendarComponent , { static : true } ) public calendar : IgxCalendarComponent ;
2031+ }
2032+
20012033class DateTester {
20022034 // tests whether a date is disabled or not
20032035 static testDatesAvailability ( dates : IgxDayItemComponent [ ] , disabled : boolean ) {
0 commit comments