import { openSearchDrawer, openSubmapsDrawer } from '@/redux/drawer/drawer.slice'; import { StoreType } from '@/redux/store'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { act, fireEvent, render, screen } from '@testing-library/react'; import { Drawer } from './Drawer.component'; const renderComponent = (): { store: StoreType } => { const { Wrapper, store } = getReduxWrapperWithStore(); return ( render( <Wrapper> <Drawer /> </Wrapper>, ), { store, } ); }; describe('Drawer - component', () => { it('should render Drawer', () => { renderComponent(); expect(screen.getByRole('drawer')).toBeInTheDocument(); }); it('should not display drawer when its not open', () => { renderComponent(); expect(screen.getByRole('drawer')).not.toHaveClass('translate-x-0'); }); describe('search drawer ', () => { it('should open drawer and display search drawer content', async () => { const { store } = renderComponent(); expect(screen.queryByTestId('search-drawer-content')).not.toBeInTheDocument(); await act(() => { store.dispatch(openSearchDrawer()); }); expect(screen.getByTestId('search-drawer-content')).toBeInTheDocument(); }); it('should close drawer after pressing close button', async () => { const { store } = renderComponent(); await act(() => { store.dispatch(openSearchDrawer()); }); expect(screen.getByTestId('search-drawer-content')).toBeInTheDocument(); const button = screen.getByRole('close-drawer-button'); await act(() => { fireEvent.click(button); }); expect(screen.getByRole('drawer')).not.toHaveClass('translate-x-0'); expect(screen.queryByTestId('search-drawer-content')).not.toBeInTheDocument(); }); }); describe('submap drawer', () => { it('should open drawer and display submaps', async () => { const { store } = renderComponent(); expect(screen.queryByTestId('submap-drawer')).not.toBeInTheDocument(); await act(() => { store.dispatch(openSubmapsDrawer()); }); expect(screen.getByTestId('submap-drawer')).toBeInTheDocument(); }); }); });