save_as_modal.jest.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. var json = {
  7. title: 'name',
  8. panels: [panel],
  9. };
  10. var mockDashboardSrv = {
  11. getCurrent: function() {
  12. return {
  13. id: 5,
  14. meta: {},
  15. getSaveModelClone: function() {
  16. return json;
  17. },
  18. };
  19. },
  20. };
  21. var ctrl = new SaveDashboardAsModalCtrl(mockDashboardSrv);
  22. var 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. var 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. var graphPanel = { id: 1, type: 'graph', alert: { rule: 1 }, thresholds: { value: 3000 } };
  40. scenario('should remove alert from graph panel', graphPanel, ctx => {
  41. expect(ctx.panel.alert).toBe(undefined);
  42. });
  43. scenario('should remove threshold from graph panel', graphPanel, ctx => {
  44. expect(ctx.panel.thresholds).toBe(undefined);
  45. });
  46. scenario('singlestat should keep threshold', { id: 1, type: 'singlestat', thresholds: { value: 3000 } }, ctx => {
  47. expect(ctx.panel.thresholds).not.toBe(undefined);
  48. });
  49. scenario('table should keep threshold', { id: 1, type: 'table', thresholds: { value: 3000 } }, ctx => {
  50. expect(ctx.panel.thresholds).not.toBe(undefined);
  51. });
  52. });