2017-03-03 15:26:23 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Moment from 'moment';
|
2019-12-11 23:32:19 +08:00
|
|
|
import momentGenerateConfig from 'rc-picker/lib/generate/moment';
|
2017-03-03 15:26:23 +08:00
|
|
|
import { mount } from 'enzyme';
|
2018-10-21 12:03:32 +08:00
|
|
|
import MockDate from 'mockdate';
|
2017-03-03 15:26:23 +08:00
|
|
|
import Calendar from '..';
|
2019-03-08 21:46:44 +08:00
|
|
|
import Header from '../Header';
|
2019-05-26 13:09:06 +08:00
|
|
|
import Select from '../../select';
|
|
|
|
import Group from '../../radio/group';
|
|
|
|
import Button from '../../radio/radioButton';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2017-03-03 15:26:23 +08:00
|
|
|
|
|
|
|
describe('Calendar', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Calendar);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Calendar, true);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2019-09-12 20:15:17 +08:00
|
|
|
function openSelect(wrapper, className) {
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapper.find(className).find('.ant-select-selector').simulate('mousedown');
|
2019-09-12 20:15:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function findSelectItem(wrapper) {
|
|
|
|
return wrapper.find('.ant-select-item-option');
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickSelectItem(wrapper, index = 0) {
|
2020-05-21 23:27:02 +08:00
|
|
|
findSelectItem(wrapper).at(index).simulate('click');
|
2019-09-12 20:15:17 +08:00
|
|
|
}
|
|
|
|
|
2021-05-08 16:59:03 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/30392
|
|
|
|
it('should be able to set undefined or null', () => {
|
|
|
|
expect(() => {
|
|
|
|
const wrapper = mount(<Calendar />);
|
|
|
|
wrapper.setProps({ value: null });
|
|
|
|
}).not.toThrow();
|
|
|
|
expect(() => {
|
|
|
|
const wrapper = mount(<Calendar />);
|
|
|
|
wrapper.setProps({ value: undefined });
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
|
2017-03-03 15:26:23 +08:00
|
|
|
it('Calendar should be selectable', () => {
|
|
|
|
const onSelect = jest.fn();
|
2020-08-24 11:50:53 +08:00
|
|
|
const onChange = jest.fn();
|
|
|
|
const wrapper = mount(<Calendar onSelect={onSelect} onChange={onChange} />);
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapper.find('.ant-picker-cell').at(0).simulate('click');
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onSelect).toHaveBeenCalledWith(expect.anything());
|
2017-03-03 15:26:23 +08:00
|
|
|
const value = onSelect.mock.calls[0][0];
|
|
|
|
expect(Moment.isMoment(value)).toBe(true);
|
2020-08-24 11:50:53 +08:00
|
|
|
expect(onChange).toHaveBeenCalled();
|
2017-03-03 15:26:23 +08:00
|
|
|
});
|
2018-02-04 16:50:50 +08:00
|
|
|
|
2018-02-03 18:54:04 +08:00
|
|
|
it('only Valid range should be selectable', () => {
|
|
|
|
const onSelect = jest.fn();
|
|
|
|
const validRange = [Moment('2018-02-02'), Moment('2018-02-18')];
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Calendar onSelect={onSelect} validRange={validRange} defaultValue={Moment('2018-02-02')} />,
|
2018-02-03 18:54:04 +08:00
|
|
|
);
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapper.find('[title="2018-02-01"]').at(0).simulate('click');
|
|
|
|
wrapper.find('[title="2018-02-02"]').at(0).simulate('click');
|
2018-02-03 18:54:04 +08:00
|
|
|
expect(onSelect.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dates other than in valid range should be disabled', () => {
|
|
|
|
const onSelect = jest.fn();
|
|
|
|
const validRange = [Moment('2018-02-02'), Moment('2018-02-18')];
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Calendar onSelect={onSelect} validRange={validRange} defaultValue={Moment('2018-02-02')} />,
|
2018-02-03 18:54:04 +08:00
|
|
|
);
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapper.find('[title="2018-02-20"]').at(0).simulate('click');
|
2019-12-11 23:32:19 +08:00
|
|
|
const elem = wrapper.find('[title="2018-02-20"]').hasClass('ant-picker-cell-disabled');
|
2018-02-03 18:54:04 +08:00
|
|
|
expect(elem).toEqual(true);
|
|
|
|
expect(onSelect.mock.calls.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('months other than in valid range should be disabled', () => {
|
|
|
|
const onSelect = jest.fn();
|
|
|
|
const validRange = [Moment('2018-02-02'), Moment('2018-05-18')];
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Calendar
|
|
|
|
onSelect={onSelect}
|
|
|
|
validRange={validRange}
|
|
|
|
defaultValue={Moment('2018-02-02')}
|
|
|
|
mode="year"
|
|
|
|
/>,
|
2018-02-03 18:54:04 +08:00
|
|
|
);
|
2020-05-21 23:27:02 +08:00
|
|
|
expect(wrapper.find('[title="2018-01"]').at(0).hasClass('ant-picker-cell-disabled')).toBe(true);
|
|
|
|
expect(wrapper.find('[title="2018-02"]').at(0).hasClass('ant-picker-cell-disabled')).toBe(
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('[title="2018-06"]').at(0).hasClass('ant-picker-cell-disabled')).toBe(true);
|
|
|
|
wrapper.find('[title="2018-01"]').at(0).simulate('click');
|
|
|
|
wrapper.find('[title="2018-03"]').at(0).simulate('click');
|
2018-02-03 18:54:04 +08:00
|
|
|
expect(onSelect.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
2018-03-09 17:41:44 +08:00
|
|
|
it('months other than in valid range should not be shown in header', () => {
|
|
|
|
const validRange = [Moment('2017-02-02'), Moment('2018-05-18')];
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<Calendar validRange={validRange} />);
|
2019-12-11 23:32:19 +08:00
|
|
|
openSelect(wrapper, '.ant-picker-calendar-year-select');
|
2019-09-12 20:15:17 +08:00
|
|
|
clickSelectItem(wrapper);
|
2019-12-11 23:32:19 +08:00
|
|
|
openSelect(wrapper, '.ant-picker-calendar-month-select');
|
2018-03-09 17:41:44 +08:00
|
|
|
// 2 years and 11 months
|
2019-09-12 20:15:17 +08:00
|
|
|
expect(wrapper.find('.ant-select-item-option').length).toBe(13);
|
2018-03-09 17:41:44 +08:00
|
|
|
});
|
|
|
|
|
2018-02-03 18:54:04 +08:00
|
|
|
it('getDateRange should returns a disabledDate function', () => {
|
|
|
|
const validRange = [Moment('2018-02-02'), Moment('2018-05-18')];
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<Calendar validRange={validRange} defaultValue={Moment('2018-02-02')} />);
|
2019-12-11 23:32:19 +08:00
|
|
|
const { disabledDate } = wrapper.find('PickerPanel').props();
|
2018-02-03 18:54:04 +08:00
|
|
|
expect(disabledDate(Moment('2018-06-02'))).toBe(true);
|
|
|
|
expect(disabledDate(Moment('2018-04-02'))).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-07-21 16:29:27 +08:00
|
|
|
it('validRange should work with disabledDate function', () => {
|
|
|
|
const validRange = [Moment('2018-02-02'), Moment('2018-05-18')];
|
|
|
|
const wrapper = mount(
|
|
|
|
<Calendar validRange={validRange} disabledDate={data => data.isSame(Moment('2018-02-03'))} />,
|
|
|
|
);
|
|
|
|
|
|
|
|
const { disabledDate } = wrapper.find('PickerPanel').props();
|
|
|
|
expect(disabledDate(Moment('2018-02-01'))).toBe(true);
|
|
|
|
expect(disabledDate(Moment('2018-02-02'))).toBe(false);
|
|
|
|
expect(disabledDate(Moment('2018-02-03'))).toBe(true);
|
|
|
|
expect(disabledDate(Moment('2018-02-04'))).toBe(false);
|
|
|
|
expect(disabledDate(Moment('2018-06-01'))).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Calendar MonthSelect should display correct label', () => {
|
|
|
|
const validRange = [Moment('2018-02-02'), Moment('2019-06-1')];
|
|
|
|
const wrapper = mount(<Calendar validRange={validRange} defaultValue={Moment('2019-01-01')} />);
|
2020-10-24 20:33:18 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2020-07-21 16:29:27 +08:00
|
|
|
});
|
|
|
|
|
2018-02-04 16:50:50 +08:00
|
|
|
it('Calendar should change mode by prop', () => {
|
|
|
|
const monthMode = 'month';
|
|
|
|
const yearMode = 'year';
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<Calendar />);
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(wrapper.find('CalendarHeader').props().mode).toEqual(monthMode);
|
|
|
|
wrapper.setProps({ mode: yearMode });
|
|
|
|
expect(wrapper.find('CalendarHeader').props().mode).toEqual(yearMode);
|
2018-02-04 16:50:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Calendar should switch mode', () => {
|
|
|
|
const monthMode = 'month';
|
|
|
|
const yearMode = 'year';
|
|
|
|
const onPanelChangeStub = jest.fn();
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<Calendar mode={yearMode} onPanelChange={onPanelChangeStub} />);
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(wrapper.find('CalendarHeader').props().mode).toEqual(yearMode);
|
2019-03-08 15:34:29 +08:00
|
|
|
wrapper.setProps({ mode: monthMode });
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(wrapper.find('CalendarHeader').props().mode).toEqual(monthMode);
|
2019-03-08 15:34:29 +08:00
|
|
|
expect(onPanelChangeStub).toHaveBeenCalledTimes(0);
|
2018-02-04 16:50:50 +08:00
|
|
|
});
|
2018-10-19 23:54:10 +08:00
|
|
|
|
|
|
|
it('Calendar should support locale', () => {
|
2020-05-21 23:27:02 +08:00
|
|
|
MockDate.set(Moment('2018-10-19').valueOf());
|
2020-04-03 15:02:11 +08:00
|
|
|
// eslint-disable-next-line global-require
|
2018-10-19 23:54:10 +08:00
|
|
|
const zhCN = require('../locale/zh_CN').default;
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<Calendar locale={zhCN} />);
|
2018-10-19 23:54:10 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2018-10-21 12:03:32 +08:00
|
|
|
MockDate.reset();
|
2018-10-19 23:54:10 +08:00
|
|
|
});
|
2019-02-26 19:56:55 +08:00
|
|
|
|
2020-06-02 21:26:52 +08:00
|
|
|
describe('onPanelChange', () => {
|
|
|
|
it('trigger when click last month of date', () => {
|
|
|
|
const onPanelChange = jest.fn();
|
|
|
|
const date = new Moment('1990-09-03');
|
|
|
|
const wrapper = mount(<Calendar onPanelChange={onPanelChange} value={date} />);
|
2019-02-26 19:56:55 +08:00
|
|
|
|
2020-06-02 21:26:52 +08:00
|
|
|
wrapper.find('.ant-picker-cell').at(0).simulate('click');
|
|
|
|
|
|
|
|
expect(onPanelChange).toHaveBeenCalled();
|
|
|
|
expect(onPanelChange.mock.calls[0][0].month()).toEqual(date.month() - 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('not trigger when in same month', () => {
|
|
|
|
const onPanelChange = jest.fn();
|
|
|
|
const date = new Moment('1990-09-03');
|
|
|
|
const wrapper = mount(<Calendar onPanelChange={onPanelChange} value={date} />);
|
|
|
|
|
|
|
|
wrapper.find('.ant-picker-cell').at(10).simulate('click');
|
2019-02-26 19:56:55 +08:00
|
|
|
|
2020-06-02 21:26:52 +08:00
|
|
|
expect(onPanelChange).not.toHaveBeenCalled();
|
|
|
|
});
|
2019-02-26 19:56:55 +08:00
|
|
|
});
|
2019-03-12 14:38:53 +08:00
|
|
|
|
2019-03-12 16:31:29 +08:00
|
|
|
it('switch should work correctly without prop mode', async () => {
|
2019-03-12 14:38:53 +08:00
|
|
|
const onPanelChange = jest.fn();
|
2019-03-12 15:46:12 +08:00
|
|
|
const date = new Moment(new Date(Date.UTC(2017, 7, 9, 8)));
|
2019-03-12 14:59:41 +08:00
|
|
|
const wrapper = mount(<Calendar onPanelChange={onPanelChange} value={date} />);
|
2019-12-11 23:32:19 +08:00
|
|
|
|
|
|
|
expect(wrapper.find('CalendarHeader').props().mode).toBe('month');
|
|
|
|
expect(wrapper.find('.ant-picker-date-panel').length).toBe(1);
|
|
|
|
expect(wrapper.find('.ant-picker-month-panel').length).toBe(0);
|
|
|
|
|
2019-03-12 15:06:41 +08:00
|
|
|
wrapper.find('.ant-radio-button-input[value="year"]').simulate('change');
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(wrapper.find('.ant-picker-date-panel').length).toBe(0);
|
|
|
|
expect(wrapper.find('.ant-picker-month-panel').length).toBe(1);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onPanelChange).toHaveBeenCalled();
|
2019-03-12 14:38:53 +08:00
|
|
|
expect(onPanelChange.mock.calls[0][1]).toEqual('year');
|
|
|
|
});
|
2019-03-09 19:01:08 +08:00
|
|
|
|
|
|
|
const createWrapper = (start, end, value, onValueChange) => {
|
2019-03-08 21:46:44 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Header
|
2019-12-11 23:32:19 +08:00
|
|
|
prefixCls="ant-picker-calendar"
|
|
|
|
generateConfig={momentGenerateConfig}
|
|
|
|
onChange={onValueChange}
|
2019-03-08 21:46:44 +08:00
|
|
|
value={value}
|
|
|
|
validRange={[start, end]}
|
|
|
|
locale={{ year: '年' }}
|
|
|
|
/>,
|
2019-03-09 18:26:30 +08:00
|
|
|
);
|
2019-12-11 23:32:19 +08:00
|
|
|
openSelect(wrapper, '.ant-picker-calendar-year-select');
|
2019-09-12 20:15:17 +08:00
|
|
|
clickSelectItem(wrapper);
|
2019-03-09 19:01:08 +08:00
|
|
|
};
|
|
|
|
|
2019-03-18 16:07:11 +08:00
|
|
|
it('if value.month > end.month, set value.month to end.month', () => {
|
2019-03-09 19:01:08 +08:00
|
|
|
const value = new Moment('1990-01-03');
|
|
|
|
const start = new Moment('2019-04-01');
|
|
|
|
const end = new Moment('2019-11-01');
|
|
|
|
const onValueChange = jest.fn();
|
|
|
|
createWrapper(start, end, value, onValueChange);
|
|
|
|
expect(onValueChange).toHaveBeenCalledWith(value.year('2019').month('3'));
|
2019-03-08 21:46:44 +08:00
|
|
|
});
|
|
|
|
|
2020-09-15 11:54:47 +08:00
|
|
|
it('if start.month > value.month, set value.month to start.month', () => {
|
2019-03-08 21:46:44 +08:00
|
|
|
const value = new Moment('1990-01-03');
|
|
|
|
const start = new Moment('2019-11-01');
|
|
|
|
const end = new Moment('2019-03-01');
|
2019-03-09 18:26:30 +08:00
|
|
|
const onValueChange = jest.fn();
|
2019-03-09 19:01:08 +08:00
|
|
|
createWrapper(start, end, value, onValueChange);
|
2019-03-09 18:26:30 +08:00
|
|
|
expect(onValueChange).toHaveBeenCalledWith(value.year('2019').month('10'));
|
2019-03-08 21:46:44 +08:00
|
|
|
});
|
|
|
|
|
2020-09-15 11:54:47 +08:00
|
|
|
it('if change year and new month > end month, set value.month to end.month', () => {
|
2019-12-11 23:32:19 +08:00
|
|
|
const value = new Moment('2018-11-03');
|
|
|
|
const start = new Moment('2000-01-01');
|
|
|
|
const end = new Moment('2019-03-01');
|
|
|
|
const onValueChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Header
|
|
|
|
prefixCls="ant-picker-calendar"
|
|
|
|
generateConfig={momentGenerateConfig}
|
|
|
|
onChange={onValueChange}
|
|
|
|
value={value}
|
|
|
|
validRange={[start, end]}
|
|
|
|
locale={{ year: '年' }}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
openSelect(wrapper, '.ant-picker-calendar-year-select');
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapper.find('.ant-select-item-option').last().simulate('click');
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(onValueChange).toHaveBeenCalledWith(value.year('2019').month('2'));
|
|
|
|
});
|
|
|
|
|
2019-03-08 21:46:44 +08:00
|
|
|
it('onMonthChange should work correctly', () => {
|
2019-03-09 18:26:30 +08:00
|
|
|
const start = new Moment('2018-11-01');
|
|
|
|
const end = new Moment('2019-03-01');
|
|
|
|
const value = new Moment('2018-12-03');
|
|
|
|
const onValueChange = jest.fn();
|
2019-03-08 21:46:44 +08:00
|
|
|
const wrapper = mount(
|
2019-03-09 18:26:30 +08:00
|
|
|
<Header
|
2019-12-11 23:32:19 +08:00
|
|
|
prefixCls="ant-picker-calendar"
|
|
|
|
generateConfig={momentGenerateConfig}
|
|
|
|
onChange={onValueChange}
|
2019-03-09 18:26:30 +08:00
|
|
|
value={value}
|
|
|
|
validRange={[start, end]}
|
2019-12-11 23:32:19 +08:00
|
|
|
locale={{ year: '年', locale: 'zh_CN' }}
|
|
|
|
mode="month"
|
2019-03-09 18:26:30 +08:00
|
|
|
/>,
|
|
|
|
);
|
2019-12-11 23:32:19 +08:00
|
|
|
openSelect(wrapper, '.ant-picker-calendar-month-select');
|
2019-09-12 20:15:17 +08:00
|
|
|
clickSelectItem(wrapper);
|
2019-03-09 18:26:30 +08:00
|
|
|
expect(onValueChange).toHaveBeenCalledWith(value.month(10));
|
2019-03-08 21:46:44 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('onTypeChange should work correctly', () => {
|
2019-03-09 18:26:30 +08:00
|
|
|
const onTypeChange = jest.fn();
|
|
|
|
const value = new Moment('2018-12-03');
|
2019-03-08 21:46:44 +08:00
|
|
|
const wrapper = mount(
|
2019-03-09 18:26:30 +08:00
|
|
|
<Header
|
2019-12-11 23:32:19 +08:00
|
|
|
prefixCls="ant-picker-calendar"
|
|
|
|
generateConfig={momentGenerateConfig}
|
|
|
|
onModeChange={onTypeChange}
|
|
|
|
locale={{ year: '年', month: '月', locale: 'zh_CN' }}
|
2019-03-09 18:26:30 +08:00
|
|
|
value={value}
|
|
|
|
type="date"
|
|
|
|
/>,
|
|
|
|
);
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapper.find('input[type="radio"]').at(1).simulate('change');
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onTypeChange).toHaveBeenCalledWith('year');
|
2019-03-08 21:46:44 +08:00
|
|
|
});
|
2019-05-26 13:09:06 +08:00
|
|
|
|
|
|
|
it('headerRender should work correctly', () => {
|
|
|
|
const onMonthChange = jest.fn();
|
|
|
|
const onYearChange = jest.fn();
|
|
|
|
const onTypeChange = jest.fn();
|
2019-12-11 23:32:19 +08:00
|
|
|
|
|
|
|
// Year
|
2019-05-26 13:09:06 +08:00
|
|
|
const headerRender = jest.fn(({ value }) => {
|
|
|
|
const year = value.year();
|
|
|
|
const options = [];
|
|
|
|
for (let i = year - 100; i < year + 100; i += 1) {
|
|
|
|
options.push(
|
|
|
|
<Select.Option className="year-item" key={i} value={i}>
|
|
|
|
{i}
|
|
|
|
</Select.Option>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
size="small"
|
|
|
|
dropdownMatchSelectWidth={false}
|
|
|
|
className="my-year-select"
|
|
|
|
onChange={onYearChange}
|
|
|
|
value={String(year)}
|
|
|
|
>
|
|
|
|
{options}
|
|
|
|
</Select>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
const wrapperWithYear = mount(<Calendar fullscreen={false} headerRender={headerRender} />);
|
|
|
|
|
2019-09-12 20:15:17 +08:00
|
|
|
openSelect(wrapperWithYear, '.ant-select');
|
2019-05-26 13:09:06 +08:00
|
|
|
wrapperWithYear.update();
|
|
|
|
|
2020-05-21 23:27:02 +08:00
|
|
|
findSelectItem(wrapperWithYear).last().simulate('click');
|
2019-05-26 13:09:06 +08:00
|
|
|
|
|
|
|
expect(onYearChange).toHaveBeenCalled();
|
2019-12-11 23:32:19 +08:00
|
|
|
|
|
|
|
// Month
|
2019-05-26 13:09:06 +08:00
|
|
|
const headerRenderWithMonth = jest.fn(({ value }) => {
|
|
|
|
const start = 0;
|
|
|
|
const end = 12;
|
|
|
|
const monthOptions = [];
|
|
|
|
const current = value.clone();
|
|
|
|
const localeData = value.localeData();
|
|
|
|
const months = [];
|
|
|
|
for (let i = 0; i < 12; i += 1) {
|
|
|
|
current.month(i);
|
|
|
|
months.push(localeData.monthsShort(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let index = start; index < end; index += 1) {
|
|
|
|
monthOptions.push(
|
2019-12-01 15:28:49 +08:00
|
|
|
<Select.Option className="month-item" key={`${index}`} value={index}>
|
2019-05-26 13:09:06 +08:00
|
|
|
{months[index]}
|
|
|
|
</Select.Option>,
|
|
|
|
);
|
|
|
|
}
|
2019-12-11 23:32:19 +08:00
|
|
|
|
2019-05-26 13:09:06 +08:00
|
|
|
const month = value.month();
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
size="small"
|
|
|
|
dropdownMatchSelectWidth={false}
|
2019-12-11 23:32:19 +08:00
|
|
|
className="my-month-select"
|
2019-05-26 13:09:06 +08:00
|
|
|
onChange={onMonthChange}
|
2019-12-11 23:32:19 +08:00
|
|
|
value={String(month)}
|
2019-05-26 13:09:06 +08:00
|
|
|
>
|
|
|
|
{monthOptions}
|
|
|
|
</Select>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
const wrapperWithMonth = mount(
|
|
|
|
<Calendar fullscreen={false} headerRender={headerRenderWithMonth} />,
|
|
|
|
);
|
|
|
|
|
2019-09-12 20:15:17 +08:00
|
|
|
openSelect(wrapperWithMonth, '.ant-select');
|
2019-05-26 13:09:06 +08:00
|
|
|
wrapperWithMonth.update();
|
|
|
|
|
2020-05-21 23:27:02 +08:00
|
|
|
findSelectItem(wrapperWithMonth).last().simulate('click');
|
2019-12-11 23:32:19 +08:00
|
|
|
|
2019-05-26 13:09:06 +08:00
|
|
|
expect(onMonthChange).toHaveBeenCalled();
|
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
// Type
|
2020-12-09 17:12:32 +08:00
|
|
|
const headerRenderWithTypeChange = jest.fn(({ type }) => (
|
|
|
|
<Group size="small" onChange={onTypeChange} value={type}>
|
|
|
|
<Button value="month">Month</Button>
|
|
|
|
<Button value="year">Year</Button>
|
|
|
|
</Group>
|
|
|
|
));
|
2019-05-26 13:09:06 +08:00
|
|
|
|
|
|
|
const wrapperWithTypeChange = mount(
|
|
|
|
<Calendar fullscreen={false} headerRender={headerRenderWithTypeChange} />,
|
|
|
|
);
|
|
|
|
|
2020-05-21 23:27:02 +08:00
|
|
|
wrapperWithTypeChange.find('.ant-radio-button-input').last().simulate('change');
|
2019-05-26 13:09:06 +08:00
|
|
|
expect(onTypeChange).toHaveBeenCalled();
|
|
|
|
});
|
2019-12-11 23:32:19 +08:00
|
|
|
|
|
|
|
it('dateFullCellRender', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Calendar dateFullCellRender={() => <div className="light">Bamboo</div>} />,
|
|
|
|
);
|
2020-05-21 23:27:02 +08:00
|
|
|
expect(wrapper.find('.light').first().text()).toEqual('Bamboo');
|
2019-12-11 23:32:19 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('monthFullCellRender', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Calendar mode="year" monthFullCellRender={() => <div className="bamboo">Light</div>} />,
|
|
|
|
);
|
2020-05-21 23:27:02 +08:00
|
|
|
expect(wrapper.find('.bamboo').first().text()).toEqual('Light');
|
2019-12-11 23:32:19 +08:00
|
|
|
});
|
2022-03-21 23:11:48 +08:00
|
|
|
|
|
|
|
it('when fullscreen is false, the element returned by dateFullCellRender should be interactive', () => {
|
|
|
|
const onClick = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Calendar
|
|
|
|
fullscreen={false}
|
|
|
|
dateFullCellRender={() => (
|
|
|
|
<div className="bamboo" onClick={onClick}>
|
|
|
|
Light
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
wrapper.find('.bamboo').first().simulate('click');
|
|
|
|
expect(onClick).toBeCalled();
|
|
|
|
});
|
2017-03-03 15:26:23 +08:00
|
|
|
});
|