mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
f64b241d32
* split logic, reenable unit test, copy whole node to prevent recursion error * remove double assignment
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { config } from '@grafana/runtime';
|
|
|
|
import { buildInitialState } from '../reducers/navModel';
|
|
|
|
import { getNavModel } from './navModel';
|
|
|
|
describe('getNavModel', () => {
|
|
config.bootData.navTree = [
|
|
{
|
|
text: 'Apps',
|
|
id: 'apps',
|
|
url: 'apps',
|
|
children: [
|
|
{ text: '', id: 'apps/child1', url: 'apps/child1' },
|
|
{ text: '', id: 'apps/child2', url: 'apps/child2' },
|
|
{
|
|
text: '',
|
|
id: 'apps/subapp',
|
|
url: 'section/subapp',
|
|
children: [
|
|
{ text: '', id: 'apps/subapp/child1', url: 'apps/subapp/child1' },
|
|
{ text: '', id: 'apps/subapp/child2', url: 'apps/subapp/child2' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const navIndex = buildInitialState();
|
|
|
|
test('returns the correct nav model for root node', () => {
|
|
const navModel = getNavModel(navIndex, 'apps');
|
|
expect(navModel.main.id).toBe('apps');
|
|
expect(navModel.node.id).toBe('apps');
|
|
});
|
|
|
|
test('returns the correct nav model a 1st-level child', () => {
|
|
const navModel = getNavModel(navIndex, 'apps/child1');
|
|
expect(navModel.main.id).toBe('apps');
|
|
expect(navModel.node.id).toBe('apps/child1');
|
|
expect(navModel.main.children![0].active).toBe(true);
|
|
expect(navModel.node.parentItem?.id).toBe(navModel.main.id);
|
|
});
|
|
|
|
test('returns the correct nav model for a 2nd-level child', () => {
|
|
const navModel = getNavModel(navIndex, 'apps/subapp/child1');
|
|
expect(navModel.main.id).toBe('apps');
|
|
expect(navModel.node.id).toBe('apps/subapp/child1');
|
|
expect(navModel.main.children![2].active).toBe(true);
|
|
expect(navModel.main.children![2].children![0].active).toBe(true);
|
|
});
|
|
});
|