forked from Shiloh/remnantchat
test: validate drawer toggling
This commit is contained in:
parent
fb2a5144a2
commit
bfa7158fb1
38
src/components/Shell/Shell.test.tsx
Normal file
38
src/components/Shell/Shell.test.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { waitFor, render, screen } from '@testing-library/react'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
import { MemoryRouter as Router } from 'react-router-dom'
|
||||||
|
|
||||||
|
import { Shell, ShellProps } from './Shell'
|
||||||
|
|
||||||
|
const ShellStub = (overrides: ShellProps = {}) => {
|
||||||
|
return (
|
||||||
|
<Router>
|
||||||
|
<Shell {...overrides} />
|
||||||
|
</Router>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Shell', () => {
|
||||||
|
describe('menu drawer', () => {
|
||||||
|
test('can be opened', () => {
|
||||||
|
render(<ShellStub />)
|
||||||
|
const menuButton = screen.getByLabelText('Open menu')
|
||||||
|
userEvent.click(menuButton)
|
||||||
|
const navigation = screen.getByRole('navigation')
|
||||||
|
expect(navigation).toBeVisible()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can be closed', async () => {
|
||||||
|
render(<ShellStub />)
|
||||||
|
const menuButton = screen.getByLabelText('Open menu')
|
||||||
|
userEvent.click(menuButton)
|
||||||
|
const closeMenu = screen.getByLabelText('Close menu')
|
||||||
|
userEvent.click(closeMenu)
|
||||||
|
const navigation = screen.getByRole('navigation')
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(navigation).not.toBeVisible()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -35,7 +35,7 @@ import Home from '@mui/icons-material/Home'
|
|||||||
import { ShellContext } from 'ShellContext'
|
import { ShellContext } from 'ShellContext'
|
||||||
import { AlertOptions } from 'models/shell'
|
import { AlertOptions } from 'models/shell'
|
||||||
|
|
||||||
interface ShellProps extends PropsWithChildren {}
|
export interface ShellProps extends PropsWithChildren {}
|
||||||
|
|
||||||
const drawerWidth = 240
|
const drawerWidth = 240
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ export const Shell = ({ children }: ShellProps) => {
|
|||||||
size="large"
|
size="large"
|
||||||
edge="start"
|
edge="start"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
aria-label="menu"
|
aria-label="Open menu"
|
||||||
sx={{ mr: 2, ...(isDrawerOpen && { display: 'none' }) }}
|
sx={{ mr: 2, ...(isDrawerOpen && { display: 'none' }) }}
|
||||||
onClick={handleDrawerOpen}
|
onClick={handleDrawerOpen}
|
||||||
>
|
>
|
||||||
@ -213,7 +213,7 @@ export const Shell = ({ children }: ShellProps) => {
|
|||||||
open={isDrawerOpen}
|
open={isDrawerOpen}
|
||||||
>
|
>
|
||||||
<DrawerHeader>
|
<DrawerHeader>
|
||||||
<IconButton onClick={handleDrawerClose}>
|
<IconButton onClick={handleDrawerClose} aria-label="Close menu">
|
||||||
{theme.direction === 'ltr' ? (
|
{theme.direction === 'ltr' ? (
|
||||||
<ChevronLeftIcon />
|
<ChevronLeftIcon />
|
||||||
) : (
|
) : (
|
||||||
@ -222,7 +222,7 @@ export const Shell = ({ children }: ShellProps) => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</DrawerHeader>
|
</DrawerHeader>
|
||||||
<Divider />
|
<Divider />
|
||||||
<List>
|
<List role="navigation">
|
||||||
<Link to="/">
|
<Link to="/">
|
||||||
<ListItem disablePadding>
|
<ListItem disablePadding>
|
||||||
<ListItemButton>
|
<ListItemButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user