test: update time-picker test

pull/2682/head
tanjinzhou 2020-08-04 17:50:19 +08:00
parent 3e2fe2a924
commit 61337aecef
6 changed files with 36 additions and 17 deletions

@ -1 +1 @@
Subproject commit 7c35d4f5f4ab0ea204cf944ef70e8705f41c7c3f Subproject commit a5c0b0c35c3b6d8284caa99b11229b709d035e6d

View File

@ -1,5 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`TimePicker not render clean icon when allowClear is false 1`] = `<span class="ant-time-picker"><input type="text" placeholder="Select time" class="ant-time-picker-input"><span class="ant-time-picker-icon"><span role="img" aria-label="clock-circle" class="anticon anticon-clock-circle ant-time-picker-clock-icon"><svg viewBox="64 64 896 896" focusable="false" data-icon="clock-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M686.7 638.6L544.1 535.5V288c0-4.4-3.6-8-8-8H488c-4.4 0-8 3.6-8 8v275.4c0 2.6 1.2 5 3.3 6.5l165.4 120.6c3.6 2.6 8.6 1.8 11.2-1.7l28.6-39c2.6-3.7 1.8-8.7-1.8-11.2z"></path></svg></span></span></span>`; exports[`TimePicker not render clean icon when allowClear is false 1`] = `
<!----><span class="ant-time-picker"><input class="ant-time-picker-input" type="text" placeholder="Select time"><span class="ant-time-picker-icon"><span role="img" aria-label="clock-circle" class="anticon anticon-clock-circle ant-time-picker-clock-icon"><svg class="" data-icon="clock-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896" focusable="false"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M686.7 638.6L544.1 535.5V288c0-4.4-3.6-8-8-8H488c-4.4 0-8 3.6-8 8v275.4c0 2.6 1.2 5 3.3 6.5l165.4 120.6c3.6 2.6 8.6 1.8 11.2-1.7l28.6-39c2.6-3.7 1.8-8.7-1.8-11.2z"></path></svg></span></span>
<!----></span>
`;
exports[`TimePicker renders addon correctly 1`] = `<div class="ant-time-picker-panel-addon"><button type="button">Ok</button></div>`; exports[`TimePicker renders addon correctly 1`] = `<div class="ant-time-picker-panel-addon"><button type="button">Ok</button></div>`;

View File

@ -4,10 +4,13 @@ import TimePicker from '..';
import moment from 'moment'; import moment from 'moment';
import focusTest from '../../../tests/shared/focusTest'; import focusTest from '../../../tests/shared/focusTest';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import { sleep } from '../../../tests/utils';
describe('TimePicker', () => { describe('TimePicker', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
beforeEach(() => {
document.body.innerHTML = '';
});
afterEach(() => { afterEach(() => {
errorSpy.mockReset(); errorSpy.mockReset();
}); });
@ -19,19 +22,17 @@ describe('TimePicker', () => {
focusTest(TimePicker); focusTest(TimePicker);
mountTest(TimePicker); mountTest(TimePicker);
it('renders addon correctly', () => { it('renders addon correctly', async () => {
const wrapper = mount({ mount(
render() { {
return <TimePicker addon={() => <button type="button">Ok</button>} />; render() {
return <TimePicker open addon={() => <button type="button">Ok</button>} />;
},
}, },
}); { sync: false, attachTo: 'body' },
const vcTimePicker = wrapper.find({ name: VcTimePicker.name }); );
const addonWrapper = mount({ await sleep();
render() { expect(document.body.querySelector('.ant-time-picker-panel-addon').outerHTML).toMatchSnapshot();
return vcTimePicker.vm.addon();
},
});
expect(addonWrapper.html()).toMatchSnapshot();
}); });
it('allowEmpty deprecated', () => { it('allowEmpty deprecated', () => {

View File

@ -91,6 +91,10 @@ export default {
}); });
this._component = null; this._component = null;
this.focusTime = null; this.focusTime = null;
this.clickOutsideHandler = null;
this.contextmenuOutsideHandler1 = null;
this.contextmenuOutsideHandler2 = null;
this.touchOutsideHandler = null;
return { return {
prevPopupVisible: popupVisible, prevPopupVisible: popupVisible,
sPopupVisible: popupVisible, sPopupVisible: popupVisible,

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/tabs/demo/index'; import demo from '../antdv-demo/docs/time-picker/demo/index';
export default { export default {
components: { components: {

View File

@ -3,7 +3,18 @@ export default function mountTest(Component) {
describe(`mount and unmount`, () => { describe(`mount and unmount`, () => {
// https://github.com/ant-design/ant-design/pull/18441 // https://github.com/ant-design/ant-design/pull/18441
it(`component could be updated and unmounted without errors`, () => { it(`component could be updated and unmounted without errors`, () => {
const wrapper = mount(Component, { sync: false, attachTo: 'body' }); const wrapper = mount(
{
render() {
return (
<div>
<Component />
</div>
);
},
},
{ sync: false, attachTo: 'body' },
);
expect(() => { expect(() => {
wrapper.vm.$forceUpdate(); wrapper.vm.$forceUpdate();
wrapper.unmount(); wrapper.unmount();