2017-01-19 13:55:04 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount, render } from 'enzyme';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { RangePicker } from '../';
|
|
|
|
|
|
|
|
describe('RangePicker', () => {
|
|
|
|
it('show month panel according to value', () => {
|
2017-04-01 14:43:36 +08:00
|
|
|
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
|
2017-01-19 13:55:04 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<RangePicker
|
|
|
|
getCalendarContainer={trigger => trigger}
|
|
|
|
format="YYYY/MM/DD"
|
2017-05-15 12:03:02 +08:00
|
|
|
showTime
|
|
|
|
open
|
2017-01-19 13:55:04 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
wrapper.setProps({ value: [birthday, birthday] });
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent()))
|
2017-01-19 13:55:04 +08:00
|
|
|
.toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('switch to corresponding month panel when click presetted ranges', () => {
|
2017-04-01 14:43:36 +08:00
|
|
|
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
|
2017-01-19 13:55:04 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<RangePicker
|
|
|
|
ranges={{
|
|
|
|
'My Birthday': [birthday, birthday],
|
|
|
|
}}
|
|
|
|
getCalendarContainer={trigger => trigger}
|
|
|
|
format="YYYY/MM/DD"
|
2017-05-15 12:03:02 +08:00
|
|
|
showTime
|
|
|
|
open
|
2017-01-19 13:55:04 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2017-09-20 16:26:18 +08:00
|
|
|
const rangeCalendarWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-01-19 13:55:04 +08:00
|
|
|
rangeCalendarWrapper.find('.ant-calendar-range-quick-selector a')
|
|
|
|
.simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(render(wrapper.find('Trigger').instance().getComponent()))
|
2017-01-19 13:55:04 +08:00
|
|
|
.toMatchSnapshot();
|
|
|
|
});
|
2017-04-26 14:44:07 +08:00
|
|
|
|
2017-05-22 09:42:04 +08:00
|
|
|
it('highlight range when hover presetted range', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<RangePicker
|
|
|
|
ranges={{
|
2017-05-31 10:59:27 +08:00
|
|
|
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
2017-05-22 09:42:04 +08:00
|
|
|
}}
|
|
|
|
getCalendarContainer={trigger => trigger}
|
|
|
|
format="YYYY/MM/DD"
|
|
|
|
open
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2017-09-20 16:26:18 +08:00
|
|
|
let rangeCalendarWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-05-22 09:42:04 +08:00
|
|
|
rangeCalendarWrapper.find('.ant-calendar-range-quick-selector a')
|
|
|
|
.simulate('mouseEnter');
|
2017-09-20 16:26:18 +08:00
|
|
|
rangeCalendarWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-05-22 09:42:04 +08:00
|
|
|
expect(rangeCalendarWrapper.find('.ant-calendar-selected-day').length).toBe(2);
|
|
|
|
});
|
|
|
|
|
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');
|
|
|
|
const wrapper = mount(
|
|
|
|
<RangePicker
|
|
|
|
getCalendarContainer={trigger => trigger}
|
|
|
|
value={[birthday, birthday]}
|
|
|
|
open
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
wrapper.setProps({ value: [] });
|
2017-09-20 16:26:18 +08:00
|
|
|
const rangeCalendarWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-07-12 15:15:21 +08:00
|
|
|
expect(() => rangeCalendarWrapper.find('.ant-calendar-cell').at(15).simulate('click').simulate('click'))
|
2017-04-26 14:44:07 +08:00
|
|
|
.not.toThrow();
|
|
|
|
});
|
2017-08-04 16:48:52 +08:00
|
|
|
|
|
|
|
// issue: https://github.com/ant-design/ant-design/issues/7077
|
|
|
|
it('should not throw error when select after clear', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<RangePicker
|
|
|
|
getCalendarContainer={trigger => trigger}
|
|
|
|
open
|
|
|
|
/>
|
|
|
|
);
|
2017-09-20 16:26:18 +08:00
|
|
|
let rangeCalendarWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-08-04 16:48:52 +08:00
|
|
|
rangeCalendarWrapper.find('.ant-calendar-cell').at(15).simulate('click').simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
wrapper.update();
|
|
|
|
wrapper.find('.ant-calendar-picker-clear').hostNodes().simulate('click');
|
2017-08-04 16:48:52 +08:00
|
|
|
wrapper.find('.ant-calendar-picker-input').simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
rangeCalendarWrapper = mount(wrapper.find('Trigger').instance().getComponent());
|
2017-08-04 16:48:52 +08:00
|
|
|
expect(() => rangeCalendarWrapper.find('.ant-calendar-cell').at(15).simulate('click').simulate('click'))
|
|
|
|
.not.toThrow();
|
|
|
|
});
|
2017-01-19 13:55:04 +08:00
|
|
|
});
|