migrations.test.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { PanelModel, FieldConfigSource } from '@grafana/data';
  2. import { mapMigrationHandler, mapPanelChangedHandler } from './migrations';
  3. describe('Worldmap Migrations', () => {
  4. let prevFieldConfig: FieldConfigSource;
  5. beforeEach(() => {
  6. prevFieldConfig = {
  7. defaults: {},
  8. overrides: [],
  9. };
  10. });
  11. it('simple worldmap', () => {
  12. const old: any = {
  13. angular: simpleWorldmapConfig,
  14. };
  15. const panel = {} as PanelModel;
  16. panel.options = mapPanelChangedHandler(panel, 'grafana-worldmap-panel', old, prevFieldConfig);
  17. expect(panel).toMatchInlineSnapshot(`
  18. Object {
  19. "fieldConfig": Object {
  20. "defaults": Object {
  21. "decimals": 3,
  22. "thresholds": Object {
  23. "mode": "absolute",
  24. "steps": Array [
  25. Object {
  26. "color": "#37872D",
  27. "value": -Infinity,
  28. },
  29. Object {
  30. "color": "#E0B400",
  31. "value": 0,
  32. },
  33. Object {
  34. "color": "#C4162A",
  35. "value": 50,
  36. },
  37. Object {
  38. "color": "#8F3BB8",
  39. "value": 100,
  40. },
  41. ],
  42. },
  43. },
  44. "overrides": Array [],
  45. },
  46. "options": Object {
  47. "basemap": Object {
  48. "name": "Basemap",
  49. "type": "default",
  50. },
  51. "controls": Object {
  52. "mouseWheelZoom": true,
  53. "showZoom": true,
  54. },
  55. "layers": Array [],
  56. "tooltip": Object {
  57. "mode": "details",
  58. },
  59. "view": Object {
  60. "id": "europe",
  61. "lat": 46,
  62. "lon": 14,
  63. "zoom": 6,
  64. },
  65. },
  66. }
  67. `);
  68. });
  69. });
  70. const simpleWorldmapConfig = {
  71. id: 23763571993,
  72. gridPos: {
  73. h: 8,
  74. w: 12,
  75. x: 0,
  76. y: 0,
  77. },
  78. type: 'grafana-worldmap-panel',
  79. title: 'Panel Title',
  80. thresholds: '0,50,100',
  81. maxDataPoints: 1,
  82. circleMaxSize: 30,
  83. circleMinSize: 2,
  84. colors: ['#37872D', '#E0B400', '#C4162A', '#8F3BB8'],
  85. decimals: 3,
  86. esMetric: 'Count',
  87. hideEmpty: false,
  88. hideZero: false,
  89. initialZoom: '6',
  90. locationData: 'countries',
  91. mapCenter: 'Europe',
  92. mapCenterLatitude: 46,
  93. mapCenterLongitude: 14,
  94. mouseWheelZoom: true,
  95. showLegend: true,
  96. stickyLabels: false,
  97. tableQueryOptions: {
  98. geohashField: 'geohash',
  99. latitudeField: 'latitude',
  100. longitudeField: 'longitude',
  101. metricField: 'metric',
  102. queryType: 'geohash',
  103. },
  104. unitPlural: '',
  105. unitSingle: '',
  106. valueName: 'total',
  107. datasource: null,
  108. };
  109. describe('geomap migrations', () => {
  110. it('updates marker', () => {
  111. const panel = {
  112. type: 'geomap',
  113. options: {
  114. layers: [
  115. {
  116. type: 'markers',
  117. config: {
  118. size: {
  119. fixed: 5,
  120. min: 2,
  121. max: 15,
  122. field: 'Count',
  123. },
  124. color: {
  125. fixed: 'dark-green',
  126. field: 'Price',
  127. },
  128. fillOpacity: 0.4,
  129. shape: 'triangle',
  130. showLegend: true,
  131. },
  132. },
  133. ],
  134. },
  135. pluginVersion: '8.2.0',
  136. } as any as PanelModel;
  137. panel.options = mapMigrationHandler(panel);
  138. expect(panel).toMatchInlineSnapshot(`
  139. Object {
  140. "options": Object {
  141. "layers": Array [
  142. Object {
  143. "config": Object {
  144. "showLegend": true,
  145. "style": Object {
  146. "color": Object {
  147. "field": "Price",
  148. "fixed": "dark-green",
  149. },
  150. "opacity": 0.4,
  151. "rotation": Object {
  152. "fixed": 0,
  153. "max": 360,
  154. "min": -360,
  155. "mode": "mod",
  156. },
  157. "size": Object {
  158. "field": "Count",
  159. "fixed": 5,
  160. "max": 15,
  161. "min": 2,
  162. },
  163. "symbol": Object {
  164. "fixed": "img/icons/marker/triangle.svg",
  165. "mode": "fixed",
  166. },
  167. "textConfig": Object {
  168. "fontSize": 12,
  169. "offsetX": 0,
  170. "offsetY": 0,
  171. "textAlign": "center",
  172. "textBaseline": "middle",
  173. },
  174. },
  175. },
  176. "type": "markers",
  177. },
  178. ],
  179. },
  180. "pluginVersion": "8.2.0",
  181. "type": "geomap",
  182. }
  183. `);
  184. });
  185. });