2022-09-01 21:12:52 -05:00
|
|
|
import { waitFor, render, screen } from '@testing-library/react'
|
|
|
|
import userEvent from '@testing-library/user-event'
|
2023-03-04 12:55:37 -06:00
|
|
|
import { SettingsContext } from 'contexts/SettingsContext'
|
2022-09-01 21:12:52 -05:00
|
|
|
import { MemoryRouter as Router } from 'react-router-dom'
|
2023-03-04 12:55:37 -06:00
|
|
|
import { userSettingsContextStubFactory } from 'test-utils/stubs/settingsContext'
|
2022-09-01 21:12:52 -05:00
|
|
|
|
|
|
|
import { Shell, ShellProps } from './Shell'
|
|
|
|
|
2023-03-04 12:55:37 -06:00
|
|
|
const mockUserPeerId = 'abc123'
|
|
|
|
|
|
|
|
const userSettingsStub = userSettingsContextStubFactory({
|
|
|
|
userId: mockUserPeerId,
|
|
|
|
})
|
|
|
|
|
|
|
|
const ShellStub = (shellProps: Partial<ShellProps> = {}) => {
|
2022-09-01 21:12:52 -05:00
|
|
|
return (
|
|
|
|
<Router>
|
2023-03-04 12:55:37 -06:00
|
|
|
<SettingsContext.Provider value={userSettingsStub}>
|
|
|
|
<Shell
|
|
|
|
appNeedsUpdate={false}
|
|
|
|
userPeerId={mockUserPeerId}
|
|
|
|
{...shellProps}
|
|
|
|
/>
|
|
|
|
</SettingsContext.Provider>
|
2022-09-01 21:12:52 -05:00
|
|
|
</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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|