mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
test: navigation sidebar (#7172)
This commit is contained in:
parent
08629e9041
commit
f7214c6cd0
@ -59,6 +59,7 @@ export const ConfigureNavigationList: FC<{
|
|||||||
<List>
|
<List>
|
||||||
{routes.map((route) => (
|
{routes.map((route) => (
|
||||||
<DynamicListItem
|
<DynamicListItem
|
||||||
|
key={route.title}
|
||||||
href={route.path}
|
href={route.path}
|
||||||
text={route.title}
|
text={route.title}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
@ -82,6 +83,7 @@ export const AdminNavigationList: FC<{
|
|||||||
<List>
|
<List>
|
||||||
{routes.map((route) => (
|
{routes.map((route) => (
|
||||||
<DynamicListItem
|
<DynamicListItem
|
||||||
|
key={route.title}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
href={route.path}
|
href={route.path}
|
||||||
text={route.title}
|
text={route.title}
|
||||||
@ -104,7 +106,11 @@ export const OtherLinksList = () => {
|
|||||||
return (
|
return (
|
||||||
<List>
|
<List>
|
||||||
{uiConfig.links.map((link) => (
|
{uiConfig.links.map((link) => (
|
||||||
<ExternalFullListItem href={link.href} text={link.value}>
|
<ExternalFullListItem
|
||||||
|
href={link.href}
|
||||||
|
text={link.value}
|
||||||
|
key={link.value}
|
||||||
|
>
|
||||||
<IconRenderer path={link.value} />
|
<IconRenderer path={link.value} />
|
||||||
</ExternalFullListItem>
|
</ExternalFullListItem>
|
||||||
))}
|
))}
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
import { render } from 'utils/testRenderer';
|
||||||
|
import { NavigationSidebar } from './NavigationSidebar';
|
||||||
|
import { screen, fireEvent, waitFor } from '@testing-library/react';
|
||||||
|
import { createLocalStorage } from 'utils/createLocalStorage';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
window.localStorage.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('switch full mode and mini mode', () => {
|
||||||
|
render(<NavigationSidebar />);
|
||||||
|
|
||||||
|
expect(screen.queryByText('Projects')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Applications')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Users')).toBeInTheDocument();
|
||||||
|
|
||||||
|
const hide = screen.getByText('Hide (⌘ + B)');
|
||||||
|
hide.click();
|
||||||
|
|
||||||
|
expect(screen.queryByText('Projects')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Applications')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Users')).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
const expand = screen.getByTestId('expand-navigation');
|
||||||
|
fireEvent.click(expand);
|
||||||
|
|
||||||
|
expect(screen.queryByText('Projects')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Applications')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Users')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('persist navigation mode and expansion selection in storage', async () => {
|
||||||
|
render(<NavigationSidebar />);
|
||||||
|
const { value } = createLocalStorage('navigation-mode:v1', {});
|
||||||
|
expect(value).toBe('full');
|
||||||
|
|
||||||
|
const configure = screen.getByText('Configure');
|
||||||
|
configure.click(); // expand
|
||||||
|
configure.click(); // hide
|
||||||
|
const admin = screen.getByText('Admin');
|
||||||
|
admin.click();
|
||||||
|
|
||||||
|
const hide = screen.getByText('Hide (⌘ + B)');
|
||||||
|
hide.click();
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
const { value } = createLocalStorage('navigation-mode:v1', {});
|
||||||
|
expect(value).toBe('mini');
|
||||||
|
|
||||||
|
const { value: expanded } = createLocalStorage(
|
||||||
|
'navigation-expanded:v1',
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
expect(expanded).toEqual(['admin']);
|
||||||
|
});
|
||||||
|
});
|
@ -35,7 +35,7 @@ export const ShowHide: FC<{ mode: NavigationMode; onChange: () => void }> = ({
|
|||||||
<ChevronLeftIcon />
|
<ChevronLeftIcon />
|
||||||
) : (
|
) : (
|
||||||
<Tooltip title='Expand (⌘ + B)' placement='right'>
|
<Tooltip title='Expand (⌘ + B)' placement='right'>
|
||||||
<ChevronRightIcon />
|
<ChevronRightIcon data-testid='expand-navigation' />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user