getFeatures.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Feature } from 'ol';
  2. import { Point } from 'ol/geom';
  3. import { GeometryTypeId } from '../style/types';
  4. import { getLayerPropertyInfo, getUniqueFeatureValues } from './getFeatures';
  5. describe('get features utils', () => {
  6. const features = [
  7. new Feature({ a: 1, b: 30, hello: 'world', geometry: new Point([0, 0]) }),
  8. new Feature({ a: 2, b: 20, hello: 'world', geometry: new Point([0, 0]) }),
  9. new Feature({ a: 2, b: 10, c: 30, geometry: new Point([0, 0]) }),
  10. ];
  11. it('reads the distinct field names', () => {
  12. const info = getLayerPropertyInfo(features);
  13. expect(info.geometryType).toBe(GeometryTypeId.Point);
  14. expect(info.propertes.map((v) => v.value)).toMatchInlineSnapshot(`
  15. Array [
  16. "a",
  17. "b",
  18. "hello",
  19. "c",
  20. ]
  21. `);
  22. });
  23. it('can collect distinct values', () => {
  24. const uniqueA = getUniqueFeatureValues(features, 'a');
  25. const uniqueB = getUniqueFeatureValues(features, 'b');
  26. expect(uniqueA).toMatchInlineSnapshot(`
  27. Array [
  28. "1",
  29. "2",
  30. ]
  31. `);
  32. expect(uniqueB).toMatchInlineSnapshot(`
  33. Array [
  34. "10",
  35. "20",
  36. "30",
  37. ]
  38. `);
  39. });
  40. });