PanelModel.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. describe('get panel options', () => {
  48. it('should apply defaults', () => {
  49. model.options = { existingProp: 10 };
  50. const options = model.getOptions({
  51. defaultProp: true,
  52. existingProp: 0,
  53. });
  54. expect(options.defaultProp).toBe(true);
  55. expect(options.existingProp).toBe(10);
  56. expect(model.options).toBe(options);
  57. });
  58. });
  59. });
  60. });