2019-01-12 11:33:27 +08:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-09-25 16:51:32 +08:00
|
|
|
import { asyncExpect, setMockDate, resetMockDate, sleep } from '../../../tests/utils';
|
|
|
|
import dayjs from 'dayjs';
|
2019-01-12 11:33:27 +08:00
|
|
|
import DatePicker from '../';
|
2021-09-25 16:51:32 +08:00
|
|
|
import { openPicker, selectCell, closePicker } from './utils';
|
2019-01-12 11:33:27 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2021-10-03 13:30:50 +08:00
|
|
|
jest.mock('../../_util/Portal');
|
2019-01-12 11:33:27 +08:00
|
|
|
const { RangePicker } = DatePicker;
|
2018-06-09 13:14:14 +08:00
|
|
|
|
|
|
|
describe('RangePicker', () => {
|
2019-01-12 11:33:27 +08:00
|
|
|
focusTest(RangePicker);
|
2018-06-09 13:14:14 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
document.body.outerHTML = '';
|
|
|
|
setMockDate();
|
|
|
|
});
|
2018-06-09 13:14:14 +08:00
|
|
|
|
|
|
|
afterEach(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
resetMockDate();
|
|
|
|
});
|
2018-06-09 13:14:14 +08:00
|
|
|
// issue: https://github.com/ant-design/ant-design/issues/5872
|
2021-12-24 17:43:55 +08:00
|
|
|
xit('should not throw error when value is reset to `[]`', async () => {
|
2021-09-25 16:51:32 +08:00
|
|
|
const birthday = dayjs('2000-01-01', 'YYYY-MM-DD');
|
|
|
|
const wrapper = mount(
|
2019-01-12 11:33:27 +08:00
|
|
|
{
|
2021-09-25 16:51:32 +08:00
|
|
|
props: ['value'],
|
|
|
|
setup(props) {
|
|
|
|
return () => <RangePicker value={props.value} open />;
|
2019-01-12 11:33:27 +08:00
|
|
|
},
|
2018-06-09 13:14:14 +08:00
|
|
|
},
|
2021-09-25 16:51:32 +08:00
|
|
|
{ attachTo: 'body', sync: 'false' },
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
wrapper.setProps({ value: [birthday, birthday] });
|
|
|
|
wrapper.setProps({ value: [] });
|
|
|
|
await sleep(0);
|
|
|
|
expect(() => {
|
|
|
|
openPicker(wrapper);
|
|
|
|
selectCell(wrapper, 3);
|
|
|
|
closePicker(wrapper);
|
|
|
|
|
|
|
|
openPicker(wrapper, 1);
|
|
|
|
selectCell(wrapper, 5, 1);
|
|
|
|
closePicker(wrapper, 1);
|
|
|
|
}).not.toThrow();
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-06-09 13:14:14 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
it('show month panel according to value', async () => {
|
|
|
|
const birthday = dayjs('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
|
2019-01-12 11:33:27 +08:00
|
|
|
const wrapper = mount(RangePicker, {
|
2020-07-25 15:46:49 +08:00
|
|
|
props: {
|
2021-09-25 16:51:32 +08:00
|
|
|
getPopupContainer: trigger => trigger,
|
|
|
|
format: 'YYYY/MM/DD',
|
|
|
|
showTime: true,
|
|
|
|
open: true,
|
2019-01-12 11:33:27 +08:00
|
|
|
},
|
|
|
|
sync: false,
|
2020-07-25 15:46:49 +08:00
|
|
|
attachTo: 'body',
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-06-09 13:14:14 +08:00
|
|
|
await asyncExpect(() => {
|
2021-09-25 16:51:32 +08:00
|
|
|
wrapper.setProps({ value: [birthday, birthday] });
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-06-09 13:14:14 +08:00
|
|
|
await asyncExpect(() => {
|
2021-09-25 16:51:32 +08:00
|
|
|
expect(document.body.innerHTML).toMatchSnapshot();
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
});
|
2018-06-09 13:14:14 +08:00
|
|
|
|
2022-01-07 16:16:11 +08:00
|
|
|
fit('customize separator', async () => {
|
2021-09-25 16:51:32 +08:00
|
|
|
const wrapper = mount(RangePicker, { props: { separator: 'test' } });
|
2022-01-07 16:16:11 +08:00
|
|
|
await sleep();
|
2021-09-25 16:51:32 +08:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2023-04-05 09:47:51 +08:00
|
|
|
|
|
|
|
fit('test WeekPicker valueFormat', async () => {
|
|
|
|
const case1 = ['2023-22', '2023-24'];
|
|
|
|
const case2 = ['2023-27', '2023-28'];
|
|
|
|
const wrapper = mount(RangePicker, {
|
|
|
|
props: {
|
|
|
|
picker: 'week',
|
|
|
|
format: 'YYYY-ww',
|
|
|
|
valueFormat: 'YYYY-ww',
|
|
|
|
value: case1,
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
attachTo: 'body',
|
|
|
|
});
|
|
|
|
const inputs = wrapper.findAll('input');
|
|
|
|
expect((inputs[0].element.value, inputs[1].element.value)).toBe((case1[0], case1[1]));
|
|
|
|
await asyncExpect(() => {
|
|
|
|
wrapper.setProps({ value: case2 });
|
|
|
|
});
|
|
|
|
expect((inputs[0].element.value, inputs[1].element.value)).toBe((case2[0], case2[1]));
|
|
|
|
});
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|