2017-01-19 13:55:04 +08:00
|
|
|
import React from 'react';
|
2019-12-11 23:32:19 +08:00
|
|
|
import { mount } from 'enzyme';
|
2017-01-19 13:55:04 +08:00
|
|
|
import moment from 'moment';
|
2018-06-22 21:05:13 +08:00
|
|
|
import DatePicker from '..';
|
2018-01-21 01:03:51 +08:00
|
|
|
import { setMockDate, resetMockDate } from '../../../tests/utils';
|
2019-12-11 23:32:19 +08:00
|
|
|
import { openPicker, selectCell, closePicker } from './utils';
|
2017-11-30 09:54:31 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2017-01-19 13:55:04 +08:00
|
|
|
|
2018-01-13 19:11:53 +08:00
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
2017-01-19 13:55:04 +08:00
|
|
|
describe('RangePicker', () => {
|
2020-04-22 15:58:57 +08:00
|
|
|
focusTest(RangePicker, { refFocus: true });
|
2017-11-30 09:54:31 +08:00
|
|
|
|
2018-02-01 16:05:57 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
setMockDate();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
resetMockDate();
|
|
|
|
});
|
|
|
|
|
2017-04-26 14:44:07 +08:00
|
|
|
// issue: https://github.com/ant-design/ant-design/issues/5872
|
|
|
|
it('should not throw error when value is reset to `[]`', () => {
|
|
|
|
const birthday = moment('2000-01-01', 'YYYY-MM-DD');
|
2019-12-11 23:32:19 +08:00
|
|
|
const wrapper = mount(<RangePicker value={[birthday, birthday]} open />);
|
2017-04-26 14:44:07 +08:00
|
|
|
wrapper.setProps({ value: [] });
|
2017-08-04 16:48:52 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(() => {
|
|
|
|
openPicker(wrapper);
|
|
|
|
selectCell(wrapper, 3);
|
|
|
|
closePicker(wrapper);
|
2018-01-21 01:03:51 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
openPicker(wrapper, 1);
|
|
|
|
selectCell(wrapper, 5, 1);
|
|
|
|
closePicker(wrapper, 1);
|
|
|
|
}).not.toThrow();
|
2018-09-10 00:26:26 +08:00
|
|
|
});
|
2019-02-28 16:11:10 +08:00
|
|
|
|
|
|
|
it('customize separator', () => {
|
|
|
|
const wrapper = mount(<RangePicker separator="test" />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-04-01 14:49:40 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/13302
|
|
|
|
describe('in "month" mode, when the left and right panels select the same month', () => {
|
|
|
|
it('the cell status is correct', () => {
|
2019-12-11 23:32:19 +08:00
|
|
|
class Test extends React.Component {
|
|
|
|
state = {
|
|
|
|
value: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
onPanelChange = value => {
|
|
|
|
this.setState({ value });
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<RangePicker
|
|
|
|
value={this.state.value}
|
|
|
|
mode={['month', 'month']}
|
|
|
|
onPanelChange={this.onPanelChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const wrapper = mount(<Test />);
|
|
|
|
openPicker(wrapper);
|
|
|
|
selectCell(wrapper, 'Feb');
|
|
|
|
openPicker(wrapper, 1);
|
|
|
|
selectCell(wrapper, 'Feb');
|
|
|
|
closePicker(wrapper, 1);
|
|
|
|
|
|
|
|
const { value } = wrapper.state();
|
|
|
|
|
|
|
|
expect(value[0].isSame(value[1], 'date')).toBeTruthy();
|
2019-09-17 14:22:16 +08:00
|
|
|
});
|
2019-07-22 17:07:13 +08:00
|
|
|
});
|
2020-04-28 16:00:04 +08:00
|
|
|
|
|
|
|
describe('ranges', () => {
|
|
|
|
it('RangePicker support presetted ranges with Tags', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<RangePicker
|
|
|
|
ranges={{
|
|
|
|
Today: [moment(), moment()],
|
|
|
|
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
|
|
|
}}
|
|
|
|
open
|
|
|
|
/>,
|
|
|
|
);
|
2020-04-28 16:48:06 +08:00
|
|
|
expect(wrapper).toMatchRenderedSnapshot();
|
2020-04-28 16:00:04 +08:00
|
|
|
});
|
|
|
|
});
|
2020-05-02 21:55:23 +08:00
|
|
|
|
|
|
|
it('placeholder', () => {
|
|
|
|
const wrapper = mount(<RangePicker placeholder={undefined} />);
|
|
|
|
expect(wrapper.find('input').first().props().placeholder).toEqual('Start date');
|
|
|
|
expect(wrapper.find('input').last().props().placeholder).toEqual('End date');
|
|
|
|
});
|
2017-01-19 13:55:04 +08:00
|
|
|
});
|