SaveDashboardAsModalCtrl.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { SaveDashboardAsModalCtrl } from './SaveDashboardAsModalCtrl';
  2. import { describe, it, expect } from 'test/lib/common';
  3. describe('saving dashboard as', () => {
  4. function scenario(name: string, panel: any, verify: Function) {
  5. describe(name, () => {
  6. const json = {
  7. title: 'name',
  8. panels: [panel],
  9. };
  10. const mockDashboardSrv: any = {
  11. getCurrent: () => {
  12. return {
  13. id: 5,
  14. meta: {},
  15. getSaveModelClone: () => {
  16. return json;
  17. },
  18. };
  19. },
  20. };
  21. const ctrl = new SaveDashboardAsModalCtrl(mockDashboardSrv);
  22. const ctx: any = {
  23. clone: ctrl.clone,
  24. ctrl: ctrl,
  25. panel: panel,
  26. };
  27. it('verify', () => {
  28. verify(ctx);
  29. });
  30. });
  31. }
  32. scenario('default values', {}, (ctx: any) => {
  33. const clone = ctx.clone;
  34. expect(clone.id).toBe(null);
  35. expect(clone.title).toBe('name Copy');
  36. expect(clone.editable).toBe(true);
  37. expect(clone.hideControls).toBe(false);
  38. });
  39. const graphPanel = {
  40. id: 1,
  41. type: 'graph',
  42. alert: { rule: 1 },
  43. thresholds: { value: 3000 },
  44. };
  45. scenario('should remove alert from graph panel', graphPanel, (ctx: any) => {
  46. expect(ctx.panel.alert).toBe(undefined);
  47. });
  48. scenario('should remove threshold from graph panel', graphPanel, (ctx: any) => {
  49. expect(ctx.panel.thresholds).toBe(undefined);
  50. });
  51. scenario(
  52. 'singlestat should keep threshold',
  53. { id: 1, type: 'singlestat', thresholds: { value: 3000 } },
  54. (ctx: any) => {
  55. expect(ctx.panel.thresholds).not.toBe(undefined);
  56. }
  57. );
  58. scenario('table should keep threshold', { id: 1, type: 'table', thresholds: { value: 3000 } }, (ctx: any) => {
  59. expect(ctx.panel.thresholds).not.toBe(undefined);
  60. });
  61. });