import moment from 'moment';
import React from 'react';
import type { PickerLocale } from 'antd/es/date-picker/generatePicker';
import TimePicker from '..';
import focusTest from '../../../tests/shared/focusTest';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { resetWarned } from '../../_util/warning';
import { render } from '../../../tests/utils';
describe('TimePicker', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
afterEach(() => {
errorSpy.mockReset();
});
afterAll(() => {
errorSpy.mockRestore();
});
focusTest(TimePicker, { refFocus: true });
mountTest(TimePicker);
rtlTest(TimePicker);
it('warning for addon', () => {
resetWarned();
const addon = () => (
);
const { container } = render();
expect(container.querySelectorAll('.my-btn').length).toBeTruthy();
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: TimePicker] `addon` is deprecated. Please use `renderExtraFooter` instead.',
);
});
it('not render clean icon when allowClear is false', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
it('clearIcon should render correctly', () => {
const clearIcon =
test
;
const { container } = render(
,
);
expect(container.querySelector('.test-clear-icon')).toBeTruthy();
});
it('prop locale should works', () => {
const locale = { placeholder: 'Избери дата' };
const { container } = render(
,
);
expect(Array.from(container.children)).toMatchSnapshot();
});
it('should pass popupClassName prop to Picker as dropdownClassName prop', () => {
const popupClassName = 'myCustomClassName';
const { container } = render(
,
);
expect(container.querySelector(`.${popupClassName}`)).toBeTruthy();
});
it('should pass popupClassName prop to RangePicker as dropdownClassName prop', () => {
const popupClassName = 'myCustomClassName';
const { container } = render(
,
);
expect(container.querySelector(`.${popupClassName}`)).toBeTruthy();
});
it('RangePicker should show warning when use dropdownClassName', () => {
render();
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', () => {
render();
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: TimePicker] `dropdownClassName` is deprecated which will be removed in next major version. Please use `popupClassName` instead.',
);
});
it('should support bordered', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
});