2021-04-16 20:40:07 -08:00
|
|
|
import * as React from 'react'
|
2022-09-28 17:30:20 -08:00
|
|
|
import { cleanup, render, screen } from '@testing-library/react'
|
2021-04-16 20:40:07 -08:00
|
|
|
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)
|
|
|
|
|
|
2021-04-16 20:40:07 -08:00
|
|
|
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(
|
2021-04-16 20:40:07 -08:00
|
|
|
<Router history={history}>
|
|
|
|
|
<DynamicMenuIcon icon={StarIcon} path={'test'} />
|
2023-12-18 10:56:03 -09:00
|
|
|
</Router>,
|
2021-04-16 20:40:07 -08:00
|
|
|
)
|
2022-09-28 17:30:20 -08:00
|
|
|
expect(screen.getByTestId('icon')).not.toBeNull()
|
2021-04-16 20:40:07 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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(
|
2021-04-16 20:40:07 -08:00
|
|
|
<Router history={history}>
|
|
|
|
|
<DynamicMenuIcon
|
|
|
|
|
icon={StarIcon}
|
|
|
|
|
activeIcon={StarBorderIcon}
|
|
|
|
|
path={'otherpath'}
|
|
|
|
|
/>
|
2023-12-18 10:56:03 -09:00
|
|
|
</Router>,
|
2021-04-16 20:40:07 -08:00
|
|
|
)
|
2022-09-28 17:30:20 -08:00
|
|
|
expect(screen.getByTestId('icon')).not.toBeNull()
|
2021-04-16 20:40:07 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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(
|
2021-04-16 20:40:07 -08:00
|
|
|
<Router history={history}>
|
|
|
|
|
<DynamicMenuIcon
|
|
|
|
|
icon={StarIcon}
|
|
|
|
|
activeIcon={StarBorderIcon}
|
|
|
|
|
path={'path'}
|
|
|
|
|
/>
|
2023-12-18 10:56:03 -09:00
|
|
|
</Router>,
|
2021-04-16 20:40:07 -08:00
|
|
|
)
|
2022-09-28 17:30:20 -08:00
|
|
|
expect(screen.getByTestId('activeIcon')).not.toBeNull()
|
2021-04-16 20:40:07 -08:00
|
|
|
})
|
|
|
|
|
})
|