migrations.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { PanelModel } from '@grafana/data';
  2. import { tablePanelChangedHandler } from './migrations';
  3. describe('Table Migrations', () => {
  4. it('migrates transform out to core transforms', () => {
  5. const toColumns = {
  6. angular: {
  7. columns: [],
  8. styles: [],
  9. transform: 'timeseries_to_columns',
  10. options: {},
  11. },
  12. };
  13. const toRows = {
  14. angular: {
  15. columns: [],
  16. styles: [],
  17. transform: 'timeseries_to_rows',
  18. options: {},
  19. },
  20. };
  21. const aggregations = {
  22. angular: {
  23. columns: [
  24. {
  25. text: 'Avg',
  26. value: 'avg',
  27. $$hashKey: 'object:82',
  28. },
  29. {
  30. text: 'Max',
  31. value: 'max',
  32. $$hashKey: 'object:83',
  33. },
  34. {
  35. text: 'Current',
  36. value: 'current',
  37. $$hashKey: 'object:84',
  38. },
  39. ],
  40. styles: [],
  41. transform: 'timeseries_aggregations',
  42. options: {},
  43. },
  44. };
  45. const table = {
  46. angular: {
  47. columns: [],
  48. styles: [],
  49. transform: 'table',
  50. options: {},
  51. },
  52. };
  53. const columnsPanel = {} as PanelModel;
  54. tablePanelChangedHandler(columnsPanel, 'table-old', toColumns);
  55. expect(columnsPanel).toMatchSnapshot();
  56. const rowsPanel = {} as PanelModel;
  57. tablePanelChangedHandler(rowsPanel, 'table-old', toRows);
  58. expect(rowsPanel).toMatchSnapshot();
  59. const aggregationsPanel = {} as PanelModel;
  60. tablePanelChangedHandler(aggregationsPanel, 'table-old', aggregations);
  61. expect(aggregationsPanel).toMatchSnapshot();
  62. const tablePanel = {} as PanelModel;
  63. tablePanelChangedHandler(tablePanel, 'table-old', table);
  64. expect(tablePanel).toMatchSnapshot();
  65. });
  66. it('migrates styles to field config overrides and defaults', () => {
  67. const oldStyles = {
  68. angular: {
  69. columns: [],
  70. styles: [
  71. {
  72. alias: 'Time',
  73. align: 'auto',
  74. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  75. pattern: 'Time',
  76. type: 'date',
  77. $$hashKey: 'object:195',
  78. },
  79. {
  80. alias: '',
  81. align: 'left',
  82. colorMode: 'cell',
  83. colors: ['rgba(245, 54, 54, 0.9)', 'rgba(237, 129, 40, 0.89)', 'rgba(50, 172, 45, 0.97)'],
  84. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  85. decimals: 2,
  86. mappingType: 1,
  87. pattern: 'ColorCell',
  88. thresholds: ['5', '10'],
  89. type: 'number',
  90. unit: 'currencyUSD',
  91. $$hashKey: 'object:196',
  92. },
  93. {
  94. alias: '',
  95. align: 'auto',
  96. colorMode: 'value',
  97. colors: ['rgba(245, 54, 54, 0.9)', 'rgba(237, 129, 40, 0.89)', 'rgba(50, 172, 45, 0.97)'],
  98. dateFormat: 'YYYY-MM-DD HH:mm:ss',
  99. decimals: 2,
  100. link: true,
  101. linkTargetBlank: true,
  102. linkTooltip: '',
  103. linkUrl: 'http://www.grafana.com',
  104. mappingType: 1,
  105. pattern: 'ColorValue',
  106. thresholds: ['5', '10'],
  107. type: 'number',
  108. unit: 'Bps',
  109. $$hashKey: 'object:197',
  110. },
  111. {
  112. unit: 'short',
  113. type: 'number',
  114. alias: '',
  115. decimals: 2,
  116. colors: ['rgba(245, 54, 54, 0.9)', 'rgba(237, 129, 40, 0.89)', 'rgba(50, 172, 45, 0.97)'],
  117. colorMode: null,
  118. pattern: '/.*/',
  119. thresholds: [],
  120. align: 'right',
  121. },
  122. ],
  123. },
  124. };
  125. const panel = {} as PanelModel;
  126. tablePanelChangedHandler(panel, 'table-old', oldStyles);
  127. expect(panel).toMatchSnapshot();
  128. });
  129. });