mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* remove code outside of the topnav feature flag * delete NavBar folder * remove topnav toggle from backend * restructure AppChrome folder * fix utils mock * fix applinks tests * remove tests since they're covered in e2e * fix 1 of the approotpage tests * Fix another dashboardpage test * remove reverse portalling + test for plugins using deprecated onNavChanged method * kick drone * handle correlations
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { NavModelItem } from '@grafana/data';
|
|
import { HOME_NAV_ID } from 'app/core/reducers/navModel';
|
|
|
|
import { buildPluginSectionNav } from './utils';
|
|
|
|
describe('buildPluginSectionNav', () => {
|
|
const pluginNav = { main: { text: 'Plugin nav' }, node: { text: 'Plugin nav' } };
|
|
const app1: NavModelItem = {
|
|
text: 'App1',
|
|
id: 'plugin-page-app1',
|
|
url: '/a/plugin1',
|
|
children: [
|
|
{
|
|
text: 'page1',
|
|
url: '/a/plugin1/page1',
|
|
},
|
|
{
|
|
text: 'page2',
|
|
url: '/a/plugin1/page2',
|
|
},
|
|
],
|
|
};
|
|
|
|
const appsSection = {
|
|
text: 'apps',
|
|
id: 'apps',
|
|
children: [app1],
|
|
};
|
|
|
|
const home = {
|
|
id: HOME_NAV_ID,
|
|
text: 'Home',
|
|
};
|
|
|
|
const adminSection: NavModelItem = {
|
|
text: 'Admin',
|
|
id: 'admin',
|
|
children: [],
|
|
parentItem: home,
|
|
};
|
|
|
|
const standalonePluginPage = {
|
|
id: 'standalone-plugin-page-/a/app2/config',
|
|
text: 'Standalone page',
|
|
parentItem: adminSection,
|
|
};
|
|
|
|
adminSection.children = [standalonePluginPage];
|
|
|
|
app1.parentItem = appsSection;
|
|
|
|
it('Should return return section nav', () => {
|
|
const result = buildPluginSectionNav(appsSection, pluginNav, '/a/plugin1/page1');
|
|
expect(result?.main.text).toBe('apps');
|
|
});
|
|
|
|
it('Should set active page', () => {
|
|
const result = buildPluginSectionNav(appsSection, null, '/a/plugin1/page2');
|
|
expect(result?.main.children![0].children![1].active).toBe(true);
|
|
expect(result?.node.text).toBe('page2');
|
|
});
|
|
|
|
it('Should only set the most specific match as active (not the parents)', () => {
|
|
const result = buildPluginSectionNav(appsSection, null, '/a/plugin1/page2');
|
|
expect(result?.main.children![0].children![1].active).toBe(true);
|
|
expect(result?.main.children![0].active).not.toBe(true); // Parent should not be active
|
|
});
|
|
|
|
it('Should set app section to active', () => {
|
|
const result = buildPluginSectionNav(appsSection, null, '/a/plugin1');
|
|
expect(result?.main.children![0].active).toBe(true);
|
|
expect(result?.node.text).toBe('App1');
|
|
});
|
|
|
|
it('Should handle standalone page', () => {
|
|
const result = buildPluginSectionNav(adminSection, pluginNav, '/a/app2/config');
|
|
expect(result?.main.text).toBe('Admin');
|
|
expect(result?.node.text).toBe('Standalone page');
|
|
});
|
|
});
|