-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
283 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
|
||
import _ from 'lodash/fp'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Link as RouterLink } from 'react-router-dom'; | ||
|
||
import { | ||
Container, | ||
Link, | ||
Breadcrumbs as MuiBreadcrumbs, | ||
Typography, | ||
} from '@mui/material'; | ||
import { visuallyHidden } from '@mui/utils'; | ||
|
||
import { useBreadcrumbs } from './Routes'; | ||
import { useBreadcrumbsContext } from './breadcrumbsContext'; | ||
|
||
const Breadcrumbs = () => { | ||
const { t } = useTranslation(); | ||
const breadcrumbs = useBreadcrumbs(); | ||
const { breadcrumbsParams } = useBreadcrumbsContext(); | ||
const { loading = true } = breadcrumbsParams; | ||
|
||
if (loading || _.isEmpty(breadcrumbs)) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
<Typography sx={visuallyHidden} variant="h2"> | ||
{t('navigation.breadcrumbs_label')} | ||
</Typography> | ||
<Container | ||
component={MuiBreadcrumbs} | ||
aria-label={t('navigation.breadcrumbs_label')} | ||
sx={{ | ||
mt: 3, | ||
}} | ||
> | ||
<Link component={RouterLink} to="/"> | ||
{t('home.title')} | ||
</Link> | ||
{breadcrumbs.map(({ to, label, current }) => ( | ||
<Link | ||
component={RouterLink} | ||
to={to} | ||
key={to} | ||
{...(current | ||
? { | ||
color: 'gray.dark1', | ||
'aria-current': 'page', | ||
} | ||
: {})} | ||
> | ||
{t(label, breadcrumbsParams)} | ||
</Link> | ||
))} | ||
</Container> | ||
</> | ||
); | ||
}; | ||
|
||
export default Breadcrumbs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { render, screen } from 'tests/utils'; | ||
|
||
import React, { useMemo } from 'react'; | ||
|
||
import { useLocation } from 'react-router-dom'; | ||
|
||
import Breadcrumbs from './Breadcrumbs'; | ||
import { useBreadcrumbsParams } from './breadcrumbsContext'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useLocation: jest.fn(), | ||
})); | ||
|
||
const TestComponent = () => { | ||
useBreadcrumbsParams( | ||
useMemo(() => ({ groupName: 'Group Name', loading: false }), []) | ||
); | ||
return <Breadcrumbs />; | ||
}; | ||
|
||
const setup = async () => { | ||
await render(<TestComponent />); | ||
}; | ||
test('Breadcrumbs: Dont Show items', async () => { | ||
useLocation.mockReturnValue({ | ||
pathname: '/groups', | ||
}); | ||
await setup(); | ||
expect( | ||
screen.queryByRole('navigation', { name: 'Breadcrumbs' }) | ||
).not.toBeInTheDocument(); | ||
}); | ||
test('Breadcrumbs: Show items', async () => { | ||
useLocation.mockReturnValue({ | ||
pathname: '/groups/group-1/members', | ||
}); | ||
await setup(); | ||
expect( | ||
screen.getByRole('navigation', { name: 'Breadcrumbs' }) | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Home' })).toHaveAttribute( | ||
'href', | ||
'/' | ||
); | ||
expect(screen.getByRole('link', { name: 'Groups' })).toHaveAttribute( | ||
'href', | ||
'/groups' | ||
); | ||
expect(screen.getByRole('link', { name: 'Group Name' })).toHaveAttribute( | ||
'href', | ||
'/groups/group-1' | ||
); | ||
expect(screen.getByRole('link', { name: 'Members' })).toHaveAttribute( | ||
'href', | ||
'/groups/group-1/members' | ||
); | ||
expect(screen.getByRole('link', { name: 'Members' })).toHaveAttribute( | ||
'aria-current', | ||
'page' | ||
); | ||
}); |
Oops, something went wrong.