diff --git a/web/src/components/NavigationDrawer.jsx b/web/src/components/NavigationDrawer.jsx index faec1d71c..417e7fb77 100644 --- a/web/src/components/NavigationDrawer.jsx +++ b/web/src/components/NavigationDrawer.jsx @@ -12,9 +12,10 @@ export default function NavigationDrawer({ children, header }) { return ( - {showDrawer ?
: ''} + {showDrawer ?
: ''}
{ + let useDrawer, setShowDrawer; + + beforeEach(() => { + setShowDrawer = jest.fn(); + useDrawer = jest.spyOn(Context, 'useDrawer').mockImplementation(() => ({ showDrawer: true, setShowDrawer })); + }); + + test('renders a navigation drawer', async () => { + render( + +
Hello
+
+ ); + expect(screen.queryByTestId('children')).toHaveTextContent('Hello'); + expect(screen.queryByTestId('drawer').classList.contains('translate-x-full')).toBe(false); + expect(screen.queryByTestId('drawer').classList.contains('translate-x-0')).toBe(true); + }); + + test('is dismissed when the scrim is clicked', async () => { + useDrawer + .mockReturnValueOnce({ showDrawer: true, setShowDrawer }) + .mockReturnValueOnce({ showDrawer: false, setShowDrawer }); + render(); + fireEvent.click(screen.queryByTestId('scrim')); + expect(setShowDrawer).toHaveBeenCalledWith(false); + }); + + test('is not visible when not set to show', async () => { + useDrawer.mockReturnValue({ showDrawer: false, setShowDrawer }); + render(); + expect(screen.queryByTestId('scrim')).not.toBeInTheDocument(); + expect(screen.queryByTestId('drawer').classList.contains('-translate-x-full')).toBe(true); + expect(screen.queryByTestId('drawer').classList.contains('translate-x-0')).toBe(false); + }); +}); + +describe('Destination', () => { + let setShowDrawer; + + beforeEach(() => { + setShowDrawer = jest.fn(); + jest.spyOn(Context, 'useDrawer').mockImplementation(() => ({ showDrawer: true, setShowDrawer })); + }); + + test('dismisses the drawer moments after being clicked', async () => { + render( + + + + ); + fireEvent.click(screen.queryByText('Tacos')); + jest.runAllTimers(); + expect(setShowDrawer).toHaveBeenCalledWith(false); + }); +});