GraphMigrations.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { PanelModel, FieldConfigSource, DataQuery } from '@grafana/data';
  2. import { graphPanelMigrationHandler } from './GraphMigrations';
  3. describe('Graph Panel Migrations', () => {
  4. it('from 7.0', () => {
  5. const panel = {
  6. aliasColors: {},
  7. bars: false,
  8. dashLength: 10,
  9. dashes: false,
  10. fill: 1,
  11. fillGradient: 0,
  12. gridPos: {
  13. h: 8,
  14. w: 9,
  15. x: 6,
  16. y: 0,
  17. },
  18. hiddenSeries: false,
  19. id: 23763571993,
  20. legend: {
  21. avg: false,
  22. current: false,
  23. max: false,
  24. min: false,
  25. show: true,
  26. total: false,
  27. values: false,
  28. },
  29. lines: true,
  30. linewidth: 1,
  31. nullPointMode: 'null',
  32. options: {
  33. dataLinks: [
  34. {
  35. targetBlank: false,
  36. title: 'Drill it down',
  37. url: 'THE DRILLDOWN URL',
  38. },
  39. ],
  40. },
  41. percentage: false,
  42. pointradius: 2,
  43. points: false,
  44. renderer: 'flot',
  45. seriesOverrides: [
  46. {
  47. alias: 'Bar datacenter {datacenter="baz", region="us-east-2"}',
  48. yaxis: 2,
  49. },
  50. ],
  51. spaceLength: 10,
  52. stack: false,
  53. steppedLine: false,
  54. targets: [
  55. {
  56. alias: 'Foo datacenter',
  57. labels: 'datacenter=foo,region=us-east-1',
  58. refId: 'A',
  59. scenarioId: 'random_walk',
  60. },
  61. {
  62. alias: 'Bar datacenter',
  63. labels: 'datacenter=bar,region=us-east-2',
  64. refId: 'B',
  65. scenarioId: 'random_walk',
  66. },
  67. {
  68. alias: 'Bar datacenter',
  69. labels: 'datacenter=baz,region=us-east-2',
  70. refId: 'C',
  71. scenarioId: 'random_walk',
  72. },
  73. ] as unknown as DataQuery[],
  74. thresholds: [],
  75. timeFrom: null,
  76. timeRegions: [],
  77. timeShift: null,
  78. title: 'Multiple series',
  79. tooltip: {
  80. shared: true,
  81. sort: 0,
  82. value_type: 'individual',
  83. },
  84. type: 'graph',
  85. xaxis: {
  86. buckets: null,
  87. mode: 'time',
  88. name: null,
  89. show: true,
  90. values: [],
  91. },
  92. yaxes: [
  93. {
  94. format: 'percent',
  95. label: null,
  96. logBase: 1,
  97. max: null,
  98. min: null,
  99. show: true,
  100. $$hashKey: 'object:122',
  101. },
  102. {
  103. format: 'gflops',
  104. label: null,
  105. logBase: 1,
  106. max: null,
  107. min: null,
  108. show: true,
  109. $$hashKey: 'object:123',
  110. },
  111. ],
  112. yaxis: {
  113. align: false,
  114. alignLevel: null,
  115. },
  116. datasource: null,
  117. } as Omit<PanelModel, 'fieldConfig'>;
  118. const result = graphPanelMigrationHandler(panel as PanelModel);
  119. const fieldSource = (panel as any).fieldConfig as FieldConfigSource;
  120. expect(result.dataLinks).toBeUndefined();
  121. expect(fieldSource.defaults.links).toHaveLength(1);
  122. const link = fieldSource.defaults.links![0];
  123. expect(link.url).toEqual('THE DRILLDOWN URL');
  124. });
  125. it('from 7.1 it should preserve existing fieldConfig', () => {
  126. const panel = {
  127. id: 1,
  128. fieldConfig: {
  129. defaults: {
  130. links: [
  131. {
  132. title: 'Details',
  133. url: '/link',
  134. },
  135. ],
  136. },
  137. overrides: [],
  138. },
  139. } as unknown as PanelModel;
  140. graphPanelMigrationHandler(panel as PanelModel);
  141. const fieldConfig = (panel as any).fieldConfig as FieldConfigSource;
  142. expect(fieldConfig.defaults.links).toHaveLength(1);
  143. });
  144. });