AlertListMigration.test.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { PanelModel } from '@grafana/data';
  2. import { alertListPanelMigrationHandler } from './AlertListMigrationHandler';
  3. import { AlertListOptions, ShowOption, SortOrder } from './types';
  4. describe('AlertList Panel Migration', () => {
  5. it('should migrate from < 7.5', () => {
  6. const panel: Omit<PanelModel, 'fieldConfig'> & Record<string, any> = {
  7. id: 7,
  8. links: [],
  9. pluginVersion: '7.4.0',
  10. targets: [],
  11. title: 'Usage',
  12. type: 'alertlist',
  13. nameFilter: 'Customer',
  14. show: 'current',
  15. sortOrder: 1,
  16. stateFilter: ['ok', 'paused'],
  17. dashboardTags: ['tag_a', 'tag_b'],
  18. dashboardFilter: '',
  19. limit: 10,
  20. onlyAlertsOnDashboard: false,
  21. options: {},
  22. };
  23. const newOptions = alertListPanelMigrationHandler(panel as PanelModel);
  24. expect(newOptions).toMatchObject({
  25. showOptions: ShowOption.Current,
  26. maxItems: 10,
  27. sortOrder: SortOrder.AlphaAsc,
  28. dashboardAlerts: false,
  29. alertName: 'Customer',
  30. dashboardTitle: '',
  31. tags: ['tag_a', 'tag_b'],
  32. stateFilter: {
  33. ok: true,
  34. paused: true,
  35. },
  36. folderId: undefined,
  37. });
  38. expect(panel).not.toHaveProperty('show');
  39. expect(panel).not.toHaveProperty('limit');
  40. expect(panel).not.toHaveProperty('sortOrder');
  41. expect(panel).not.toHaveProperty('onlyAlertsOnDashboard');
  42. expect(panel).not.toHaveProperty('nameFilter');
  43. expect(panel).not.toHaveProperty('dashboardFilter');
  44. expect(panel).not.toHaveProperty('folderId');
  45. expect(panel).not.toHaveProperty('dashboardTags');
  46. expect(panel).not.toHaveProperty('stateFilter');
  47. });
  48. it('should handle >= 7.5', () => {
  49. const panel: Omit<PanelModel<AlertListOptions>, 'fieldConfig'> & Record<string, any> = {
  50. id: 7,
  51. links: [],
  52. pluginVersion: '7.5.0',
  53. targets: [],
  54. title: 'Usage',
  55. type: 'alertlist',
  56. options: {
  57. showOptions: ShowOption.Current,
  58. maxItems: 10,
  59. sortOrder: SortOrder.AlphaAsc,
  60. dashboardAlerts: false,
  61. alertName: 'Customer',
  62. dashboardTitle: '',
  63. tags: ['tag_a', 'tag_b'],
  64. stateFilter: {
  65. ok: true,
  66. paused: true,
  67. no_data: false,
  68. execution_error: false,
  69. pending: false,
  70. alerting: false,
  71. },
  72. folderId: 1,
  73. },
  74. };
  75. const newOptions = alertListPanelMigrationHandler(panel as PanelModel);
  76. expect(newOptions).toMatchObject({
  77. showOptions: 'current',
  78. maxItems: 10,
  79. sortOrder: SortOrder.AlphaAsc,
  80. dashboardAlerts: false,
  81. alertName: 'Customer',
  82. dashboardTitle: '',
  83. tags: ['tag_a', 'tag_b'],
  84. stateFilter: {
  85. ok: true,
  86. paused: true,
  87. no_data: false,
  88. execution_error: false,
  89. pending: false,
  90. alerting: false,
  91. },
  92. folderId: 1,
  93. });
  94. expect(panel).not.toHaveProperty('show');
  95. expect(panel).not.toHaveProperty('limit');
  96. expect(panel).not.toHaveProperty('sortOrder');
  97. expect(panel).not.toHaveProperty('onlyAlertsOnDashboard');
  98. expect(panel).not.toHaveProperty('nameFilter');
  99. expect(panel).not.toHaveProperty('dashboardFilter');
  100. expect(panel).not.toHaveProperty('folderId');
  101. expect(panel).not.toHaveProperty('dashboardTags');
  102. expect(panel).not.toHaveProperty('stateFilter');
  103. });
  104. it('should handle config with no options or stateFilter', () => {
  105. const panel: Omit<PanelModel, 'fieldConfig'> & Record<string, any> = {
  106. id: 7,
  107. links: [],
  108. pluginVersion: '7.4.0',
  109. targets: [],
  110. title: 'Usage',
  111. type: 'alertlist',
  112. onlyAlertsOnDashboard: false,
  113. options: {},
  114. };
  115. const newOptions = alertListPanelMigrationHandler(panel as PanelModel);
  116. expect(newOptions).toMatchObject({
  117. showOptions: ShowOption.Current,
  118. maxItems: 10,
  119. sortOrder: SortOrder.AlphaAsc,
  120. dashboardAlerts: false,
  121. alertName: '',
  122. dashboardTitle: '',
  123. tags: [],
  124. stateFilter: {},
  125. folderId: undefined,
  126. });
  127. });
  128. });