Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear renderCalendarInfo timeout before assigning a new timeout (#1323) #2021

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/DayPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ class DayPicker extends React.PureComponent {
// breaks the CSS transition.
// The setTimeout will wait until the transition ends.
if (this.calendarInfo) {
clearTimeout(this.setCalendarInfoWidthTimeout);

this.setCalendarInfoWidthTimeout = setTimeout(() => {
const { calendarInfoWidth } = this.state;
const calendarInfoPanelWidth = calculateDimension(this.calendarInfo, 'width', true, true);
Expand Down
39 changes: 29 additions & 10 deletions test/components/DayPicker_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import moment from 'moment/min/moment-with-locales';
import { expect } from 'chai';
import sinon from 'sinon-sandbox';
import wrap from 'mocha-wrap';
import { mount, shallow } from 'enzyme';

import * as isDayVisible from '../../src/utils/isDayVisible';
Expand All @@ -22,8 +23,9 @@ const today = moment().locale('en');
const event = { preventDefault() {}, stopPropagation() {} };

describe('DayPicker', () => {
let adjustDayPickerHeightSpy;
beforeEach(() => {
sinon.stub(PureDayPicker.prototype, 'adjustDayPickerHeight');
adjustDayPickerHeightSpy = sinon.stub(PureDayPicker.prototype, 'adjustDayPickerHeight');
});

afterEach(() => {
Expand Down Expand Up @@ -892,13 +894,8 @@ describe('DayPicker', () => {
});
});

describe.skip('life cycle methods', () => {
let adjustDayPickerHeightSpy;
beforeEach(() => {
adjustDayPickerHeightSpy = sinon.stub(PureDayPicker.prototype, 'adjustDayPickerHeight');
});

describe('#componentDidMount', () => {
describe('life cycle methods', () => {
describe.skip('#componentDidMount', () => {
describe('props.orientation === HORIZONTAL_ORIENTATION', () => {
it('calls adjustDayPickerHeight', () => {
mount(<DayPicker orientation={HORIZONTAL_ORIENTATION} />);
Expand Down Expand Up @@ -934,7 +931,7 @@ describe('DayPicker', () => {
});
});

describe('#componentWillReceiveProps', () => {
describe.skip('#componentWillReceiveProps', () => {
describe('props.orientation === VERTICAL_SCROLLABLE', () => {
it('updates state.currentMonthScrollTop', () => {
sinon.spy(DayPicker.prototype, 'setTransitionContainerRef');
Expand All @@ -949,7 +946,29 @@ describe('DayPicker', () => {
});
});

describe('#componentDidUpdate', () => {
wrap()
.withGlobal('window', () => ({ getComputedStyle: sinon.stub().returns({}) }))
.describe('#componentWillUpdate', () => {
it('clears timeouts appropriately', (done) => {
const wrapper = shallow(<DayPicker />).dive();
const instance = wrapper.instance();
instance.calendarInfo = 'something';
expect(instance).to.have.property('setCalendarInfoWidthTimeout', null);

// trigger a componentWillUpdate by setting state.
wrapper.setState({ calendarInfoWidth: 1 });

// this.setCalendarInfoWidthTimeout is no longer null.
expect(instance).not.to.have.property('setCalendarInfoWidthTimeout', null);

setTimeout(() => {
expect(window.getComputedStyle).to.have.property('callCount', 1);
done();
}, 1);
});
});

describe.skip('#componentDidUpdate', () => {
let updateStateAfterMonthTransitionSpy;
beforeEach(() => {
updateStateAfterMonthTransitionSpy = sinon.stub(
Expand Down