From: Antony Shaleynikov Date: Wed, 8 Mar 2017 19:50:57 +0000 (+0300) Subject: Fixed unwanted exception on missed value X-Git-Tag: 2.3.1~1^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=4f26f23b14ec9f1aa6260b1eee9a190639530b45;p=github%2Ffretlink%2Ftime-picker.git Fixed unwanted exception on missed value --- diff --git a/src/Combobox.jsx b/src/Combobox.jsx index 36b61cc..477c5ee 100644 --- a/src/Combobox.jsx +++ b/src/Combobox.jsx @@ -170,7 +170,7 @@ const Combobox = React.createClass({ }, isAM() { - const { value } = this.props; + const value = (this.props.value || this.props.defaultOpenValue); return value.hour() >= 0 && value.hour() < 12; }, diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx index 1ea3b8b..6f9ac2d 100644 --- a/tests/TimePicker.spec.jsx +++ b/tests/TimePicker.spec.jsx @@ -174,4 +174,38 @@ describe('TimePicker', () => { }); }); }); + + describe('render panel to body 12pm mode', () => { + it('popup correctly', (done) => { + let change; + const picker = renderPickerWithoutSeconds({ + use12Hours: true, + value: null, + onChange(v) { + change = v; + }, + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + expect((input).value).to.be(''); + async.series([(next) => { + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-inner')[0]).to.be.ok(); + expect(picker.state.open).to.be(true); + const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; + Simulate.click(hour); + setTimeout(next, 100); + }, (next) => { + expect(change).to.be.ok(); + expect(picker.state.open).to.be.ok(); + next(); + }], () => { + done(); + }); + }); + }); });