gazetteer.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { getCenterPointWGS84 } from 'app/features/transformers/spatial/utils';
  2. import { getGazetteer } from './gazetteer';
  3. let backendResults: any = { hello: 'world' };
  4. const geojsonObject = {
  5. type: 'FeatureCollection',
  6. features: [
  7. {
  8. id: 'A',
  9. type: 'Feature',
  10. geometry: {
  11. type: 'Point',
  12. coordinates: [0, 0],
  13. },
  14. properties: {
  15. hello: 'A',
  16. },
  17. },
  18. {
  19. type: 'Feature',
  20. geometry: {
  21. type: 'Point',
  22. coordinates: [1, 1],
  23. },
  24. properties: {
  25. some_code: 'B',
  26. hello: 'B',
  27. },
  28. },
  29. {
  30. type: 'Feature',
  31. geometry: {
  32. type: 'Point',
  33. coordinates: [2, 2],
  34. },
  35. properties: {
  36. an_id: 'C',
  37. hello: 'C',
  38. },
  39. },
  40. ],
  41. };
  42. jest.mock('@grafana/runtime', () => ({
  43. ...(jest.requireActual('@grafana/runtime') as unknown as object),
  44. getBackendSrv: () => ({
  45. get: jest.fn().mockResolvedValue(backendResults),
  46. }),
  47. }));
  48. describe('Placename lookup from geojson format', () => {
  49. beforeEach(() => {
  50. backendResults = { hello: 'world' };
  51. });
  52. it('can lookup by id', async () => {
  53. backendResults = geojsonObject;
  54. const gaz = await getGazetteer('local');
  55. expect(gaz.error).toBeUndefined();
  56. expect(getCenterPointWGS84(gaz.find('A')?.geometry())).toMatchInlineSnapshot(`
  57. Array [
  58. 0,
  59. 0,
  60. ]
  61. `);
  62. });
  63. it('can look up by a code', async () => {
  64. backendResults = geojsonObject;
  65. const gaz = await getGazetteer('airports');
  66. expect(gaz.error).toBeUndefined();
  67. expect(getCenterPointWGS84(gaz.find('B')?.geometry())).toMatchInlineSnapshot(`
  68. Array [
  69. 1,
  70. 1,
  71. ]
  72. `);
  73. });
  74. it('can look up by an id property', async () => {
  75. backendResults = geojsonObject;
  76. const gaz = await getGazetteer('airports');
  77. expect(gaz.error).toBeUndefined();
  78. expect(getCenterPointWGS84(gaz.find('C')?.geometry())).toMatchInlineSnapshot(`
  79. Array [
  80. 2,
  81. 2,
  82. ]
  83. `);
  84. });
  85. });