save_as_modal.jest.ts 2.1 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. var json = {
  7. title: "name",
  8. rows: [ { panels: [
  9. panel
  10. ]}]
  11. };
  12. var mockDashboardSrv = {
  13. getCurrent: function() {
  14. return {
  15. id: 5,
  16. getSaveModelClone: function() {
  17. return json;
  18. }
  19. };
  20. }
  21. };
  22. var ctrl = new SaveDashboardAsModalCtrl(mockDashboardSrv);
  23. var ctx: any = {
  24. clone: ctrl.clone,
  25. ctrl: ctrl,
  26. panel: {}
  27. };
  28. for (let row of ctrl.clone.rows) {
  29. for (let panel of row.panels) {
  30. ctx.panel = panel;
  31. }
  32. }
  33. it("verify", () => {
  34. verify(ctx);
  35. });
  36. });
  37. }
  38. scenario("default values", {}, (ctx) => {
  39. var clone = ctx.clone;
  40. expect(clone.id).toBe(null);
  41. expect(clone.title).toBe("name Copy");
  42. expect(clone.editable).toBe(true);
  43. expect(clone.hideControls).toBe(false);
  44. });
  45. var graphPanel = { id: 1, type: "graph", alert: { rule: 1}, thresholds: { value: 3000} };
  46. scenario("should remove alert from graph panel", graphPanel , (ctx) => {
  47. expect(ctx.panel.alert).toBe(undefined);
  48. });
  49. scenario("should remove threshold from graph panel", graphPanel, (ctx) => {
  50. expect(ctx.panel.thresholds).toBe(undefined);
  51. });
  52. scenario("singlestat should keep threshold", { id: 1, type: "singlestat", thresholds: { value: 3000} }, (ctx) => {
  53. expect(ctx.panel.thresholds).not.toBe(undefined);
  54. });
  55. scenario("table should keep threshold", { id: 1, type: "table", thresholds: { value: 3000} }, (ctx) => {
  56. expect(ctx.panel.thresholds).not.toBe(undefined);
  57. });
  58. });