quintodrome/ui/src/layout/DynamicMenuIcon.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.5 KiB
JavaScript
Raw Normal View History

import * as React from 'react'
2022-09-28 17:30:20 -08:00
import { cleanup, render, screen } from '@testing-library/react'
import { createMemoryHistory } from 'history'
import { Router } from 'react-router-dom'
import StarIcon from '@material-ui/icons/Star'
import StarBorderIcon from '@material-ui/icons/StarBorder'
import DynamicMenuIcon from './DynamicMenuIcon'
describe('<DynamicMenuIcon />', () => {
2021-04-22 10:04:48 -08:00
afterEach(cleanup)
it('renders icon if no activeIcon is specified', () => {
const history = createMemoryHistory()
const route = '/test'
history.push(route)
2022-09-28 17:30:20 -08:00
render(
<Router history={history}>
<DynamicMenuIcon icon={StarIcon} path={'test'} />
</Router>
)
2022-09-28 17:30:20 -08:00
expect(screen.getByTestId('icon')).not.toBeNull()
})
it('renders icon if path does not match the URL', () => {
const history = createMemoryHistory()
const route = '/path'
history.push(route)
2022-09-28 17:30:20 -08:00
render(
<Router history={history}>
<DynamicMenuIcon
icon={StarIcon}
activeIcon={StarBorderIcon}
path={'otherpath'}
/>
</Router>
)
2022-09-28 17:30:20 -08:00
expect(screen.getByTestId('icon')).not.toBeNull()
})
it('renders activeIcon if path matches the URL', () => {
const history = createMemoryHistory()
const route = '/path'
history.push(route)
2022-09-28 17:30:20 -08:00
render(
<Router history={history}>
<DynamicMenuIcon
icon={StarIcon}
activeIcon={StarBorderIcon}
path={'path'}
/>
</Router>
)
2022-09-28 17:30:20 -08:00
expect(screen.getByTestId('activeIcon')).not.toBeNull()
})
})