metrics_panel_ctrl.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. jest.mock('app/core/core', () => ({}));
  2. jest.mock('app/core/config', () => {
  3. return {
  4. ...(jest.requireActual('app/core/config') as unknown as object),
  5. bootData: {
  6. user: {},
  7. },
  8. panels: {
  9. test: {
  10. id: 'test',
  11. name: 'test',
  12. },
  13. },
  14. config: {
  15. appSubUrl: 'test',
  16. },
  17. };
  18. });
  19. import { PanelModel } from 'app/features/dashboard/state/PanelModel';
  20. import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
  21. describe('MetricsPanelCtrl', () => {
  22. describe('can setup', () => {
  23. it('should return controller', async () => {
  24. const ctrl = setupController({ hasAccessToExplore: true });
  25. expect((await ctrl.getAdditionalMenuItems()).length).toBe(0);
  26. });
  27. });
  28. });
  29. function setupController({ hasAccessToExplore } = { hasAccessToExplore: false }) {
  30. const injectorStub = {
  31. get: (type: any) => {
  32. switch (type) {
  33. case 'contextSrv': {
  34. return { hasAccessToExplore: () => hasAccessToExplore };
  35. }
  36. case 'timeSrv': {
  37. return { timeRangeForUrl: () => {} };
  38. }
  39. default: {
  40. return jest.fn();
  41. }
  42. }
  43. },
  44. };
  45. const scope: any = {
  46. panel: { events: [] },
  47. appEvent: jest.fn(),
  48. onAppEvent: jest.fn(),
  49. $on: jest.fn(),
  50. colors: [],
  51. $parent: {
  52. panel: new PanelModel({ type: 'test' }),
  53. dashboard: {},
  54. },
  55. };
  56. return new MetricsPanelCtrl(scope, injectorStub);
  57. }