common.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { NavModel, NavModelItem } from '@grafana/data';
  2. export const backendSrv = {
  3. get: jest.fn(),
  4. getDashboard: jest.fn(),
  5. getDashboardByUid: jest.fn(),
  6. getFolderByUid: jest.fn(),
  7. post: jest.fn(),
  8. };
  9. export function createNavTree(...args: any[]) {
  10. const root: any[] = [];
  11. let node = root;
  12. for (const arg of args) {
  13. const child: any = { id: arg, url: `/url/${arg}`, text: `${arg}-Text`, children: [] };
  14. node.push(child);
  15. node = child.children;
  16. }
  17. return root;
  18. }
  19. export function createNavModel(title: string, ...tabs: string[]): NavModel {
  20. const node: NavModelItem = {
  21. id: title,
  22. text: title,
  23. icon: 'exclamation-triangle',
  24. subTitle: 'subTitle',
  25. url: title,
  26. children: [],
  27. breadcrumbs: [],
  28. };
  29. const children = [];
  30. for (const tab of tabs) {
  31. children.push({
  32. id: tab,
  33. icon: 'icon',
  34. subTitle: 'subTitle',
  35. url: title,
  36. text: title,
  37. active: false,
  38. });
  39. }
  40. children[0].active = true;
  41. node.children = children;
  42. return {
  43. node: node,
  44. main: node,
  45. };
  46. }