Skip to content

Commit

Permalink
Consider assigned perspective when merging navigation dropdowns. (#21295
Browse files Browse the repository at this point in the history
)
  • Loading branch information
linuspahl authored Jan 9, 2025
1 parent b1e8a57 commit 73a5fc9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import * as React from 'react';
import type { PluginExports } from 'graylog-web-plugin/plugin';
import { PluginManifest, PluginStore } from 'graylog-web-plugin/plugin';
import { defaultUser } from 'defaultMockValues';
import userEvent from '@testing-library/user-event';

import AppConfig from 'util/AppConfig';
import { asMock } from 'helpers/mocking';
import useCurrentUser from 'hooks/useCurrentUser';
import { adminUser } from 'fixtures/users';
import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider';
import PerspectivesBindings from 'components/perspectives/bindings';
import { examplePerspective } from 'fixtures/perspectives';

import MainNavbar from './MainNavbar';

Expand Down Expand Up @@ -74,6 +76,28 @@ describe('MainNavbar', () => {
{ path: '/newpluginroute', description: 'New dropdown route', requiredFeatureFlag: 'enable_dropdown_nav_item' },
],
},
{
description: 'Merged dropdown test',
path: '/',
children: [
{ path: '/another-route', description: 'Menu item for general perspective' },
],
},
{
description: 'Merged dropdown test',
path: '/',
children: [
{ path: '/just-another-route', description: 'Merged item for general perspective' },
],
},
{
description: 'Merged dropdown test',
path: '/',
perspective: examplePerspective.id,
children: [
{ path: '/another-route', description: 'Menu item for specific perspective' },
],
},
],
} as PluginExports,
};
Expand Down Expand Up @@ -176,6 +200,25 @@ describe('MainNavbar', () => {

await screen.findByRole('button', { name: /neat stuff \/ something else/i });
});

it('should merge navigation dropdowns when their description is equal', async () => {
render(<SUT />);

userEvent.click(await screen.findByRole('button', { name: /Merged dropdown test/i }));

await screen.findByRole('menuitem', { name: /Menu item for general perspective/i });
await screen.findByRole('menuitem', { name: /Merged item for general perspective/i });
});

it('should not merge navigation dropdowns when their assigned perspective varies', async () => {
render(<SUT />);

userEvent.click(await screen.findByRole('button', { name: /Merged dropdown test/i }));

await screen.findByRole('menuitem', { name: /Menu item for general perspective/i });

expect(screen.queryByRole('menuitem', { name: /Menu item for specific perspective/i })).not.toBeInTheDocument();
});
});

describe('uses correct permissions:', () => {
Expand All @@ -196,7 +239,7 @@ describe('MainNavbar', () => {

render(<SUT />);

expect(await screen.findByRole('link', { name: /enterprise/i })).toBeInTheDocument();
await screen.findByRole('link', { name: /enterprise/i });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const _existingDropdownItemIndex = (existingNavigationItems: Array<PluginNavigat
return -1;
}

return existingNavigationItems.findIndex(({ description, children }) => newNavigationItem.description === description && children);
return existingNavigationItems.findIndex(({ description, perspective, children }) => newNavigationItem.description === description && newNavigationItem.perspective === perspective && children);
};

const mergeDuplicateDropdowns = (navigationItems: Array<PluginNavigation>): Array<PluginNavigation> => navigationItems.reduce((result, current) => {
Expand Down

0 comments on commit 73a5fc9

Please sign in to comment.