add unit tests for buildBreadcrumbs (#54785)

This commit is contained in:
Ashley Harrison 2022-09-06 16:43:59 +01:00 committed by GitHub
parent 066710a7bc
commit a4566eaf32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,86 @@
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({ icon: 'home-alt', href: '/', text: 'Home' });
});
it('includes breadcrumbs for the section nav', () => {
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
};
expect(buildBreadcrumbs(sectionNav)).toEqual([
{ icon: 'home-alt', 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([
{ icon: 'home-alt', 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([
{ icon: 'home-alt', 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([
{ icon: 'home-alt', 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' },
]);
});
});
});