2022-02-17 10:12:38 -06:00
|
|
|
import { getCenterPointWGS84 } from 'app/features/transformers/spatial/utils';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-10-19 23:05:55 -05:00
|
|
|
import { getGazetteer } from './gazetteer';
|
|
|
|
|
|
|
|
let backendResults: any = { 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', () => ({
|
2022-02-02 06:02:32 -06:00
|
|
|
...(jest.requireActual('@grafana/runtime') as unknown as object),
|
2021-10-19 23:05:55 -05:00
|
|
|
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();
|
2022-01-21 16:27:26 -06:00
|
|
|
expect(getCenterPointWGS84(gaz.find('A')?.geometry())).toMatchInlineSnapshot(`
|
2022-11-24 08:00:41 -06:00
|
|
|
[
|
2022-01-13 19:15:31 -06:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
]
|
2021-10-19 23:05:55 -05:00
|
|
|
`);
|
|
|
|
});
|
|
|
|
it('can look up by a code', async () => {
|
|
|
|
backendResults = geojsonObject;
|
|
|
|
const gaz = await getGazetteer('airports');
|
|
|
|
expect(gaz.error).toBeUndefined();
|
2022-01-21 16:27:26 -06:00
|
|
|
expect(getCenterPointWGS84(gaz.find('B')?.geometry())).toMatchInlineSnapshot(`
|
2022-11-24 08:00:41 -06:00
|
|
|
[
|
2022-01-13 19:15:31 -06:00
|
|
|
1,
|
|
|
|
1,
|
|
|
|
]
|
2021-10-19 23:05:55 -05:00
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can look up by an id property', async () => {
|
|
|
|
backendResults = geojsonObject;
|
|
|
|
const gaz = await getGazetteer('airports');
|
|
|
|
expect(gaz.error).toBeUndefined();
|
2022-01-21 16:27:26 -06:00
|
|
|
expect(getCenterPointWGS84(gaz.find('C')?.geometry())).toMatchInlineSnapshot(`
|
2022-11-24 08:00:41 -06:00
|
|
|
[
|
2022-01-13 19:15:31 -06:00
|
|
|
2,
|
|
|
|
2,
|
|
|
|
]
|
2021-10-19 23:05:55 -05:00
|
|
|
`);
|
|
|
|
});
|
|
|
|
});
|