ant-design/components/drawer/__tests__/DrawerEvent.test.js
afc163 30ac6bd4e4
test: wrap React.StrictMode for test cases (#35026)
* test: React StrictMode

* test: fix Spin test

* chore: wrapper enzyme

* test: fix setState

* test: more test cover

* test: more test cover

* test: more test cover

* test: more test cover

* test: more test cover

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: more test case

* test: disable part of it

* test: fix test & add placeholder

* test: Use orign enzyme mount

Co-authored-by: zombiej <smith3816@gmail.com>
2022-04-18 21:02:11 +08:00

68 lines
2.2 KiB
JavaScript

import React from 'react';
import Drawer from '..';
import { render, fireEvent } from '../../../tests/utils';
describe('Drawer', () => {
const getDrawer = props => (
<Drawer visible getContainer={false} {...props}>
Here is content of Drawer
</Drawer>
);
it('render correctly', () => {
const { container, asFragment, rerender } = render(getDrawer());
expect(container.querySelector('.ant-drawer-body')).toBeTruthy();
rerender(getDrawer({ visible: false }));
expect(container.querySelector('.ant-drawer-body').textContent).toEqual(
'Here is content of Drawer',
);
expect(asFragment().firstChild).toMatchSnapshot();
});
it('mask trigger onClose', () => {
const onClose = jest.fn();
const { container } = render(getDrawer({ onClose }));
fireEvent.click(container.querySelector('.ant-drawer-mask'));
expect(onClose).toHaveBeenCalled();
});
it('close button trigger onClose', () => {
const onClose = jest.fn();
const { container } = render(getDrawer({ onClose }));
fireEvent.click(container.querySelector('.ant-drawer-close'));
expect(onClose).toHaveBeenCalled();
});
it('maskClosable no trigger onClose', () => {
const onClose = jest.fn();
const { container } = render(getDrawer({ onClose, maskClosable: false }));
fireEvent.click(container.querySelector('.ant-drawer-mask'));
expect(onClose).not.toHaveBeenCalled();
});
it('dom should be removed after close when destroyOnClose is true', () => {
const { container, rerender } = render(getDrawer({ destroyOnClose: true }));
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();
rerender(getDrawer({ visible: false }));
fireEvent.transitionEnd(container.querySelector('.ant-drawer-wrapper-body'));
expect(container.querySelector('.ant-drawer-wrapper-body')).toBeTruthy();
});
});