PanelModel.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import _ from 'lodash';
  2. import { PanelModel } from '../state/PanelModel';
  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. targets: [{ refId: 'A' }, { noRefId: true }],
  11. });
  12. });
  13. it('should apply defaults', () => {
  14. expect(model.gridPos.h).toBe(3);
  15. });
  16. it('should set model props on instance', () => {
  17. expect(model.showColumns).toBe(true);
  18. });
  19. it('should add missing refIds', () => {
  20. expect(model.targets[1].refId).toBe('B');
  21. });
  22. it('getSaveModel should remove defaults', () => {
  23. const saveModel = model.getSaveModel();
  24. expect(saveModel.gridPos).toBe(undefined);
  25. });
  26. it('getSaveModel should remove nonPersistedProperties', () => {
  27. const saveModel = model.getSaveModel();
  28. expect(saveModel.events).toBe(undefined);
  29. });
  30. describe('when changing panel type', () => {
  31. beforeEach(() => {
  32. model.changeType('graph', true);
  33. model.alert = { id: 2 };
  34. });
  35. it('should remove table properties but keep core props', () => {
  36. expect(model.showColumns).toBe(undefined);
  37. });
  38. it('should restore table properties when changing back', () => {
  39. model.changeType('table', true);
  40. expect(model.showColumns).toBe(true);
  41. });
  42. it('should remove alert rule when changing type that does not support it', () => {
  43. model.changeType('table', true);
  44. expect(model.alert).toBe(undefined);
  45. });
  46. });
  47. });
  48. });