2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import TimePicker from '..';
|
2019-04-17 01:00:27 +00:00
|
|
|
import moment from 'moment';
|
2019-01-12 03:33:27 +00:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2020-03-07 11:45:13 +00:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-08-04 09:50:19 +00:00
|
|
|
import { sleep } from '../../../tests/utils';
|
2018-06-17 07:57:09 +00:00
|
|
|
|
|
|
|
describe('TimePicker', () => {
|
2019-04-17 01:00:27 +00:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2020-08-04 09:50:19 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
document.body.innerHTML = '';
|
|
|
|
});
|
2019-04-17 01:00:27 +00:00
|
|
|
afterEach(() => {
|
|
|
|
errorSpy.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
focusTest(TimePicker);
|
2020-03-07 11:45:13 +00:00
|
|
|
mountTest(TimePicker);
|
2018-06-17 07:57:09 +00:00
|
|
|
|
2020-08-04 09:50:19 +00:00
|
|
|
it('renders addon correctly', async () => {
|
|
|
|
mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <TimePicker open addon={() => <button type="button">Ok</button>} />;
|
|
|
|
},
|
2018-06-17 07:57:09 +00:00
|
|
|
},
|
2020-08-04 09:50:19 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
|
|
|
);
|
|
|
|
await sleep();
|
|
|
|
expect(document.body.querySelector('.ant-time-picker-panel-addon').outerHTML).toMatchSnapshot();
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2019-04-17 01:00:27 +00:00
|
|
|
|
|
|
|
it('allowEmpty deprecated', () => {
|
|
|
|
mount({
|
|
|
|
render() {
|
|
|
|
return <TimePicker allowEmpty />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(errorSpy).toBeCalledWith(
|
2020-03-07 11:45:13 +00:00
|
|
|
'Warning: [antdv: TimePicker] `allowEmpty` is deprecated. Please use `allowClear` instead.',
|
2019-04-17 01:00:27 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('not render clean icon when allowClear is false', () => {
|
2019-05-28 03:37:38 +00:00
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return <TimePicker defaultValue={moment('2000-01-01 00:00:00')} allowClear={false} />;
|
|
|
|
},
|
|
|
|
});
|
2019-04-17 01:00:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|