2016-12-14 14:48:09 +08:00
|
|
|
import React from 'react';
|
2019-12-11 23:32:19 +08:00
|
|
|
import { mount } from 'enzyme';
|
2019-01-25 10:31:09 +08:00
|
|
|
import moment from 'moment';
|
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';
|
2019-12-11 23:32:19 +08:00
|
|
|
import { resetWarned } from '../../_util/warning';
|
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();
|
|
|
|
});
|
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
focusTest(TimePicker, true);
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(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">
|
|
|
|
Ok
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
const wrapper = mount(<TimePicker addon={addon} open />);
|
2019-01-25 10:31:09 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
expect(wrapper.find('.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', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<TimePicker defaultValue={moment('2000-01-01 00:00:00')} allowClear={false} />,
|
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-03-07 11:31:36 +08:00
|
|
|
|
|
|
|
it('clearIcon should render correctly', () => {
|
|
|
|
const clearIcon = <div className="test-clear-icon">test</div>;
|
|
|
|
const wrapper = mount(<TimePicker clearIcon={clearIcon} />);
|
|
|
|
expect(wrapper.find('Picker').prop('clearIcon')).toEqual(
|
2019-12-11 23:32:19 +08:00
|
|
|
<div className="test-clear-icon">test</div>,
|
2019-03-07 11:31:36 +08:00
|
|
|
);
|
|
|
|
});
|
2019-04-04 14:01:28 +08:00
|
|
|
|
|
|
|
it('prop locale should works', () => {
|
|
|
|
const locale = {
|
|
|
|
placeholder: 'Избери дата',
|
|
|
|
};
|
2019-06-19 19:09:08 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<TimePicker defaultValue={moment('2000-01-01 00:00:00')} open locale={locale} />,
|
|
|
|
);
|
2019-04-04 14:01:28 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|