grafana/public/test/mocks/common.ts

52 lines
1007 B
TypeScript
Raw Normal View History

2018-09-02 09:11:21 -05:00
import { NavModel, NavModelItem } from 'app/types';
2017-12-28 10:01:28 -06:00
export const backendSrv = {
get: jest.fn(),
getDashboard: jest.fn(),
2018-02-01 06:21:24 -06:00
getDashboardByUid: jest.fn(),
getFolderByUid: jest.fn(),
2018-01-01 11:54:23 -06:00
post: jest.fn(),
2017-12-28 10:01:28 -06:00
};
export function createNavTree(...args) {
const root = [];
2017-12-28 10:01:28 -06:00
let node = root;
for (const arg of args) {
const child = { id: arg, url: `/url/${arg}`, text: `${arg}-Text`, children: [] };
2017-12-28 10:01:28 -06:00
node.push(child);
node = child.children;
}
2017-12-28 10:01:28 -06:00
return root;
}
2018-09-02 09:11:21 -05:00
export function createNavModel(title: string, ...tabs: string[]): NavModel {
2018-09-02 09:11:21 -05:00
const node: NavModelItem = {
id: title,
text: title,
icon: 'fa fa-fw fa-warning',
subTitle: 'subTitle',
url: title,
children: [],
breadcrumbs: [],
};
2018-09-07 10:55:38 -05:00
for (const tab of tabs) {
2018-09-02 09:11:21 -05:00
node.children.push({
id: tab,
icon: 'icon',
subTitle: 'subTitle',
url: title,
text: title,
active: false,
2018-09-02 09:11:21 -05:00
});
}
node.children[0].active = true;
2018-09-02 09:11:21 -05:00
return {
node: node,
main: node,
};
}