Skip to content

Commit 3dd3118

Browse files
author
Matt Lewis
committed
fix(monthView): only call beforeViewRender once when refreshing the view
Closes #293
1 parent 712ded8 commit 3dd3118

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/components/month/calendarMonthView.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ export class CalendarMonthViewComponent
345345
}
346346

347347
private refreshAll(): void {
348+
this.columnHeaders = null;
349+
this.view = null;
348350
this.refreshHeader();
349351
this.refreshBody();
350352
this.checkActiveDayIsOpen();

test/calendarMonthView.component.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@angular/core/testing';
88
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
99
import * as moment from 'moment';
10+
import * as sinon from 'sinon';
1011
import { expect } from 'chai';
1112
import { spy } from 'sinon';
1213
import {
@@ -722,4 +723,22 @@ describe('calendarMonthView component', () => {
722723
expect(headerCells[6].classList.contains('cal-weekend')).to.equal(true);
723724
fixture.destroy();
724725
});
726+
727+
it('should only call the beforeViewRender output once when refreshing the view', () => {
728+
const fixture: ComponentFixture<
729+
CalendarMonthViewComponent
730+
> = TestBed.createComponent(CalendarMonthViewComponent);
731+
fixture.componentInstance.refresh = new Subject();
732+
fixture.componentInstance.ngOnInit();
733+
fixture.componentInstance.viewDate = new Date('2016-06-27');
734+
fixture.componentInstance.ngOnChanges({ viewDate: {} });
735+
const beforeViewRenderCalled = sinon.spy();
736+
const subscription = fixture.componentInstance.beforeViewRender.subscribe(
737+
beforeViewRenderCalled
738+
);
739+
fixture.componentInstance.refresh.next(true);
740+
expect(beforeViewRenderCalled).to.have.callCount(1);
741+
subscription.unsubscribe();
742+
fixture.destroy();
743+
});
725744
});

0 commit comments

Comments
 (0)