This commit is contained in:
Andras Schmelczer 2026-05-09 09:26:40 +01:00
parent 701c17a703
commit f114ada255
44 changed files with 5264 additions and 1674 deletions

View file

@ -4,6 +4,12 @@ import type { FeatureMeta } from '../types';
import { apiUrl, assertOk, buildFilterString, isAbortError } from './api';
import { createSchoolFilterKey } from './school-filter';
import { createSpecificCrimeFilterKey } from './crime-filter';
import { createEthnicityFilterKey } from './ethnicity-filter';
import {
POI_COUNT_2KM_FILTER_NAME,
createPoiDistanceFilterKey,
createPoiFilterKey,
} from './poi-distance-filter';
describe('api utilities', () => {
it('builds API URLs from endpoint names, paths, and params', () => {
@ -99,4 +105,52 @@ describe('api utilities', () => {
)
).toBe('Burglary (avg/yr):0:5;;Vehicle crime (avg/yr):1:10');
});
it('deduplicates repeated ethnicity filters to the strictest backend range', () => {
const features: FeatureMeta[] = [{ name: '% White', type: 'numeric', min: 0, max: 100 }];
expect(
buildFilterString(
{
[createEthnicityFilterKey('% White', 1)]: [10, 90],
[createEthnicityFilterKey('% White', 2)]: [20, 80],
},
features
)
).toBe('% White:20:80');
});
it('serializes POI distance filters using their selected backend feature', () => {
const features: FeatureMeta[] = [
{ name: 'Distance to nearest park (km)', type: 'numeric', min: 0, max: 2 },
{ name: 'Distance to nearest Tesco (km)', type: 'numeric', min: 0, max: 5 },
];
expect(
buildFilterString(
{
[createPoiDistanceFilterKey('Distance to nearest park (km)', 1)]: [0, 0.5],
[createPoiDistanceFilterKey('Distance to nearest Tesco (km)', 2)]: [0, 1],
},
features
)
).toBe('Distance to nearest park (km):0:0.5;;Distance to nearest Tesco (km):0:1');
});
it('serializes POI count filters using their selected backend feature', () => {
const features: FeatureMeta[] = [
{ name: 'Number of Cafe POIs within 2km', type: 'numeric', min: 0, max: 20 },
];
expect(
buildFilterString(
{
[createPoiFilterKey(POI_COUNT_2KM_FILTER_NAME, 'Number of Cafe POIs within 2km', 1)]: [
2, 10,
],
},
features
)
).toBe('Number of Cafe POIs within 2km:2:10');
});
});