You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
8 years ago
|
import Modal from '..';
|
||
|
|
||
|
const confirm = Modal.confirm;
|
||
|
|
||
|
describe('Modal.confirm triggers callbacks correctly', () => {
|
||
8 years ago
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||
|
|
||
|
afterEach(() => {
|
||
|
errorSpy.mockReset();
|
||
|
});
|
||
|
|
||
|
afterAll(() => {
|
||
|
errorSpy.mockRestore();
|
||
|
});
|
||
|
|
||
8 years ago
|
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')[1].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')[4].click();
|
||
8 years ago
|
expect(errorSpy).not.toHaveBeenCalled();
|
||
8 years ago
|
});
|
||
|
|
||
|
it('should allow Modal.comfirm without onOk been set', () => {
|
||
|
open();
|
||
|
// Fourth Modal
|
||
|
$$('.ant-btn-primary')[3].click();
|
||
8 years ago
|
expect(errorSpy).not.toHaveBeenCalled();
|
||
8 years ago
|
});
|
||
|
});
|