GaugeMigrations.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { PanelModel } from '@grafana/ui';
  2. import { gaugePanelMigrationHandler, gaugePanelChangedHandler } from './GaugeMigrations';
  3. describe('Gauge Panel Migrations', () => {
  4. it('from 6.1.1', () => {
  5. const panel = {
  6. datasource: '-- Grafana --',
  7. gridPos: {
  8. h: 9,
  9. w: 12,
  10. x: 0,
  11. y: 0,
  12. },
  13. id: 2,
  14. options: {
  15. maxValue: '50',
  16. minValue: '-50',
  17. orientation: 'auto',
  18. showThresholdLabels: true,
  19. showThresholdMarkers: true,
  20. thresholds: [
  21. {
  22. color: 'green',
  23. index: 0,
  24. value: null,
  25. },
  26. {
  27. color: '#EAB839',
  28. index: 1,
  29. value: -25,
  30. },
  31. {
  32. color: '#6ED0E0',
  33. index: 2,
  34. value: 0,
  35. },
  36. {
  37. color: 'red',
  38. index: 3,
  39. value: 25,
  40. },
  41. ],
  42. valueMappings: [
  43. {
  44. id: 1,
  45. operator: '',
  46. value: '',
  47. text: 'BIG',
  48. type: 2,
  49. from: '50',
  50. to: '1000',
  51. },
  52. ],
  53. valueOptions: {
  54. decimals: 3,
  55. prefix: 'XX',
  56. stat: 'last',
  57. suffix: 'YY',
  58. unit: 'accMS2',
  59. },
  60. },
  61. pluginVersion: '6.1.6',
  62. targets: [
  63. {
  64. refId: 'A',
  65. },
  66. {
  67. refId: 'B',
  68. },
  69. {
  70. refId: 'C',
  71. },
  72. ],
  73. timeFrom: null,
  74. timeShift: null,
  75. title: 'Panel Title',
  76. type: 'gauge',
  77. } as PanelModel;
  78. expect(gaugePanelMigrationHandler(panel)).toMatchSnapshot();
  79. });
  80. it('change from angular singlestat to gauge', () => {
  81. const old: any = {
  82. angular: {
  83. format: 'ms',
  84. decimals: 7,
  85. gauge: {
  86. maxValue: 150,
  87. minValue: -10,
  88. show: true,
  89. thresholdLabels: true,
  90. thresholdMarkers: true,
  91. },
  92. },
  93. };
  94. const newOptions = gaugePanelChangedHandler({} as any, 'singlestat', old);
  95. expect(newOptions.fieldOptions.defaults.unit).toBe('ms');
  96. expect(newOptions.fieldOptions.defaults.min).toBe(-10);
  97. expect(newOptions.fieldOptions.defaults.max).toBe(150);
  98. expect(newOptions.fieldOptions.defaults.decimals).toBe(7);
  99. expect(newOptions.showThresholdMarkers).toBe(true);
  100. expect(newOptions.showThresholdLabels).toBe(true);
  101. });
  102. });