BarGaugeMigrations.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { PanelModel } from '@grafana/data';
  2. import { barGaugePanelMigrationHandler } from './BarGaugeMigrations';
  3. describe('BarGauge Panel Migrations', () => {
  4. it('from 6.2', () => {
  5. const panel = {
  6. id: 7,
  7. links: [],
  8. options: {
  9. displayMode: 'lcd',
  10. fieldOptions: {
  11. calcs: ['mean'],
  12. defaults: {
  13. decimals: null,
  14. max: -22,
  15. min: 33,
  16. unit: 'watt',
  17. },
  18. mappings: [],
  19. override: {},
  20. thresholds: [
  21. {
  22. color: 'green',
  23. index: 0,
  24. value: -Infinity,
  25. },
  26. {
  27. color: 'orange',
  28. index: 1,
  29. value: 40,
  30. },
  31. {
  32. color: 'red',
  33. index: 2,
  34. value: 80,
  35. },
  36. ],
  37. values: false,
  38. },
  39. orientation: 'vertical',
  40. },
  41. pluginVersion: '6.2.0',
  42. targets: [],
  43. title: 'Usage',
  44. type: 'bargauge',
  45. } as Omit<PanelModel, 'fieldConfig'>;
  46. const newOptions = barGaugePanelMigrationHandler(panel as PanelModel);
  47. // should mutate panel model and move field config out of panel.options
  48. expect((panel as any).fieldConfig).toMatchInlineSnapshot(`
  49. Object {
  50. "defaults": Object {
  51. "color": Object {
  52. "mode": "thresholds",
  53. },
  54. "decimals": null,
  55. "mappings": Array [],
  56. "max": 33,
  57. "min": -22,
  58. "thresholds": Object {
  59. "mode": "absolute",
  60. "steps": Array [
  61. Object {
  62. "color": "green",
  63. "index": 0,
  64. "value": -Infinity,
  65. },
  66. Object {
  67. "color": "orange",
  68. "index": 1,
  69. "value": 40,
  70. },
  71. Object {
  72. "color": "red",
  73. "index": 2,
  74. "value": 80,
  75. },
  76. ],
  77. },
  78. "unit": "watt",
  79. },
  80. "overrides": Array [],
  81. }
  82. `);
  83. // should options options
  84. expect(newOptions).toMatchInlineSnapshot(`
  85. Object {
  86. "displayMode": "lcd",
  87. "orientation": "vertical",
  88. "reduceOptions": Object {
  89. "calcs": Array [
  90. "mean",
  91. ],
  92. "limit": undefined,
  93. "values": false,
  94. },
  95. }
  96. `);
  97. });
  98. });