ant-design/components/drawer/__tests__/DrawerEvent.test.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-06-21 12:32:13 +08:00
import React from 'react';
import Drawer from '..';
import { render, fireEvent } from '../../../tests/utils';
2018-06-21 12:32:13 +08:00
describe('Drawer', () => {
const getDrawer = props => (
<Drawer visible getContainer={false} {...props}>
Here is content of Drawer
</Drawer>
);
2018-06-21 12:32:13 +08:00
it('render correctly', () => {
const { container, asFragment, rerender } = render(getDrawer());
expect(container.querySelector('.ant-drawer-body')).toBeTruthy();
2018-06-21 12:32:13 +08:00
rerender(getDrawer({ visible: false }));
2018-06-21 12:32:13 +08:00
expect(container.querySelector('.ant-drawer-body').textContent).toEqual(
'Here is content of Drawer',
);
2018-06-21 12:32:13 +08:00
expect(asFragment().firstChild).toMatchSnapshot();
2018-06-21 12:32:13 +08:00
});
it('mask trigger onClose', () => {
const onClose = jest.fn();
const { container } = render(getDrawer({ onClose }));
2018-06-21 12:32:13 +08:00
fireEvent.click(container.querySelector('.ant-drawer-mask'));
expect(onClose).toHaveBeenCalled();
2018-06-21 12:32:13 +08:00
});
it('close button trigger onClose', () => {
const onClose = jest.fn();
const { container } = render(getDrawer({ onClose }));
2018-06-21 12:32:13 +08:00
fireEvent.click(container.querySelector('.ant-drawer-close'));
expect(onClose).toHaveBeenCalled();
2018-06-21 12:32:13 +08:00
});
it('maskClosable no trigger onClose', () => {
const onClose = jest.fn();
const { container } = render(getDrawer({ onClose, maskClosable: false }));
2018-06-21 12:32:13 +08:00
fireEvent.click(container.querySelector('.ant-drawer-mask'));
expect(onClose).not.toHaveBeenCalled();
2018-06-21 12:32:13 +08:00
});
2018-07-20 18:51:10 +08:00
it('dom should be removed after close when destroyOnClose is true', () => {
const { container, rerender } = render(getDrawer({ destroyOnClose: true }));
2018-07-20 18:51:10 +08:00
rerender(getDrawer({ destroyOnClose: true, visible: false }));
fireEvent.transitionEnd(container.querySelector('.ant-drawer-wrapper-body'));
expect(container.querySelector('.ant-drawer-wrapper-body')).toBeFalsy();
});
it('dom should be existed after close when destroyOnClose is false', () => {
const { container, rerender } = render(getDrawer());
expect(container.querySelector('.ant-drawer-wrapper-body')).toBeTruthy();
2018-07-20 18:51:10 +08:00
rerender(getDrawer({ visible: false }));
fireEvent.transitionEnd(container.querySelector('.ant-drawer-wrapper-body'));
2018-07-20 18:51:10 +08:00
expect(container.querySelector('.ant-drawer-wrapper-body')).toBeTruthy();
2018-07-20 18:51:10 +08:00
});
2018-06-21 12:32:13 +08:00
});