import { render, screen } from '../test-utils'; import SlidingPanel, { SlidingPanelProps } from './SlidingPanel'; describe('SlidingPanel', () => { const initialProps: SlidingPanelProps = { open: true, children:
Content
, testId: 'wrapper', }; const customRender = (overrides: Partial = {}) => render(); describe('open', () => { it('should respect open=false', () => { customRender({ open: false }); expect(screen.queryByTestId('wrapper')).not.toBeInTheDocument(); }); it('should respect open=true', () => { customRender(); expect(screen.getByTestId('wrapper')).toBeInTheDocument(); }); }); describe('position', () => { it(`should default to 'left'`, () => { customRender(); expect(screen.queryByTestId('wrapper')).toHaveClass(`sliding-panel--open-left`); }); (['left', 'right', 'top', 'bottom'] as const).forEach((position) => { describe(position, () => { it(`should add the classname`, () => { customRender({ position }); expect(screen.queryByTestId('wrapper')).toHaveClass(`sliding-panel--open-${position}`); }); it(`should add the classname for 'showSlidingPanelBorder'`, () => { customRender({ position, showSlidingPanelBorder: true }); expect(screen.queryByTestId('wrapper')).toHaveClass(`sliding-panel--border-${position}`); }); }); }); }); it('should render children', () => { customRender(); expect(screen.getByTestId('content')).toBeInTheDocument(); }); it('should respect className', () => { const className = 'customClass'; customRender({ className }); expect(screen.getByTestId('wrapper')).toHaveClass(className); }); describe('slidingPanelPositionFixed', () => { it('should not be fixed by default', () => { customRender(); expect(screen.getByTestId('wrapper')).not.toHaveClass('sliding-panel--fixed'); }); it('should respect slidingPanelPositionFixed=true', () => { customRender({ slidingPanelPositionFixed: true }); expect(screen.getByTestId('wrapper')).toHaveClass('sliding-panel--fixed'); }); }); });