Browse Source

Ignore invalid end date

Fix #9267
pull/9298/head
Wei Zhu 7 years ago
parent
commit
e992682aa8
  1. 3
      components/date-picker/RangePicker.tsx
  2. 13
      components/date-picker/__tests__/RangePicker.test.js
  3. 4
      components/date-picker/__tests__/utils.js

3
components/date-picker/RangePicker.tsx

@ -157,6 +157,9 @@ export default class RangePicker extends React.Component<any, RangePickerState>
}
handleCalendarInputSelect = (value: RangePickerValue) => {
if (!value[0]) {
return;
}
this.setState(({ showDate }) => ({
value,
showDate: getShowDateFromValue(value) || showDate,

13
components/date-picker/__tests__/RangePicker.test.js

@ -3,6 +3,7 @@ import { mount, render } from 'enzyme';
import moment from 'moment';
import DatePicker from '../';
import { setMockDate, resetMockDate } from '../../../tests/utils';
import { selectDate } from './utils';
import focusTest from '../../../tests/shared/focusTest';
const { RangePicker } = DatePicker;
@ -202,4 +203,16 @@ describe('RangePicker', () => {
wrapper.find('.ant-calendar-range-quick-selector a').simulate('click');
expect(handleOk).toBeCalledWith(range);
});
// https://github.com/ant-design/ant-design/issues/9267
it('invali end date not throw error', () => {
const wrapper = mount(<RangePicker />);
wrapper.find('.ant-calendar-picker-input').simulate('click');
selectDate(wrapper, moment('2017-09-18'), 0);
selectDate(wrapper, moment('2017-10-18'), 1);
wrapper.find('.ant-calendar-picker-input').simulate('click');
expect(() =>
wrapper.find('.ant-calendar-input').at(1).simulate('change', { target: { value: '2016-01-01' } })
).not.toThrow();
});
});

4
components/date-picker/__tests__/utils.js

@ -1,8 +1,8 @@
/* eslint-disable import/prefer-default-export */
export function selectDate(wrapper, date, index) {
let calendar = wrapper;
if (index) {
calendar = wrapper.find('.ant-calendar-range-part')[index];
if (index !== undefined) {
calendar = wrapper.find('.ant-calendar-range-part').at(index);
}
calendar.find({ title: date.format('LL'), role: 'gridcell' }).simulate('click');
}

Loading…
Cancel
Save