2023-06-07 21:59:21 +08:00
|
|
|
|
import type { TriggerProps } from '@rc-component/trigger';
|
2022-08-23 18:00:20 +08:00
|
|
|
|
import dayjs from 'dayjs';
|
2023-12-12 12:30:27 +08:00
|
|
|
|
|
2022-08-23 18:00:20 +08:00
|
|
|
|
import 'dayjs/locale/mk'; // to test local in 'prop locale should works' test case
|
2023-12-12 12:30:27 +08:00
|
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import { CloseCircleFilled } from '@ant-design/icons';
|
2022-08-23 18:00:20 +08:00
|
|
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
2022-08-18 17:40:47 +08:00
|
|
|
|
import MockDate from 'mockdate';
|
2023-04-12 17:20:08 +08:00
|
|
|
|
import dayJsGenerateConfig from 'rc-picker/lib/generate/dayjs';
|
2023-12-12 12:30:27 +08:00
|
|
|
|
|
2022-08-18 17:40:47 +08:00
|
|
|
|
import DatePicker from '..';
|
2023-12-12 12:30:27 +08:00
|
|
|
|
import { resetWarned } from '../../_util/warning';
|
2022-08-18 17:40:47 +08:00
|
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2024-02-01 16:26:38 +08:00
|
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
2023-04-12 17:20:08 +08:00
|
|
|
|
import type { PickerLocale } from '../generatePicker';
|
2024-02-01 16:26:38 +08:00
|
|
|
|
import { getClearButton } from './utils';
|
2022-08-18 17:40:47 +08:00
|
|
|
|
|
2022-08-23 18:00:20 +08:00
|
|
|
|
dayjs.extend(customParseFormat);
|
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
|
let triggerProps: TriggerProps;
|
|
|
|
|
|
|
|
|
|
jest.mock('@rc-component/trigger', () => {
|
|
|
|
|
let Trigger = jest.requireActual('@rc-component/trigger/lib/mock');
|
|
|
|
|
Trigger = Trigger.default || Trigger;
|
|
|
|
|
const h: typeof React = jest.requireActual('react');
|
|
|
|
|
|
|
|
|
|
return {
|
2023-07-08 15:45:28 +08:00
|
|
|
|
default: h.forwardRef<HTMLElement, TriggerProps>((props, ref) => {
|
2023-06-07 21:59:21 +08:00
|
|
|
|
triggerProps = props;
|
|
|
|
|
return h.createElement(Trigger, { ref, ...props });
|
|
|
|
|
}),
|
|
|
|
|
__esModule: true,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-29 15:34:48 +08:00
|
|
|
|
function getCell(text: string) {
|
|
|
|
|
const cells = Array.from(document.querySelectorAll('.ant-picker-cell'));
|
|
|
|
|
|
|
|
|
|
return cells.find((cell) => cell.textContent === text);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 17:40:47 +08:00
|
|
|
|
describe('DatePicker', () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2022-08-18 17:40:47 +08:00
|
|
|
|
|
|
|
|
|
focusTest(DatePicker, { refFocus: true });
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-08-23 18:00:20 +08:00
|
|
|
|
MockDate.set(dayjs('2016-11-22').valueOf());
|
2022-08-18 17:40:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
MockDate.reset();
|
|
|
|
|
errorSpy.mockReset();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('prop locale should works', () => {
|
|
|
|
|
const locale = {
|
|
|
|
|
lang: {
|
|
|
|
|
locale: 'mk',
|
|
|
|
|
placeholder: 'Избери дата',
|
|
|
|
|
rangePlaceholder: ['Начална дата', 'Крайна дата'],
|
|
|
|
|
today: 'Днес',
|
|
|
|
|
now: 'Сега',
|
|
|
|
|
backToToday: 'Към днес',
|
|
|
|
|
ok: 'Добре',
|
|
|
|
|
clear: 'Изчистване',
|
|
|
|
|
month: 'Месец',
|
|
|
|
|
year: 'Година',
|
|
|
|
|
timeSelect: 'Избор на час',
|
|
|
|
|
dateSelect: 'Избор на дата',
|
|
|
|
|
monthSelect: 'Избор на месец',
|
|
|
|
|
yearSelect: 'Избор на година',
|
|
|
|
|
decadeSelect: 'Десетилетие',
|
|
|
|
|
previousMonth: 'Предишен месец (PageUp)',
|
|
|
|
|
nextMonth: 'Следващ месец (PageDown)',
|
|
|
|
|
previousYear: 'Последна година (Control + left)',
|
|
|
|
|
nextYear: 'Следваща година (Control + right)',
|
|
|
|
|
previousDecade: 'Предишно десетилетие',
|
|
|
|
|
nextDecade: 'Следващо десетилетие',
|
|
|
|
|
previousCentury: 'Последен век',
|
|
|
|
|
nextCentury: 'Следващ век',
|
|
|
|
|
yearFormat: 'YYYY',
|
|
|
|
|
dateFormat: 'D M YYYY',
|
|
|
|
|
dayFormat: 'D',
|
|
|
|
|
dateTimeFormat: 'D M YYYY HH:mm:ss',
|
|
|
|
|
monthBeforeYear: true,
|
|
|
|
|
},
|
|
|
|
|
timePickerLocale: {
|
|
|
|
|
placeholder: 'Избор на час',
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-08-23 18:00:20 +08:00
|
|
|
|
const birthday = dayjs('2000-01-01', 'YYYY-MM-DD');
|
2022-08-18 17:40:47 +08:00
|
|
|
|
const wrapper = render(<DatePicker open locale={locale as PickerLocale} value={birthday} />);
|
|
|
|
|
expect(Array.from(wrapper.container.children)).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('disabled date', () => {
|
2022-08-23 18:00:20 +08:00
|
|
|
|
const disabledDate = (current: any) => current && current < dayjs().endOf('day');
|
2024-01-29 15:34:48 +08:00
|
|
|
|
render(<DatePicker disabledDate={disabledDate} open />);
|
|
|
|
|
|
|
|
|
|
expect(getCell('21')).toHaveClass('ant-picker-cell-disabled');
|
|
|
|
|
expect(getCell('23')).not.toHaveClass('ant-picker-cell-disabled');
|
2022-08-18 17:40:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('placeholder', () => {
|
|
|
|
|
const wrapper = render(<DatePicker placeholder={undefined} />);
|
|
|
|
|
expect(wrapper.container.querySelector('input')?.placeholder).toEqual('Select date');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('showTime={{ showHour: true, showMinute: true }}', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker
|
2022-08-23 18:00:20 +08:00
|
|
|
|
defaultValue={dayjs()}
|
2022-08-18 17:40:47 +08:00
|
|
|
|
showTime={{ showHour: true, showMinute: true }}
|
|
|
|
|
format="YYYY-MM-DD"
|
|
|
|
|
open
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(2);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(24);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-12 12:30:27 +08:00
|
|
|
|
it('showTime={{ showMinute: true, showSecond: true }}', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker
|
|
|
|
|
defaultValue={dayjs()}
|
|
|
|
|
showTime={{ showMinute: true, showSecond: true }}
|
|
|
|
|
format="YYYY-MM-DD"
|
|
|
|
|
open
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(2);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('showTime={{ showHour: true, showMinute: true, showSecond: true }}', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker
|
|
|
|
|
defaultValue={dayjs()}
|
|
|
|
|
showTime={{ showHour: true, showMinute: true, showSecond: true }}
|
|
|
|
|
format="YYYY-MM-DD"
|
|
|
|
|
open
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(3);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(24);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[2]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
|
|
|
|
|
2022-08-18 17:40:47 +08:00
|
|
|
|
it('showTime={{ showHour: true, showSecond: true }}', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker
|
2022-08-23 18:00:20 +08:00
|
|
|
|
defaultValue={dayjs()}
|
2022-08-18 17:40:47 +08:00
|
|
|
|
showTime={{ showHour: true, showSecond: true }}
|
|
|
|
|
format="YYYY-MM-DD"
|
|
|
|
|
open
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(2);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(24);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-12 12:30:27 +08:00
|
|
|
|
it('showTime={{ showSecond: true }}', () => {
|
2022-08-18 17:40:47 +08:00
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker
|
2022-08-23 18:00:20 +08:00
|
|
|
|
defaultValue={dayjs()}
|
2023-12-12 12:30:27 +08:00
|
|
|
|
showTime={{ showSecond: true }}
|
2022-08-18 17:40:47 +08:00
|
|
|
|
format="YYYY-MM-DD"
|
|
|
|
|
open
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2023-12-12 12:30:27 +08:00
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(1);
|
2022-08-18 17:40:47 +08:00
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
2023-12-12 12:30:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('showTime={{ showMinute: true }}', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker
|
|
|
|
|
defaultValue={dayjs()}
|
|
|
|
|
showTime={{ showMinute: true }}
|
|
|
|
|
format="YYYY-MM-DD"
|
|
|
|
|
open
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(1);
|
2022-08-18 17:40:47 +08:00
|
|
|
|
expect(
|
|
|
|
|
container
|
2023-12-12 12:30:27 +08:00
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
2022-08-18 17:40:47 +08:00
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
2023-12-12 12:30:27 +08:00
|
|
|
|
|
|
|
|
|
it('showTime={{ showHour: true }}', () => {
|
|
|
|
|
const { container } = render(
|
2024-01-29 15:34:48 +08:00
|
|
|
|
<DatePicker defaultValue={dayjs()} showTime={{ showHour: true }} format="YYYY-MM-DD" open />,
|
2023-12-12 12:30:27 +08:00
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(1);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(24);
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-29 15:34:48 +08:00
|
|
|
|
it('showTime={{ }} (no true args)', () => {
|
2023-12-12 12:30:27 +08:00
|
|
|
|
const { container } = render(
|
2024-01-29 15:34:48 +08:00
|
|
|
|
<DatePicker defaultValue={dayjs()} showTime={{}} format="YYYY-MM-DD" open />,
|
2023-12-12 12:30:27 +08:00
|
|
|
|
);
|
2024-01-29 15:34:48 +08:00
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column')).toHaveLength(3);
|
2023-12-12 12:30:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
2022-08-18 17:40:47 +08:00
|
|
|
|
it('showTime should work correctly when format is custom function', () => {
|
|
|
|
|
const { container } = render(
|
2022-11-19 13:47:33 +08:00
|
|
|
|
<DatePicker
|
|
|
|
|
defaultValue={dayjs()}
|
|
|
|
|
showTime
|
|
|
|
|
format={(val) => val.format('YYYY-MM-DD')}
|
|
|
|
|
open
|
|
|
|
|
/>,
|
2022-08-18 17:40:47 +08:00
|
|
|
|
);
|
2024-01-29 15:34:48 +08:00
|
|
|
|
const focusEvent = () => {
|
2022-08-18 17:40:47 +08:00
|
|
|
|
fireEvent.focus(container.querySelector('input')!);
|
|
|
|
|
};
|
|
|
|
|
const mouseDownEvent = () => {
|
|
|
|
|
fireEvent.mouseDown(container.querySelector('input')!);
|
|
|
|
|
};
|
2024-01-29 15:34:48 +08:00
|
|
|
|
expect(focusEvent).not.toThrow();
|
2022-08-30 10:57:13 +08:00
|
|
|
|
expect(mouseDownEvent).not.toThrow();
|
2022-08-18 17:40:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
2023-08-22 13:00:42 +08:00
|
|
|
|
it('showTime should work correctly when format is Array', () => {
|
|
|
|
|
const { container } = render(
|
2023-08-23 15:42:33 +08:00
|
|
|
|
<DatePicker defaultValue={dayjs()} showTime format={['YYYY-MM-DD HH:mm']} open />,
|
2023-08-22 13:00:42 +08:00
|
|
|
|
);
|
|
|
|
|
const fuousEvent = () => {
|
|
|
|
|
fireEvent.focus(container.querySelector('input')!);
|
|
|
|
|
};
|
|
|
|
|
const mouseDownEvent = () => {
|
|
|
|
|
fireEvent.mouseDown(container.querySelector('input')!);
|
|
|
|
|
};
|
|
|
|
|
expect(fuousEvent).not.toThrow();
|
|
|
|
|
expect(mouseDownEvent).not.toThrow();
|
|
|
|
|
});
|
|
|
|
|
|
2022-08-18 17:40:47 +08:00
|
|
|
|
it('12 hours', () => {
|
|
|
|
|
const { container } = render(
|
2022-08-23 18:00:20 +08:00
|
|
|
|
<DatePicker defaultValue={dayjs()} showTime format="YYYY-MM-DD HH:mm:ss A" open />,
|
2022-08-18 17:40:47 +08:00
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(4);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(12);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[2]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[3]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('24 hours', () => {
|
|
|
|
|
const { container } = render(
|
2022-08-23 18:00:20 +08:00
|
|
|
|
<DatePicker defaultValue={dayjs()} showTime format="YYYY-MM-DD HH:mm:ss" open />,
|
2022-08-18 17:40:47 +08:00
|
|
|
|
);
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(3);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(24);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[2]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-07 17:56:55 +08:00
|
|
|
|
it('DatePicker.RangePicker with defaultValue and showTime', () => {
|
2022-08-23 18:00:20 +08:00
|
|
|
|
const startDate = dayjs('1982-02-12');
|
|
|
|
|
const endDate = dayjs('1982-02-22');
|
2022-08-18 17:40:47 +08:00
|
|
|
|
|
|
|
|
|
const { container } = render(
|
2023-09-07 17:56:55 +08:00
|
|
|
|
<DatePicker.RangePicker defaultValue={[startDate, endDate]} showTime open />,
|
2022-08-18 17:40:47 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const m = container.querySelector('.ant-picker-header-view .ant-picker-month-btn')?.innerHTML;
|
|
|
|
|
const y = container.querySelector('.ant-picker-header-view .ant-picker-year-btn')?.innerHTML;
|
|
|
|
|
expect(m).toBe(startDate.format('MMM'));
|
|
|
|
|
expect(y).toBe(startDate.format('YYYY'));
|
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel').length).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('placement api work correctly', () => {
|
|
|
|
|
const { rerender } = render(<DatePicker.RangePicker open placement="topLeft" />);
|
2023-06-07 21:59:21 +08:00
|
|
|
|
expect(triggerProps?.builtinPlacements).toEqual(
|
2022-08-18 17:40:47 +08:00
|
|
|
|
expect.objectContaining({
|
|
|
|
|
topLeft: expect.objectContaining({ offset: [0, -4], points: ['bl', 'tl'] }),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
rerender(<DatePicker.RangePicker open placement="topRight" />);
|
2023-06-07 21:59:21 +08:00
|
|
|
|
expect(triggerProps?.builtinPlacements).toEqual(
|
2022-08-18 17:40:47 +08:00
|
|
|
|
expect.objectContaining({
|
|
|
|
|
topRight: expect.objectContaining({ offset: [0, -4], points: ['br', 'tr'] }),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
rerender(<DatePicker.RangePicker open placement="bottomLeft" />);
|
2023-06-07 21:59:21 +08:00
|
|
|
|
expect(triggerProps?.builtinPlacements).toEqual(
|
2022-08-18 17:40:47 +08:00
|
|
|
|
expect.objectContaining({
|
|
|
|
|
bottomLeft: expect.objectContaining({ offset: [0, 4], points: ['tl', 'bl'] }),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
rerender(<DatePicker.RangePicker open placement="bottomRight" />);
|
2023-06-07 21:59:21 +08:00
|
|
|
|
expect(triggerProps?.builtinPlacements).toEqual(
|
2022-08-18 17:40:47 +08:00
|
|
|
|
expect.objectContaining({
|
|
|
|
|
bottomRight: expect.objectContaining({ offset: [0, 4], points: ['tr', 'br'] }),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2022-09-08 14:33:11 +08:00
|
|
|
|
|
|
|
|
|
it('legacy dropdownClassName', () => {
|
|
|
|
|
resetWarned();
|
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2022-09-08 14:33:11 +08:00
|
|
|
|
const { container } = render(<DatePicker dropdownClassName="legacy" open />);
|
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
|
|
|
'Warning: [antd: DatePicker] `dropdownClassName` is deprecated. Please use `popupClassName` instead.',
|
|
|
|
|
);
|
|
|
|
|
expect(container.querySelector('.legacy')).toBeTruthy();
|
|
|
|
|
|
|
|
|
|
errSpy.mockRestore();
|
|
|
|
|
});
|
2023-04-12 17:20:08 +08:00
|
|
|
|
|
|
|
|
|
it('support DatePicker.generatePicker', () => {
|
|
|
|
|
const MyDatePicker = DatePicker.generatePicker(dayJsGenerateConfig);
|
|
|
|
|
const { container } = render(<MyDatePicker />);
|
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
|
|
|
});
|
2023-05-19 18:57:35 +08:00
|
|
|
|
|
|
|
|
|
it('kk:mm format', () => {
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<DatePicker defaultValue={dayjs()} format="kk:mm" showTime open />,
|
|
|
|
|
);
|
2024-01-29 15:34:48 +08:00
|
|
|
|
expect(container.querySelectorAll('.ant-picker-time-panel-column')).toHaveLength(2);
|
2023-05-19 18:57:35 +08:00
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(24);
|
|
|
|
|
expect(
|
|
|
|
|
container
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
|
|
|
|
|
.querySelectorAll('.ant-picker-time-panel-cell').length,
|
|
|
|
|
).toBe(60);
|
|
|
|
|
});
|
2023-08-04 16:14:56 +08:00
|
|
|
|
|
|
|
|
|
it('allows or prohibits clearing as applicable', async () => {
|
2024-02-01 16:26:38 +08:00
|
|
|
|
const somePoint = dayjs('2023-08-01');
|
|
|
|
|
const { rerender, container } = render(<DatePicker value={somePoint} />);
|
|
|
|
|
expect(getClearButton()).toBeTruthy();
|
2023-08-04 16:14:56 +08:00
|
|
|
|
|
2024-02-01 16:26:38 +08:00
|
|
|
|
rerender(<DatePicker value={somePoint} allowClear={false} />);
|
|
|
|
|
expect(getClearButton()).toBeFalsy();
|
2023-08-04 16:14:56 +08:00
|
|
|
|
|
2024-02-01 16:26:38 +08:00
|
|
|
|
rerender(<DatePicker value={somePoint} allowClear={{ clearIcon: <CloseCircleFilled /> }} />);
|
|
|
|
|
expect(getClearButton()).toBeTruthy();
|
2023-08-04 16:14:56 +08:00
|
|
|
|
|
|
|
|
|
rerender(
|
|
|
|
|
<DatePicker
|
2024-02-01 16:26:38 +08:00
|
|
|
|
value={somePoint}
|
2023-08-04 16:14:56 +08:00
|
|
|
|
allowClear={{ clearIcon: <div data-testid="custom-clear" /> }}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2024-02-01 16:26:38 +08:00
|
|
|
|
expect(getClearButton()).toBeTruthy();
|
|
|
|
|
expect(container.querySelector('[data-testid="custom-clear"]')).toBeTruthy();
|
2023-08-04 16:14:56 +08:00
|
|
|
|
|
2024-02-01 16:26:38 +08:00
|
|
|
|
rerender(<DatePicker value={somePoint} allowClear={{}} />);
|
|
|
|
|
expect(getClearButton()).toBeTruthy();
|
2023-08-04 16:14:56 +08:00
|
|
|
|
});
|
2022-08-18 17:40:47 +08:00
|
|
|
|
});
|