save_as_modal.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { SaveDashboardAsModalCtrl } from '../save_as_modal';
  2. import { describe, it, expect } from 'test/lib/common';
  3. describe('saving dashboard as', () => {
  4. function scenario(name, panel, verify) {
  5. describe(name, () => {
  6. const json = {
  7. title: 'name',
  8. panels: [panel],
  9. };
  10. const mockDashboardSrv = {
  11. getCurrent: function() {
  12. return {
  13. id: 5,
  14. meta: {},
  15. getSaveModelClone: function() {
  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 => {
  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 => {
  46. expect(ctx.panel.alert).toBe(undefined);
  47. });
  48. scenario('should remove threshold from graph panel', graphPanel, ctx => {
  49. expect(ctx.panel.thresholds).toBe(undefined);
  50. });
  51. scenario('singlestat should keep threshold', { id: 1, type: 'singlestat', thresholds: { value: 3000 } }, ctx => {
  52. expect(ctx.panel.thresholds).not.toBe(undefined);
  53. });
  54. scenario('table should keep threshold', { id: 1, type: 'table', thresholds: { value: 3000 } }, ctx => {
  55. expect(ctx.panel.thresholds).not.toBe(undefined);
  56. });
  57. });