import React from 'react'; import { act } from 'react-dom/test-utils'; import type { DrawerProps } from '..'; import Drawer from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { fireEvent, render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; import { resetWarned } from '../../_util/warning'; const DrawerTest: React.FC = ({ getContainer }) => (
Here is content of Drawer
); describe('Drawer', () => { mountTest(Drawer); rtlTest(Drawer); beforeEach(() => { jest.useFakeTimers(); }); afterEach(() => { jest.useRealTimers(); }); function triggerMotion() { act(() => { jest.runAllTimers(); }); const mask = document.querySelector('.ant-drawer-mask'); if (mask) { fireEvent.animationEnd(mask); } const panel = document.querySelector('.ant-drawer-content'); if (panel) { fireEvent.animationEnd(panel); } act(() => { jest.runAllTimers(); }); } it('render correctly', () => { const { container: wrapper } = render( Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('getContainer return undefined', () => { const { container, rerender } = render( undefined as unknown as HTMLElement} />, ); triggerMotion(); expect(container.firstChild).toMatchSnapshot(); rerender(); triggerMotion(); expect(container.firstChild).toMatchSnapshot(); }); it('render top drawer', () => { const { container } = render( Here is content of Drawer , ); triggerMotion(); expect(container.firstChild).toMatchSnapshot(); }); it('have a title', () => { const { container } = render( Here is content of Drawer , ); triggerMotion(); expect(container.firstChild).toMatchSnapshot(); }); it('closable is false', () => { const { container: wrapper } = render( Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('destroyOnClose is true', () => { const { container: wrapper } = render( Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('className is test_drawer', () => { const { container: wrapper } = render( Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('style/drawerStyle/headerStyle/bodyStyle should work', () => { const style = { backgroundColor: '#08c', }; const { container: wrapper } = render( Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('have a footer', () => { const { container: wrapper } = render( Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('forceRender works', () => { const { baseElement, rerender } = render( , ); expect(baseElement.querySelectorAll('button.forceRender').length).toBe(0); rerender( , ); expect(baseElement.querySelectorAll('button.forceRender').length).toBe(1); }); it('support closeIcon', () => { const { container: wrapper } = render( close} width={400} getContainer={false}> Here is content of Drawer , ); triggerMotion(); expect(wrapper.firstChild).toMatchSnapshot(); }); it('ConfigProvider should not warning', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); render( Bamboo is Light , ); expect(errorSpy).not.toHaveBeenCalled(); errorSpy.mockRestore(); }); it('zIndex should work', () => { const { container } = render(); expect(container.querySelector('.ant-drawer')).toHaveStyle({ zIndex: 903, }); }); describe('style migrate', () => { it('not warning with getContainer', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); resetWarned(); render( document.body} />); expect(errorSpy).not.toHaveBeenCalled(); errorSpy.mockRestore(); }); it('not warning with getContainer false', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); resetWarned(); render(); expect(errorSpy).not.toHaveBeenCalled(); errorSpy.mockRestore(); }); it('warning with getContainer & style', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); resetWarned(); render(); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Drawer] `style` is replaced by `rootStyle` in v5. Please check that `position: absolute` is necessary.', ); errorSpy.mockRestore(); }); }); });