mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* fix any's in tests * fix more any's in tests * more test type fixes * fixing any's in tests part 3 * more test type fixes * fixing test any's p5 * some tidy up * fix template_srv
115 lines
2.3 KiB
TypeScript
115 lines
2.3 KiB
TypeScript
import { dataFrameToJSON, FieldType } from '@grafana/data';
|
|
|
|
import { frameFromGeoJSON } from './geojson';
|
|
|
|
describe('Read GeoJSON', () => {
|
|
it('supports simple read', () => {
|
|
const frame = frameFromGeoJSON({
|
|
type: 'FeatureCollection',
|
|
features: [
|
|
{
|
|
id: 'A',
|
|
type: 'Feature',
|
|
geometry: {
|
|
type: 'Point',
|
|
coordinates: [0, 0],
|
|
},
|
|
properties: {
|
|
hello: 'A',
|
|
},
|
|
},
|
|
{
|
|
type: 'Feature',
|
|
geometry: {
|
|
type: 'Point',
|
|
coordinates: [1, 1],
|
|
},
|
|
properties: {
|
|
number: 1.2,
|
|
hello: 'B',
|
|
mixed: 'first',
|
|
},
|
|
},
|
|
{
|
|
type: 'Feature',
|
|
geometry: {
|
|
type: 'Point',
|
|
coordinates: [2, 2],
|
|
},
|
|
properties: {
|
|
number: 2.3,
|
|
mixed: 2,
|
|
},
|
|
},
|
|
],
|
|
});
|
|
const msg = dataFrameToJSON(frame);
|
|
expect(msg.schema).toMatchInlineSnapshot(`
|
|
{
|
|
"fields": [
|
|
{
|
|
"config": {},
|
|
"name": "id",
|
|
"type": "string",
|
|
},
|
|
{
|
|
"config": {},
|
|
"name": "geo",
|
|
"type": "geo",
|
|
},
|
|
{
|
|
"config": {},
|
|
"name": "hello",
|
|
"type": "string",
|
|
},
|
|
{
|
|
"config": {},
|
|
"name": "number",
|
|
"type": "number",
|
|
},
|
|
{
|
|
"config": {},
|
|
"name": "mixed",
|
|
"type": "string",
|
|
},
|
|
],
|
|
"meta": undefined,
|
|
"name": undefined,
|
|
"refId": undefined,
|
|
}
|
|
`);
|
|
|
|
expect(
|
|
frame.fields.reduce<Record<string, unknown[]>>((acc, v, idx, arr) => {
|
|
if (v.type !== FieldType.geo) {
|
|
acc[v.name] = v.values.toArray();
|
|
}
|
|
return acc;
|
|
}, {})
|
|
).toMatchInlineSnapshot(`
|
|
{
|
|
"hello": [
|
|
"A",
|
|
"B",
|
|
null,
|
|
],
|
|
"id": [
|
|
"A",
|
|
null,
|
|
null,
|
|
],
|
|
"mixed": [
|
|
null,
|
|
"first",
|
|
"2",
|
|
],
|
|
"number": [
|
|
null,
|
|
1.2,
|
|
2.3,
|
|
],
|
|
}
|
|
`);
|
|
});
|
|
});
|