grafana/public/app/features/geo/gazetteer/gazetteer.test.ts
Ashley Harrison f8d89eff56
Chore: fix type errors in tests (#63270)
* 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
2023-02-14 16:46:42 +01:00

93 lines
2.0 KiB
TypeScript

import { getCenterPointWGS84 } from 'app/features/transformers/spatial/utils';
import { getGazetteer } from './gazetteer';
let backendResults: Record<string, unknown> = { hello: 'world' };
const geojsonObject = {
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: {
some_code: 'B',
hello: 'B',
},
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [2, 2],
},
properties: {
an_id: 'C',
hello: 'C',
},
},
],
};
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
getBackendSrv: () => ({
get: jest.fn().mockResolvedValue(backendResults),
}),
}));
describe('Placename lookup from geojson format', () => {
beforeEach(() => {
backendResults = { hello: 'world' };
});
it('can lookup by id', async () => {
backendResults = geojsonObject;
const gaz = await getGazetteer('local');
expect(gaz.error).toBeUndefined();
expect(getCenterPointWGS84(gaz.find('A')?.geometry())).toMatchInlineSnapshot(`
[
0,
0,
]
`);
});
it('can look up by a code', async () => {
backendResults = geojsonObject;
const gaz = await getGazetteer('airports');
expect(gaz.error).toBeUndefined();
expect(getCenterPointWGS84(gaz.find('B')?.geometry())).toMatchInlineSnapshot(`
[
1,
1,
]
`);
});
it('can look up by an id property', async () => {
backendResults = geojsonObject;
const gaz = await getGazetteer('airports');
expect(gaz.error).toBeUndefined();
expect(getCenterPointWGS84(gaz.find('C')?.geometry())).toMatchInlineSnapshot(`
[
2,
2,
]
`);
});
});