Skip to content

Commit

Permalink
Added the passing down from SingleDatePicker to DayPickerSingleDateCo…
Browse files Browse the repository at this point in the history
…ntroller the keepOpenOnDateSelect prop
  • Loading branch information
Erin Doyle committed Jul 6, 2017
1 parent d091b08 commit f41548f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/components/SingleDatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export default class SingleDatePicker extends React.Component {
navNext,
withPortal,
withFullScreenPortal,
keepOpenOnDateSelect,
initialVisibleMonth,
renderMonth,
renderDay,
Expand Down Expand Up @@ -344,6 +345,7 @@ export default class SingleDatePicker extends React.Component {
monthFormat={monthFormat}
withPortal={withPortal || withFullScreenPortal}
focused={focused}
keepOpenOnDateSelect={keepOpenOnDateSelect}
hideKeyboardShortcutsPanel={hideKeyboardShortcutsPanel}
initialVisibleMonth={initialVisibleMonth}
navPrev={navPrev}
Expand Down
77 changes: 55 additions & 22 deletions test/components/DayPickerSingleDateController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,30 +500,63 @@ describe('DayPickerSingleDateController', () => {
expect(onDateChangeStub.callCount).to.equal(1);
});

it('props.onFocusChange is called', () => {
const onFocusChangeStub = sinon.stub();
const wrapper = shallow(
<DayPickerSingleDateController
onDateChange={() => {}}
onFocusChange={onFocusChangeStub}
/>,
);
wrapper.instance().onDayClick(moment());
expect(onFocusChangeStub.callCount).to.equal(1);
});
describe('props.keepOpenOnDateSelect is false', () => {
it('props.onFocusChange is called', () => {
const onFocusChangeStub = sinon.stub();
const wrapper = shallow(
<DayPickerSingleDateController
onDateChange={() => {}}
onFocusChange={onFocusChangeStub}
keepOpenOnDateSelect={false}
/>,
);
wrapper.instance().onDayClick(moment());
expect(onFocusChangeStub.callCount).to.equal(1);
});

it('props.onClose is called', () => {
const onCloseStub = sinon.stub();
const wrapper = shallow(
<DayPickerSingleDateController
onDateChange={() => {}}
onFocusChange={() => {}}
onClose={onCloseStub}
/>,
);
wrapper.instance().onDayClick(moment());
expect(onCloseStub.callCount).to.equal(1);
it('props.onClose is called', () => {
const onCloseStub = sinon.stub();
const wrapper = shallow(
<DayPickerSingleDateController
onDateChange={() => {}}
onFocusChange={() => {}}
onClose={onCloseStub}
keepOpenOnDateSelect={false}
/>,
);
wrapper.instance().onDayClick(moment());
expect(onCloseStub.callCount).to.equal(1);
});
});

describe('props.keepOpenOnDateSelect is true', () => {
it('props.onFocusChange is not called', () => {
const onFocusChangeStub = sinon.stub();
const wrapper = shallow(
<DayPickerSingleDateController
onDateChange={() => {}}
onFocusChange={onFocusChangeStub}
keepOpenOnDateSelect={true}
/>,
);
wrapper.instance().onDayClick(moment());
expect(onFocusChangeStub.callCount).to.equal(0);
});

it('props.onClose is not called', () => {
const onCloseStub = sinon.stub();
const wrapper = shallow(
<DayPickerSingleDateController
onDateChange={() => {}}
onFocusChange={() => {}}
onClose={onCloseStub}
keepOpenOnDateSelect={true}
/>,
);
wrapper.instance().onDayClick(moment());
expect(onCloseStub.callCount).to.equal(0);
});
});
});
});

Expand Down

0 comments on commit f41548f

Please sign in to comment.