spatialTransformer.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { FieldMatcherID, fieldMatchers, FieldType } from '@grafana/data';
  2. import { toDataFrame } from '@grafana/data/src/dataframe/processDataFrame';
  3. import { DataTransformerID } from '@grafana/data/src/transformations/transformers/ids';
  4. import { frameAsGazetter } from 'app/features/geo/gazetteer/gazetteer';
  5. describe('spatial transformer', () => {
  6. it('adds lat/lon based on string field', async () => {
  7. const cfg = {
  8. id: DataTransformerID.spatial,
  9. options: {
  10. lookupField: 'location',
  11. gazetteer: 'public/gazetteer/usa-states.json',
  12. },
  13. };
  14. const data = toDataFrame({
  15. name: 'locations',
  16. fields: [
  17. { name: 'location', type: FieldType.string, values: ['AL', 'AK', 'Arizona', 'Arkansas', 'Somewhere'] },
  18. { name: 'values', type: FieldType.number, values: [0, 10, 5, 1, 5] },
  19. ],
  20. });
  21. const matcher = fieldMatchers.get(FieldMatcherID.byName).get(cfg.options?.lookupField);
  22. const frame = toDataFrame({
  23. fields: [
  24. { name: 'id', values: ['AL', 'AK', 'AZ'] },
  25. { name: 'name', values: ['Alabama', 'Arkansas', 'Arizona'] },
  26. { name: 'lng', values: [-80.891064, -100.891064, -111.891064] },
  27. { name: 'lat', values: [12.448457, 24.448457, 33.448457] },
  28. ],
  29. });
  30. const gaz = frameAsGazetter(frame, { path: 'path/to/gaz.json' });
  31. // TODO!!!!!
  32. expect(gaz).toBeDefined();
  33. expect(matcher).toBeDefined();
  34. expect(data).toBeDefined();
  35. });
  36. });