Navigation: enable third level on the DockedMegaMenu (#75180)

This commit is contained in:
Laura Fernández 2023-09-21 15:15:11 +02:00 committed by GitHub
parent d218aa1a97
commit 14f4ed0180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { Router } from 'react-router-dom';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
@ -17,7 +18,12 @@ const setup = () => {
id: 'section',
url: 'section',
children: [
{ text: 'Child1', id: 'child1', url: 'section/child1' },
{
text: 'Child1',
id: 'child1',
url: 'section/child1',
children: [{ text: 'Grandchild1', id: 'grandchild1', url: 'section/child1/grandchild1' }],
},
{ text: 'Child2', id: 'child2', url: 'section/child2' },
],
},
@ -41,6 +47,9 @@ const setup = () => {
};
describe('MegaMenu', () => {
afterEach(() => {
window.localStorage.clear();
});
it('should render component', async () => {
setup();
@ -48,6 +57,22 @@ describe('MegaMenu', () => {
expect(await screen.findByRole('link', { name: 'Section name' })).toBeInTheDocument();
});
it('should render children', async () => {
setup();
await userEvent.click(await screen.findByRole('button', { name: 'Expand section Section name' }));
expect(await screen.findByRole('link', { name: 'Child1' })).toBeInTheDocument();
expect(await screen.findByRole('link', { name: 'Child2' })).toBeInTheDocument();
});
it('should render grandchildren', async () => {
setup();
await userEvent.click(await screen.findByRole('button', { name: 'Expand section Section name' }));
expect(await screen.findByRole('link', { name: 'Child1' })).toBeInTheDocument();
await userEvent.click(await screen.findByRole('button', { name: 'Expand section Child1' }));
expect(await screen.findByRole('link', { name: 'Grandchild1' })).toBeInTheDocument();
expect(await screen.findByRole('link', { name: 'Child2' })).toBeInTheDocument();
});
it('should filter out profile', async () => {
setup();

View File

@ -34,7 +34,14 @@ export function NavBarMenuItemWrapper({
{linkHasChildren(link) && (
<ul className={styles.children}>
{link.children.map((childLink) => {
return (
return linkHasChildren(childLink) ? (
<NavBarMenuItemWrapper
key={`${link.text}-${childLink.text}`}
link={childLink}
activeItem={activeItem}
onClose={onClose}
/>
) : (
!childLink.isCreateAction && (
<NavBarMenuItem
key={`${link.text}-${childLink.text}`}