import type { DrawerPopupProps } from 'rc-drawer/lib/DrawerPopup'; import React, { useState } from 'react'; import Drawer from '..'; import { fireEvent, render } from '../../../tests/utils'; import Button from '../../button'; interface DrawerPropsType { push?: DrawerPopupProps['push']; placement?: DrawerPopupProps['placement']; } const MultiDrawer: React.FC = (props) => { const { placement, push } = props; const [open, setOpen] = useState(false); const [hasChildren, setHasChildren] = useState(true); const [childrenDrawer, setChildrenDrawer] = useState(false); const showDrawer = () => { setOpen(true); setHasChildren(true); }; const onClose = () => { setOpen(false); }; const showChildrenDrawer = () => { setChildrenDrawer(true); setHasChildren(true); }; const onChildrenDrawerClose = () => { setChildrenDrawer(false); }; const onRemoveChildDrawer = () => { setHasChildren(false); }; return (
{hasChildren && (
This is two-level drawer
)}
{String(childrenDrawer)}
); }; describe('Drawer', () => { it('render right MultiDrawer', () => { const { container } = render(); fireEvent.click(container.querySelector('button#open_drawer')!); fireEvent.click(container.querySelector('button#open_two_drawer')!); expect(container.querySelector('.ant-drawer-content-wrapper')).toHaveStyle({ transform: 'translateX(-180px)', }); expect(container.querySelectorAll('#two_drawer_text').length).toBe(1); }); it('render left MultiDrawer', () => { const { container } = render(); fireEvent.click(container.querySelector('button#open_drawer')!); fireEvent.click(container.querySelector('button#open_two_drawer')!); expect(container.querySelector('.ant-drawer-content-wrapper')).toHaveStyle({ transform: 'translateX(180px)', }); expect(container.querySelectorAll('#two_drawer_text').length).toBe(1); fireEvent.click(container.querySelector('.Two-level .ant-drawer-close')!); expect(container.querySelector('.childrenDrawer')?.innerHTML).toEqual('false'); }); it('render top MultiDrawer', () => { const { container } = render(); fireEvent.click(container.querySelector('button#open_drawer')!); fireEvent.click(container.querySelector('button#open_two_drawer')!); expect(container.querySelector('.ant-drawer-content-wrapper')).toHaveStyle({ transform: 'translateY(180px)', }); expect(container.querySelectorAll('#two_drawer_text').length).toBe(1); }); it('render MultiDrawer is child in unmount', () => { const { container: wrapper } = render(); fireEvent.click(wrapper.querySelector('button#open_drawer')!); fireEvent.click(wrapper.querySelector('button#open_two_drawer')!); fireEvent.click(wrapper.querySelector('button#remove_drawer')!); // Strange, testing-lib get wrong style in next branch. expect((wrapper.querySelector('.ant-drawer-content-wrapper') as any).style).toEqual( expect.objectContaining({ transform: '', }), ); fireEvent.click(wrapper.querySelector('button#open_two_drawer')!); expect(wrapper.querySelector('.ant-drawer-content-wrapper')).toHaveStyle({ transform: 'translateY(180px)', }); expect(wrapper.querySelectorAll('#two_drawer_text').length).toBe(1); }); it('custom MultiDrawer push distance', () => { const { container } = render(); fireEvent.click(container.querySelector('button#open_drawer')!); fireEvent.click(container.querySelector('button#open_two_drawer')!); expect(container.querySelector('.ant-drawer-content-wrapper')).toHaveStyle({ transform: 'translateX(-256px)', }); }); it('custom MultiDrawer push with true', () => { const { container } = render(); fireEvent.click(container.querySelector('button#open_drawer')!); fireEvent.click(container.querySelector('button#open_two_drawer')!); expect(container.querySelector('.ant-drawer-content-wrapper')).toHaveStyle({ transform: 'translateX(-180px)', }); }); it('custom MultiDrawer push with false', () => { const { container: wrapper } = render(); fireEvent.click(wrapper.querySelector('button#open_drawer')!); fireEvent.click(wrapper.querySelector('button#open_two_drawer')!); expect((wrapper.querySelector('.ant-drawer-content-wrapper') as any).style).toEqual( expect.objectContaining({ transform: '', }), ); }); });