Files
grafana/public/app/plugins/panel/geomap/utils/getFeatures.test.ts
renovate[bot] e84a01e870 Update jest monorepo to v29 (#58261)
* Update jest monorepo to v29

* update snapshots + wrap test in act

* fix linting errors: jest.mocked now defaults to deep mocking

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
2022-11-24 14:00:41 +00:00

46 lines
1.1 KiB
TypeScript

import { Feature } from 'ol';
import { Point } from 'ol/geom';
import { GeometryTypeId } from '../style/types';
import { getLayerPropertyInfo, getUniqueFeatureValues } from './getFeatures';
describe('get features utils', () => {
const features = [
new Feature({ a: 1, b: 30, hello: 'world', geometry: new Point([0, 0]) }),
new Feature({ a: 2, b: 20, hello: 'world', geometry: new Point([0, 0]) }),
new Feature({ a: 2, b: 10, c: 30, geometry: new Point([0, 0]) }),
];
it('reads the distinct field names', () => {
const info = getLayerPropertyInfo(features);
expect(info.geometryType).toBe(GeometryTypeId.Point);
expect(info.propertes.map((v) => v.value)).toMatchInlineSnapshot(`
[
"a",
"b",
"hello",
"c",
]
`);
});
it('can collect distinct values', () => {
const uniqueA = getUniqueFeatureValues(features, 'a');
const uniqueB = getUniqueFeatureValues(features, 'b');
expect(uniqueA).toMatchInlineSnapshot(`
[
"1",
"2",
]
`);
expect(uniqueB).toMatchInlineSnapshot(`
[
"10",
"20",
"30",
]
`);
});
});