mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
test: migrate part of TimePicker tests (#37055)
* test: migrate part of TimePicker tests * test: test clearIcon * test: migrate part of TimePicker tests Co-authored-by: 二货机器人 <smith3816@gmail.com>
This commit is contained in:
parent
82ba5eac40
commit
19ab86e67a
@ -1,11 +1,12 @@
|
||||
import { mount } from 'enzyme';
|
||||
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(() => {});
|
||||
@ -29,69 +30,72 @@ describe('TimePicker', () => {
|
||||
OK
|
||||
</button>
|
||||
);
|
||||
const wrapper = mount(<TimePicker addon={addon} open />);
|
||||
|
||||
expect(wrapper.find('.my-btn').length).toBeTruthy();
|
||||
const { container } = render(<TimePicker addon={addon} open />);
|
||||
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 wrapper = mount(
|
||||
const { container } = render(
|
||||
<TimePicker defaultValue={moment('2000-01-01 00:00:00')} allowClear={false} />,
|
||||
);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('clearIcon should render correctly', () => {
|
||||
const clearIcon = <div className="test-clear-icon">test</div>;
|
||||
const wrapper = mount(<TimePicker clearIcon={clearIcon} />);
|
||||
expect(wrapper.find('Picker').last().prop('clearIcon')).toEqual(
|
||||
<div className="test-clear-icon">test</div>,
|
||||
const { container } = render(
|
||||
<TimePicker clearIcon={clearIcon} value={moment('00:00:00', 'HH:mm:ss')} />,
|
||||
);
|
||||
expect(container.querySelector('.test-clear-icon')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('prop locale should works', () => {
|
||||
const locale = {
|
||||
placeholder: 'Избери дата',
|
||||
};
|
||||
const wrapper = mount(
|
||||
<TimePicker defaultValue={moment('2000-01-01 00:00:00')} open locale={locale} />,
|
||||
const locale = { placeholder: 'Избери дата' };
|
||||
const { container } = render(
|
||||
<TimePicker
|
||||
open
|
||||
defaultValue={moment('2000-01-01 00:00:00')}
|
||||
locale={locale as unknown as PickerLocale}
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
expect(Array.from(container.children)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should pass popupClassName prop to Picker as dropdownClassName prop', () => {
|
||||
const popupClassName = 'myCustomClassName';
|
||||
const wrapper = mount(
|
||||
const { container } = render(
|
||||
<TimePicker
|
||||
open
|
||||
defaultOpenValue={moment('00:00:00', 'HH:mm:ss')}
|
||||
popupClassName={popupClassName}
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find('Picker').last().prop('dropdownClassName')).toEqual(popupClassName);
|
||||
expect(container.querySelector(`.${popupClassName}`)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should pass popupClassName prop to RangePicker as dropdownClassName prop', () => {
|
||||
const popupClassName = 'myCustomClassName';
|
||||
const wrapper = mount(
|
||||
const { container } = render(
|
||||
<TimePicker.RangePicker
|
||||
open
|
||||
defaultOpenValue={moment('00:00:00', 'HH:mm:ss')}
|
||||
popupClassName={popupClassName}
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find('RangePicker').last().prop('dropdownClassName')).toEqual(popupClassName);
|
||||
expect(container.querySelector(`.${popupClassName}`)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support bordered', () => {
|
||||
const wrapper = mount(
|
||||
const { container } = render(
|
||||
<TimePicker
|
||||
className="custom-class"
|
||||
defaultValue={moment('2000-01-01 00:00:00')}
|
||||
bordered={false}
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user