1import { PanelModel, FieldConfigSource } from '@grafana/data';
2import { mapMigrationHandler, mapPanelChangedHandler } from './migrations';
3describe('Worldmap Migrations', () => {
4  let prevFieldConfig: FieldConfigSource;
5
6  beforeEach(() => {
7    prevFieldConfig = {
8      defaults: {},
9      overrides: [],
10    };
11  });
12
13  it('simple worldmap', () => {
14    const old: any = {
15      angular: simpleWorldmapConfig,
16    };
17    const panel = {} as PanelModel;
18    panel.options = mapPanelChangedHandler(panel, 'grafana-worldmap-panel', old, prevFieldConfig);
19    expect(panel).toMatchInlineSnapshot(`
20      Object {
21        "fieldConfig": Object {
22          "defaults": Object {
23            "decimals": 3,
24            "thresholds": Object {
25              "mode": "absolute",
26              "steps": Array [
27                Object {
28                  "color": "#37872D",
29                  "value": -Infinity,
30                },
31                Object {
32                  "color": "#E0B400",
33                  "value": 0,
34                },
35                Object {
36                  "color": "#C4162A",
37                  "value": 50,
38                },
39                Object {
40                  "color": "#8F3BB8",
41                  "value": 100,
42                },
43              ],
44            },
45          },
46          "overrides": Array [],
47        },
48        "options": Object {
49          "basemap": Object {
50            "name": "Basemap",
51            "type": "default",
52          },
53          "controls": Object {
54            "mouseWheelZoom": true,
55            "showZoom": true,
56          },
57          "layers": Array [],
58          "view": Object {
59            "id": "europe",
60            "lat": 46,
61            "lon": 14,
62            "zoom": 6,
63          },
64        },
65      }
66    `);
67  });
68});
69
70const 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
110describe('geomap migrations', () => {
111  it('updates marker', () => {
112    const panel = ({
113      type: 'geomap',
114      options: {
115        layers: [
116          {
117            type: 'markers',
118            config: {
119              size: {
120                fixed: 5,
121                min: 2,
122                max: 15,
123                field: 'Count',
124              },
125              color: {
126                fixed: 'dark-green',
127                field: 'Price',
128              },
129              fillOpacity: 0.4,
130              shape: 'triangle',
131              showLegend: true,
132            },
133          },
134        ],
135      },
136      pluginVersion: '8.2.0',
137    } as any) as PanelModel;
138    panel.options = mapMigrationHandler(panel);
139
140    expect(panel).toMatchInlineSnapshot(`
141      Object {
142        "options": Object {
143          "layers": Array [
144            Object {
145              "config": Object {
146                "showLegend": true,
147                "style": Object {
148                  "color": Object {
149                    "field": "Price",
150                    "fixed": "dark-green",
151                  },
152                  "opacity": 0.4,
153                  "rotation": Object {
154                    "fixed": 0,
155                    "max": 360,
156                    "min": -360,
157                    "mode": "mod",
158                  },
159                  "size": Object {
160                    "field": "Count",
161                    "fixed": 5,
162                    "max": 15,
163                    "min": 2,
164                  },
165                  "symbol": Object {
166                    "fixed": "img/icons/marker/triangle.svg",
167                    "mode": "fixed",
168                  },
169                  "textConfig": Object {
170                    "fontSize": 12,
171                    "offsetX": 0,
172                    "offsetY": 0,
173                    "textAlign": "center",
174                    "textBaseline": "middle",
175                  },
176                },
177              },
178              "type": "markers",
179            },
180          ],
181        },
182        "pluginVersion": "8.2.0",
183        "type": "geomap",
184      }
185    `);
186  });
187});
188