2016-12-14 14:48:09 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount, render } from 'enzyme';
|
|
|
|
import RcTimePicker from 'rc-time-picker/lib/TimePicker';
|
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';
|
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();
|
|
|
|
});
|
|
|
|
|
2017-11-19 01:41:40 +08:00
|
|
|
focusTest(TimePicker);
|
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
it('renders addon correctly', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
const addon = () => <button type="button">Ok</button>;
|
2016-12-14 14:48:09 +08:00
|
|
|
const wrapper = mount(<TimePicker addon={addon} />);
|
|
|
|
const rcTimePicker = wrapper.find(RcTimePicker);
|
|
|
|
const addonWrapper = render(rcTimePicker.props().addon());
|
|
|
|
|
2017-04-02 18:09:23 +08:00
|
|
|
expect(addonWrapper).toMatchSnapshot();
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|
2019-01-25 10:31:09 +08:00
|
|
|
|
|
|
|
it('allowEmpty deprecated', () => {
|
|
|
|
mount(<TimePicker allowEmpty />);
|
|
|
|
expect(errorSpy).toBeCalledWith(
|
2019-02-27 15:32:29 +08:00
|
|
|
'Warning: [antd: TimePicker] `allowEmpty` is deprecated. Please use `allowClear` 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('handleChange should work correctly', done => {
|
|
|
|
const date = moment('2000-01-01 00:00:00');
|
|
|
|
const onChange = (value, formattedValue) => {
|
|
|
|
expect(value).toBe(date);
|
|
|
|
expect(formattedValue).toBe(date.format('HH:mm:ss'));
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
const wrapper = mount(<TimePicker onChange={onChange} />).instance();
|
|
|
|
wrapper.handleChange(date);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handleOpenClose should work correctly', done => {
|
|
|
|
const onOpenChange = open => {
|
|
|
|
expect(open).toBe(true);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
const wrapper = mount(<TimePicker onOpenChange={onOpenChange} />).instance();
|
|
|
|
wrapper.handleOpenClose({ open: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
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(
|
|
|
|
<div className="test-clear-icon ant-time-picker-clear">test</div>,
|
|
|
|
);
|
|
|
|
});
|
2016-12-14 14:48:09 +08:00
|
|
|
});
|