metrics_panel_ctrl.jest.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. jest.mock('app/core/core', () => ({}));
  2. import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
  3. import q from 'q';
  4. import { PanelModel } from 'app/features/dashboard/panel_model';
  5. describe('MetricsPanelCtrl', () => {
  6. let ctrl;
  7. beforeEach(() => {
  8. ctrl = setupController();
  9. });
  10. describe('when getting additional menu items', () => {
  11. let additionalItems;
  12. describe('and has no datasource set', () => {
  13. beforeEach(() => {
  14. additionalItems = ctrl.getAdditionalMenuItems();
  15. });
  16. it('should not return any items', () => {
  17. expect(additionalItems.length).toBe(0);
  18. });
  19. });
  20. describe('and has datasource set that supports explore', () => {
  21. beforeEach(() => {
  22. ctrl.datasource = { supportsExplore: true };
  23. additionalItems = ctrl.getAdditionalMenuItems();
  24. });
  25. it('should not return any items', () => {
  26. expect(additionalItems.length).toBe(1);
  27. });
  28. });
  29. });
  30. });
  31. function setupController() {
  32. const injectorStub = {
  33. get: type => {
  34. switch (type) {
  35. case '$q': {
  36. return q;
  37. }
  38. default: {
  39. return jest.fn();
  40. }
  41. }
  42. },
  43. };
  44. const scope = {
  45. panel: { events: [] },
  46. appEvent: jest.fn(),
  47. onAppEvent: jest.fn(),
  48. $on: jest.fn(),
  49. colors: [],
  50. };
  51. MetricsPanelCtrl.prototype.panel = new PanelModel({ type: 'test' });
  52. return new MetricsPanelCtrl(scope, injectorStub);
  53. }