PanelModel.test.ts 1.6 KB

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