mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 19:19:26 +08:00
test Popconfirm
This commit is contained in:
parent
aff9d8fc62
commit
d58c0780f9
@ -45,4 +45,41 @@ describe('Popconfirm', () => {
|
|||||||
expect(popup.innerHTML).toMatchSnapshot();
|
expect(popup.innerHTML).toMatchSnapshot();
|
||||||
expect(popup.innerHTML).toMatchSnapshot();
|
expect(popup.innerHTML).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be controlled by visible', () => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
const popconfirm = mount(
|
||||||
|
<Popconfirm title="code">
|
||||||
|
<span>show me your code</span>
|
||||||
|
</Popconfirm>
|
||||||
|
);
|
||||||
|
expect(popconfirm.instance().getPopupDomNode()).toBeFalsy();
|
||||||
|
popconfirm.setProps({ visible: true });
|
||||||
|
expect(popconfirm.instance().getPopupDomNode()).toBeTruthy();
|
||||||
|
expect(popconfirm.instance().getPopupDomNode().className).not.toContain('ant-popover-hidden');
|
||||||
|
popconfirm.setProps({ visible: false });
|
||||||
|
jest.runAllTimers();
|
||||||
|
expect(popconfirm.instance().getPopupDomNode().className).toContain('ant-popover-hidden');
|
||||||
|
jest.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should trigger onConfirm and onCancel', () => {
|
||||||
|
const confirm = jest.fn();
|
||||||
|
const cancel = jest.fn();
|
||||||
|
const onVisibleChange = jest.fn();
|
||||||
|
const popconfirm = mount(
|
||||||
|
<Popconfirm title="code" onConfirm={confirm} onCancel={cancel} onVisibleChange={onVisibleChange}>
|
||||||
|
<span>show me your code</span>
|
||||||
|
</Popconfirm>
|
||||||
|
);
|
||||||
|
const triggerNode = popconfirm.find('span').at(0);
|
||||||
|
triggerNode.simulate('click');
|
||||||
|
popconfirm.find('.ant-btn-primary').simulate('click');
|
||||||
|
expect(confirm).toHaveBeenCalled();
|
||||||
|
expect(onVisibleChange).toHaveBeenLastCalledWith(false);
|
||||||
|
triggerNode.simulate('click');
|
||||||
|
popconfirm.find('.ant-btn').at(0).simulate('click');
|
||||||
|
expect(cancel).toHaveBeenCalled();
|
||||||
|
expect(onVisibleChange).toHaveBeenLastCalledWith(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user