@@ -172,7 +172,8 @@ describe('IgxCalendar - ', () => {
172172 configureTestSuite ( ) ;
173173 beforeAll ( async ( ( ) => {
174174 TestBed . configureTestingModule ( {
175- declarations : [ IgxCalendarSampleComponent , IgxCalendarRangeComponent , IgxCalendarDisabledSpecialDatesComponent ] ,
175+ declarations : [ IgxCalendarSampleComponent , IgxCalendarRangeComponent , IgxCalendarDisabledSpecialDatesComponent ,
176+ IgxCalendarValueComponent ] ,
176177 imports : [ IgxCalendarModule , FormsModule , NoopAnimationsModule ]
177178 } ) . compileComponents ( ) ;
178179 } ) ) ;
@@ -252,8 +253,8 @@ describe('IgxCalendar - ', () => {
252253 expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( defaultOptions ) ) ;
253254 expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( defaultViews ) ) ;
254255 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
255- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
256- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 17 ' ) ;
256+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
257+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 1 ' ) ;
257258 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
258259 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
259260
@@ -267,8 +268,8 @@ describe('IgxCalendar - ', () => {
267268 expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultOptions , formatOptions ) ) ) ;
268269 expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultViews , formatViews ) ) ) ;
269270 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
270- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
271- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 17 ' ) ;
271+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
272+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 1 ' ) ;
272273 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
273274 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'September' ) ;
274275
@@ -283,12 +284,33 @@ describe('IgxCalendar - ', () => {
283284 expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultOptions , formatOptions ) ) ) ;
284285 expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultViews , formatViews ) ) ) ;
285286 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
286- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
287- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 17 ' ) ;
287+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
288+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 1 ' ) ;
288289 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
289290 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( '8' ) ;
290291 } ) ;
291292
293+ it ( 'Should show right month when value is set' , ( ) => {
294+ fixture = TestBed . createComponent ( IgxCalendarValueComponent ) ;
295+ fixture . detectChanges ( ) ;
296+ calendar = fixture . componentInstance . calendar ;
297+
298+ expect ( calendar . weekStart ) . toEqual ( WEEKDAYS . SUNDAY ) ;
299+ expect ( calendar . selection ) . toEqual ( 'single' ) ;
300+ expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( calendar . value . getMonth ( ) ) ;
301+
302+ const date = new Date ( 2020 , 8 , 28 ) ;
303+ calendar . viewDate = date ;
304+ fixture . detectChanges ( ) ;
305+
306+ expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( date . getMonth ( ) ) ;
307+
308+ calendar . value = new Date ( 2020 , 9 , 15 ) ;
309+ fixture . detectChanges ( ) ;
310+
311+ expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( date . getMonth ( ) ) ;
312+ } ) ;
313+
292314 it ( 'Should properly set locale' , ( ) => {
293315 fixture . componentInstance . viewDate = new Date ( 2018 , 8 , 17 ) ;
294316 fixture . componentInstance . model = new Date ( ) ;
@@ -305,8 +327,8 @@ describe('IgxCalendar - ', () => {
305327 fixture . detectChanges ( ) ;
306328
307329 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
308- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
309- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 17 ' ) ;
330+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
331+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 1 ' ) ;
310332 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
311333 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
312334 expect ( bodyWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sun' ) ;
@@ -319,8 +341,8 @@ describe('IgxCalendar - ', () => {
319341 bodyWeekday = dom . query ( By . css ( HelperTestFunctions . WEEKSTART_LABEL_CSSCLASS ) ) ;
320342 expect ( calendar . locale ) . toEqual ( locale ) ;
321343 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
322- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'lun .,' ) ;
323- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( '17 sept.' ) ;
344+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'sam .,' ) ;
345+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( '1 sept.' ) ;
324346 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
325347 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'sept.' ) ;
326348 expect ( bodyWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Dim.' ) ;
@@ -1932,6 +1954,16 @@ export class IgxCalendarDisabledSpecialDatesComponent {
19321954 @ViewChild ( IgxCalendarComponent , { static : true } ) public calendar : IgxCalendarComponent ;
19331955}
19341956
1957+ @Component ( {
1958+ template : `
1959+ <igx-calendar [value]="value"></igx-calendar>
1960+ `
1961+ } )
1962+ export class IgxCalendarValueComponent {
1963+ public value = new Date ( 2020 , 7 , 13 ) ;
1964+ @ViewChild ( IgxCalendarComponent , { static : true } ) public calendar : IgxCalendarComponent ;
1965+ }
1966+
19351967class DateTester {
19361968 // tests whether a date is disabled or not
19371969 static testDatesAvailability ( dates : IgxDayItemComponent [ ] , disabled : boolean ) {
0 commit comments