mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-26 12:10:06 +08:00
55c85f77a1
* deps: upgrade rc-menu, and close: #2837 * test: update snapshots * Update rc-calendar * Update rc-cascader * Update rc-dialog * Update dropdown * Update rc-select@7.1.0 * Update rc-slider * Update rc-time-picker * Update rc-tooltip * Update rc-tree-select * Mock rc-trigger and Portal * Fix animation warning when inlineCollapsed changes * fix: should use SubMenu[popupClassName] * Fix typescript error * Fix lint * fix: style for menu * Mock rc-trigger for React 15 * Remvoe allow_failures
69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
import Modal from '..';
|
|
|
|
const { confirm } = Modal;
|
|
|
|
describe('Modal.confirm triggers callbacks correctly', () => {
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
afterEach(() => {
|
|
errorSpy.mockReset();
|
|
document.body.innerHTML = '';
|
|
});
|
|
|
|
afterAll(() => {
|
|
errorSpy.mockRestore();
|
|
});
|
|
|
|
function $$(className) {
|
|
return document.body.querySelectorAll(className);
|
|
}
|
|
|
|
function open(args) {
|
|
confirm({
|
|
title: 'Want to delete these items?',
|
|
content: 'some descriptions',
|
|
...args,
|
|
});
|
|
}
|
|
|
|
it('trigger onCancel once when click on cancel button', () => {
|
|
const onCancel = jest.fn();
|
|
const onOk = jest.fn();
|
|
open({
|
|
onCancel,
|
|
onOk,
|
|
});
|
|
// first Modal
|
|
$$('.ant-btn')[0].click();
|
|
expect(onCancel.mock.calls.length).toBe(1);
|
|
expect(onOk.mock.calls.length).toBe(0);
|
|
});
|
|
|
|
it('trigger onOk once when click on ok button', () => {
|
|
const onCancel = jest.fn();
|
|
const onOk = jest.fn();
|
|
open({
|
|
onCancel,
|
|
onOk,
|
|
});
|
|
// second Modal
|
|
$$('.ant-btn-primary')[0].click();
|
|
expect(onCancel.mock.calls.length).toBe(0);
|
|
expect(onOk.mock.calls.length).toBe(1);
|
|
});
|
|
|
|
it('should allow Modal.comfirm without onCancel been set', () => {
|
|
open();
|
|
// Third Modal
|
|
$$('.ant-btn')[0].click();
|
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should allow Modal.comfirm without onOk been set', () => {
|
|
open();
|
|
// Fourth Modal
|
|
$$('.ant-btn-primary')[0].click();
|
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
});
|
|
});
|