Skip to content

Commit

Permalink
Tests for block navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroabreu committed Nov 17, 2018
1 parent 1e0a2f0 commit ea7137a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/components/DayPickerNavigation_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,25 @@ describe('DayPickerNavigation', () => {
nextMonthButton.simulate('click');
expect(onNextMonthStub).to.have.property('callCount', 1);
});

it('props.onPrevMonthClick is not triggered by prev month disabled click', () => {
const onPrevMonthStub = sinon.stub();
const prevMonthButton = shallow(<DayPickerNavigation
onPrevMonthClick={onPrevMonthStub}
hasPrev={false}
/>).dive().find('[role="button"]').at(0);
prevMonthButton.simulate('click');
expect(onPrevMonthStub).to.have.property('callCount', 0);
});

it('props.onNextMonthClick is not triggered by prev month disabled click', () => {
const onNextMonthStub = sinon.stub();
const nextMonthButton = shallow(<DayPickerNavigation
onNextMonthClick={onNextMonthStub}
hasNext={false}
/>).dive().find('[role="button"]').at(1);
nextMonthButton.simulate('click');
expect(onNextMonthStub).to.have.property('callCount', 0);
});
});
});
66 changes: 66 additions & 0 deletions test/components/DayPickerRangeController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,72 @@ describe('DayPickerRangeController', () => {
expect(onPrevMonthClickStub.firstCall.args[0].year()).to.equal(newMonth.year());
expect(onPrevMonthClickStub.firstCall.args[0].month()).to.equal(newMonth.month());
});

it('calls this.getNavigationStatus', () => {
const getNavigationStatusSpy = sinon.spy(DayPickerRangeController.prototype, 'getNavigationStatus');
const wrapper = shallow((
<DayPickerRangeController
onDatesChange={sinon.stub()}
onFocusChange={sinon.stub()}
/>
));
getNavigationStatusSpy.resetHistory();
wrapper.instance().onPrevMonthClick();
expect(getNavigationStatusSpy.callCount).to.equal(1);
});

it('sets hasNext and hasPrev on onPrevMonthClick call withouth maxDate and minDate set', () => {
const numberOfMonths = 2;
const wrapper = shallow((
<DayPickerRangeController
onDatesChange={sinon.stub()}
onFocusChange={sinon.stub()}
numberOfMonths={numberOfMonths}
/>
));
wrapper.setState({
currentMonth: today,
});
wrapper.instance().onPrevMonthClick();
expect(wrapper.state().hasNext).to.equal(true);
expect(wrapper.state().hasPrev).to.equal(true);
});

it('sets hasNext as false when maxDate is in visible month', () => {
const numberOfMonths = 2;
const wrapper = shallow((
<DayPickerRangeController
onDatesChange={sinon.stub()}
onFocusChange={sinon.stub()}
numberOfMonths={numberOfMonths}
maxDate={today}
/>
));
wrapper.setState({
currentMonth: today,
});
wrapper.instance().onPrevMonthClick();
expect(wrapper.state().hasNext).to.equal(false);
expect(wrapper.state().hasPrev).to.equal(true);
});

it('sets hasPrev as false when minDate is in visible month', () => {
const numberOfMonths = 2;
const wrapper = shallow((
<DayPickerRangeController
onDatesChange={sinon.stub()}
onFocusChange={sinon.stub()}
numberOfMonths={numberOfMonths}
minDate={today.clone().subtract(1, 'month')}
/>
));
wrapper.setState({
currentMonth: today,
});
wrapper.instance().onPrevMonthClick();
expect(wrapper.state().hasNext).to.equal(true);
expect(wrapper.state().hasPrev).to.equal(false);
});
});

describe('#onNextMonthClick', () => {
Expand Down

0 comments on commit ea7137a

Please sign in to comment.