2017-03-30 16:06:03 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Modal from '..';
|
2020-05-05 12:03:16 +08:00
|
|
|
import Button from '../../button';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2017-03-30 16:06:03 +08:00
|
|
|
|
2017-11-11 00:07:03 +08:00
|
|
|
jest.mock('rc-util/lib/Portal');
|
|
|
|
|
2017-03-30 16:06:03 +08:00
|
|
|
class ModalTester extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = { visible: false };
|
|
|
|
}
|
2018-06-22 21:05:13 +08:00
|
|
|
|
2017-03-30 16:06:03 +08:00
|
|
|
componentDidMount() {
|
|
|
|
this.setState({ visible: true }); // eslint-disable-line react/no-did-mount-set-state
|
|
|
|
}
|
2018-06-22 21:05:13 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
saveContainer = container => {
|
2017-03-30 16:06:03 +08:00
|
|
|
this.container = container;
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2018-06-22 21:05:13 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
getContainer = () => this.container;
|
2018-06-22 21:05:13 +08:00
|
|
|
|
2017-03-30 16:06:03 +08:00
|
|
|
render() {
|
2018-06-22 21:05:13 +08:00
|
|
|
const { visible } = this.state;
|
2017-03-30 16:06:03 +08:00
|
|
|
return (
|
2017-04-05 16:21:21 +08:00
|
|
|
<div>
|
|
|
|
<div ref={this.saveContainer} />
|
2018-12-07 16:17:45 +08:00
|
|
|
<Modal {...this.props} visible={visible} getContainer={this.getContainer}>
|
2017-03-30 16:06:03 +08:00
|
|
|
Here is content of Modal
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Modal', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Modal);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Modal);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2017-03-30 16:06:03 +08:00
|
|
|
it('render correctly', () => {
|
|
|
|
const wrapper = mount(<ModalTester />);
|
2017-04-02 18:09:23 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2017-03-30 16:06:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('render without footer', () => {
|
|
|
|
const wrapper = mount(<ModalTester footer={null} />);
|
2017-04-02 18:09:23 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2017-03-30 16:06:03 +08:00
|
|
|
});
|
2019-03-07 12:45:14 +08:00
|
|
|
|
|
|
|
it('onCancel should be called', () => {
|
|
|
|
const onCancel = jest.fn();
|
2020-05-19 20:15:51 +08:00
|
|
|
const wrapper = mount(<Modal visible onCancel={onCancel} />);
|
|
|
|
wrapper.find('.ant-btn').first().simulate('click');
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onCancel).toHaveBeenCalled();
|
2019-03-07 12:45:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('onOk should be called', () => {
|
|
|
|
const onOk = jest.fn();
|
2020-05-19 20:15:51 +08:00
|
|
|
const wrapper = mount(<Modal visible onOk={onOk} />);
|
|
|
|
wrapper.find('.ant-btn').last().simulate('click');
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onOk).toHaveBeenCalled();
|
2019-03-07 12:45:14 +08:00
|
|
|
});
|
2019-08-17 20:55:59 +08:00
|
|
|
|
|
|
|
it('support closeIcon', () => {
|
|
|
|
const wrapper = mount(<Modal closeIcon={<a>closeIcon</a>} visible />);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2020-05-05 12:03:16 +08:00
|
|
|
|
|
|
|
it('danger type', () => {
|
|
|
|
const wrapper = mount(<Modal okType="danger" visible />);
|
|
|
|
expect(wrapper.find(Button).last().props().danger).toBeTruthy();
|
|
|
|
});
|
2017-03-30 16:06:03 +08:00
|
|
|
});
|