grafana/public/app/core/components/Breadcrumbs/utils.test.ts
Torkel Ödegaard da001b01f1
TopNav: Section navigation UX (#55012)
* Design tweaks

* Updated

* Fixing unit tests

* Review fixes

* Text primary on active sections, and change home icon to text

* spacing fix

* More fix

* Fixes

* Updates
2022-09-13 12:24:23 +02:00

87 lines
2.6 KiB
TypeScript

import { NavModelItem } from '@grafana/data';
import { buildBreadcrumbs } from './utils';
describe('breadcrumb utils', () => {
describe('buildBreadcrumbs', () => {
it('includes the home breadcrumb at the root', () => {
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
};
const result = buildBreadcrumbs(sectionNav);
expect(result[0]).toEqual({ href: '/', text: 'Home' });
});
it('includes breadcrumbs for the section nav', () => {
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
};
expect(buildBreadcrumbs(sectionNav)).toEqual([
{ href: '/', text: 'Home' },
{ text: 'My section', href: '/my-section' },
]);
});
it('includes breadcrumbs for the page nav', () => {
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
};
const pageNav: NavModelItem = {
text: 'My page',
url: '/my-page',
};
expect(buildBreadcrumbs(sectionNav, pageNav)).toEqual([
{ href: '/', text: 'Home' },
{ text: 'My section', href: '/my-section' },
{ text: 'My page', href: '/my-page' },
]);
});
it('includes breadcrumbs for any parents in the section nav', () => {
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
parentItem: {
text: 'My parent section',
url: '/my-parent-section',
},
};
expect(buildBreadcrumbs(sectionNav)).toEqual([
{ href: '/', text: 'Home' },
{ text: 'My parent section', href: '/my-parent-section' },
{ text: 'My section', href: '/my-section' },
]);
});
it('includes breadcrumbs for any parents in the section nav or page nav', () => {
const pageNav: NavModelItem = {
text: 'My page',
url: '/my-page',
parentItem: {
text: 'My parent page',
url: '/my-parent-page',
},
};
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
parentItem: {
text: 'My parent section',
url: '/my-parent-section',
},
};
expect(buildBreadcrumbs(sectionNav, pageNav)).toEqual([
{ href: '/', text: 'Home' },
{ text: 'My parent section', href: '/my-parent-section' },
{ text: 'My section', href: '/my-section' },
{ text: 'My parent page', href: '/my-parent-page' },
{ text: 'My page', href: '/my-page' },
]);
});
});
});