2019-01-25 10:31:09 +08:00
|
|
|
import moment from 'moment';
|
2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2022-08-15 17:44:43 +08:00
|
|
|
import type { PickerLocale } from 'antd/es/date-picker/generatePicker';
|
2016-12-14 14:48:09 +08:00
|
|
|
import TimePicker from '..';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
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';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { resetWarned } from '../../_util/warning';
|
2022-08-15 17:44:43 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2016-12-14 14:48:09 +08:00
|
|
|
|
|
|
|
describe('TimePicker', () => {
|
2019-01-25 10:31:09 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
errorSpy.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
|
|
|
|
2020-04-22 15:58:57 +08:00
|
|
|
focusTest(TimePicker, { refFocus: true });
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(TimePicker);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(TimePicker);
|
2017-11-19 01:41:40 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
it('warning for addon', () => {
|
|
|
|
resetWarned();
|
|
|
|
const addon = () => (
|
|
|
|
<button className="my-btn" type="button">
|
2021-09-23 22:13:05 +08:00
|
|
|
OK
|
2019-12-11 23:32:19 +08:00
|
|
|
</button>
|
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
const { container } = render(<TimePicker addon={addon} open />);
|
|
|
|
expect(container.querySelectorAll('.my-btn').length).toBeTruthy();
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
2019-12-11 23:32:19 +08:00
|
|
|
'Warning: [antd: TimePicker] `addon` is deprecated. Please use `renderExtraFooter` instead.',
|
2019-01-25 10:31:09 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('not render clean icon when allowClear is false', () => {
|
2022-08-15 17:44:43 +08:00
|
|
|
const { container } = render(
|
2019-01-25 10:31:09 +08:00
|
|
|
<TimePicker defaultValue={moment('2000-01-01 00:00:00')} allowClear={false} />,
|
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-25 10:31:09 +08:00
|
|
|
});
|
2019-03-07 11:31:36 +08:00
|
|
|
|
|
|
|
it('clearIcon should render correctly', () => {
|
|
|
|
const clearIcon = <div className="test-clear-icon">test</div>;
|
2022-08-15 17:44:43 +08:00
|
|
|
const { container } = render(
|
|
|
|
<TimePicker clearIcon={clearIcon} value={moment('00:00:00', 'HH:mm:ss')} />,
|
2019-03-07 11:31:36 +08:00
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
expect(container.querySelector('.test-clear-icon')).toBeTruthy();
|
2019-03-07 11:31:36 +08:00
|
|
|
});
|
2019-04-04 14:01:28 +08:00
|
|
|
|
|
|
|
it('prop locale should works', () => {
|
2022-08-15 17:44:43 +08:00
|
|
|
const locale = { placeholder: 'Избери дата' };
|
|
|
|
const { container } = render(
|
|
|
|
<TimePicker
|
|
|
|
open
|
|
|
|
defaultValue={moment('2000-01-01 00:00:00')}
|
|
|
|
locale={locale as unknown as PickerLocale}
|
|
|
|
/>,
|
2019-06-19 19:09:08 +08:00
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
expect(Array.from(container.children)).toMatchSnapshot();
|
2019-04-04 14:01:28 +08:00
|
|
|
});
|
2020-04-14 16:49:58 +08:00
|
|
|
|
|
|
|
it('should pass popupClassName prop to Picker as dropdownClassName prop', () => {
|
|
|
|
const popupClassName = 'myCustomClassName';
|
2022-08-15 17:44:43 +08:00
|
|
|
const { container } = render(
|
2020-04-14 16:49:58 +08:00
|
|
|
<TimePicker
|
2022-08-15 17:44:43 +08:00
|
|
|
open
|
2020-04-14 16:49:58 +08:00
|
|
|
defaultOpenValue={moment('00:00:00', 'HH:mm:ss')}
|
|
|
|
popupClassName={popupClassName}
|
|
|
|
/>,
|
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
expect(container.querySelector(`.${popupClassName}`)).toBeTruthy();
|
2020-04-14 16:49:58 +08:00
|
|
|
});
|
2020-06-06 14:37:08 +08:00
|
|
|
|
2021-03-02 22:09:21 +08:00
|
|
|
it('should pass popupClassName prop to RangePicker as dropdownClassName prop', () => {
|
|
|
|
const popupClassName = 'myCustomClassName';
|
2022-08-15 17:44:43 +08:00
|
|
|
const { container } = render(
|
2021-03-02 22:09:21 +08:00
|
|
|
<TimePicker.RangePicker
|
2022-08-15 17:44:43 +08:00
|
|
|
open
|
2021-03-02 22:09:21 +08:00
|
|
|
defaultOpenValue={moment('00:00:00', 'HH:mm:ss')}
|
|
|
|
popupClassName={popupClassName}
|
|
|
|
/>,
|
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
expect(container.querySelector(`.${popupClassName}`)).toBeTruthy();
|
2021-03-02 22:09:21 +08:00
|
|
|
});
|
|
|
|
|
2022-08-05 11:21:07 +08:00
|
|
|
it('RangePicker should show warning when use dropdownClassName', () => {
|
2022-08-18 11:06:13 +08:00
|
|
|
render(<TimePicker.RangePicker dropdownClassName="myCustomClassName" />);
|
2022-08-05 11:21:07 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: RangePicker] `dropdownClassName` is deprecated which will be removed in next major version. Please use `popupClassName` instead.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('TimePicker should show warning when use dropdownClassName', () => {
|
2022-08-18 11:06:13 +08:00
|
|
|
render(<TimePicker dropdownClassName="myCustomClassName" />);
|
2022-08-05 11:21:07 +08:00
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: TimePicker] `dropdownClassName` is deprecated which will be removed in next major version. Please use `popupClassName` instead.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-06-06 14:37:08 +08:00
|
|
|
it('should support bordered', () => {
|
2022-08-15 17:44:43 +08:00
|
|
|
const { container } = render(
|
2020-06-06 14:37:08 +08:00
|
|
|
<TimePicker
|
|
|
|
className="custom-class"
|
|
|
|
defaultValue={moment('2000-01-01 00:00:00')}
|
|
|
|
bordered={false}
|
|
|
|
/>,
|
|
|
|
);
|
2022-08-15 17:44:43 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2020-06-06 14:37:08 +08:00
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|