panel_model.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import _ from 'lodash';
  2. import { PanelModel } from '../panel_model';
  3. describe('PanelModel', () => {
  4. describe('when creating new panel model', () => {
  5. let model;
  6. beforeEach(() => {
  7. model = new PanelModel({
  8. type: 'table',
  9. showColumns: true,
  10. });
  11. });
  12. it('should apply defaults', () => {
  13. expect(model.gridPos.h).toBe(3);
  14. });
  15. it('should set model props on instance', () => {
  16. expect(model.showColumns).toBe(true);
  17. });
  18. it('getSaveModel should remove defaults', () => {
  19. const saveModel = model.getSaveModel();
  20. expect(saveModel.gridPos).toBe(undefined);
  21. });
  22. it('getSaveModel should remove nonPersistedProperties', () => {
  23. const saveModel = model.getSaveModel();
  24. expect(saveModel.events).toBe(undefined);
  25. });
  26. describe('when changing panel type', () => {
  27. beforeEach(() => {
  28. model.changeType('graph', true);
  29. model.alert = { id: 2 };
  30. });
  31. it('should remove table properties but keep core props', () => {
  32. expect(model.showColumns).toBe(undefined);
  33. });
  34. it('should restore table properties when changing back', () => {
  35. model.changeType('table', true);
  36. expect(model.showColumns).toBe(true);
  37. });
  38. it('should remove alert rule when changing type that does not support it', () => {
  39. model.changeType('table', true);
  40. expect(model.alert).toBe(undefined);
  41. });
  42. });
  43. });
  44. });