common.ts 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { NavModel, NavModelItem } from '@grafana/ui';
  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 createNavModel(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 (const tab of tabs) {
  30. node.children.push({
  31. id: tab,
  32. icon: 'icon',
  33. subTitle: 'subTitle',
  34. url: title,
  35. text: title,
  36. active: false,
  37. });
  38. }
  39. node.children[0].active = true;
  40. return {
  41. node: node,
  42. main: node,
  43. };
  44. }