ant-design-vue/components/popconfirm/__tests__/index.test.js

76 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import Popconfirm from '..';
function $$(className) {
return document.body.querySelectorAll(className);
2018-06-12 13:16:49 +00:00
}
describe('Popconfirm', () => {
2018-12-14 01:56:40 +00:00
// const eventObject = expect.objectContaining({
// target: expect.anything(),
// preventDefault: expect.any(Function),
// })
2018-06-12 13:16:49 +00:00
it('should popup Popconfirm dialog', async () => {
2019-01-12 03:33:27 +00:00
const onVisibleChange = jest.fn();
2018-06-12 13:16:49 +00:00
const wrapper = mount(
{
2019-01-12 03:33:27 +00:00
render() {
return (
<Popconfirm
title={<span class="popconfirm-test">Are you sure delete this task?</span>}
okText="Yes"
cancelText="No"
mouseEnterDelay={0}
mouseLeaveDelay={0}
onVisibleChange={onVisibleChange}
>
<span>Delete</span>
</Popconfirm>
);
2018-06-12 13:16:49 +00:00
},
2019-01-12 03:33:27 +00:00
},
{ sync: false, attachToDocument: true },
);
let triggerNode = null;
2018-06-12 13:16:49 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
triggerNode = wrapper.findAll('span').at(0);
triggerNode.trigger('click');
});
2018-06-12 13:16:49 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(onVisibleChange).toHaveBeenLastCalledWith(true, undefined);
expect($$('.popconfirm-test').length).toBe(1);
triggerNode.trigger('click');
}, 1000);
2018-06-12 13:16:49 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(onVisibleChange).toHaveBeenLastCalledWith(false, undefined);
});
});
2018-06-12 13:16:49 +00:00
it('should show overlay when trigger is clicked', async () => {
2019-01-12 03:33:27 +00:00
const popconfirm = mount(
{
render() {
return (
<Popconfirm ref="popconfirm" title="code">
<span>show me your code</span>
</Popconfirm>
);
},
2018-06-12 13:16:49 +00:00
},
2019-01-12 03:33:27 +00:00
{ sync: false },
);
2018-06-12 13:16:49 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect(popconfirm.vm.$refs.popconfirm.getPopupDomNode()).toBe(null);
2018-06-12 13:16:49 +00:00
2019-01-12 03:33:27 +00:00
popconfirm.find('span').trigger('click');
}, 1000);
2018-06-12 13:16:49 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
const popup = popconfirm.vm.$refs.popconfirm.getPopupDomNode();
expect(popup).not.toBe(null);
expect(popup.className).toContain('ant-popover-placement-top');
expect(popup.innerHTML).toMatchSnapshot();
}, 1000);
});
});