common.ts 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { NavModel, NavModelItem } from 'app/types';
  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) {
  10. const root = [];
  11. let node = root;
  12. for (const arg of args) {
  13. const child = { 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 getNavModel(title: string, tabs: string[]): NavModel {
  20. const node: NavModelItem = {
  21. id: title,
  22. text: title,
  23. icon: 'fa fa-fw fa-warning',
  24. subTitle: 'subTitle',
  25. url: title,
  26. children: [],
  27. breadcrumbs: [],
  28. };
  29. for (let tab of tabs) {
  30. node.children.push({
  31. id: tab,
  32. icon: 'icon',
  33. subTitle: 'subTitle',
  34. url: title,
  35. text: title,
  36. });
  37. }
  38. return {
  39. node: node,
  40. main: node,
  41. };
  42. }