LGTM
This commit is contained in:
parent
701c17a703
commit
f114ada255
44 changed files with 5264 additions and 1674 deletions
|
|
@ -2,8 +2,15 @@ import { beforeEach, describe, expect, it } from 'vitest';
|
|||
|
||||
import type { FeatureMeta } from '../types';
|
||||
import { parseUrlState, stateToParams } from './url-state';
|
||||
import { INITIAL_VIEW_STATE } from './consts';
|
||||
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('url-state', () => {
|
||||
beforeEach(() => {
|
||||
|
|
@ -43,6 +50,15 @@ describe('url-state', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('leaves POIs unselected when URL params are omitted', () => {
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.viewState).toEqual(INITIAL_VIEW_STATE);
|
||||
expect(state.filters).toEqual({});
|
||||
expect(state.poiCategories).toEqual(new Set());
|
||||
expect(state.tab).toBe('area');
|
||||
});
|
||||
|
||||
it('serializes map state and active filters into stable URL params', () => {
|
||||
const features: FeatureMeta[] = [
|
||||
{ name: 'Last known price', type: 'numeric' },
|
||||
|
|
@ -81,6 +97,17 @@ describe('url-state', () => {
|
|||
expect(params.getAll('tt')).toEqual(['bicycle:bank:Bank:5:25']);
|
||||
});
|
||||
|
||||
it('round-trips an explicitly empty POI selection', () => {
|
||||
const params = stateToParams(null, {}, [], new Set(), 'area');
|
||||
|
||||
expect(params.getAll('poi')).toEqual(['__none']);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.poiCategories).toEqual(new Set());
|
||||
});
|
||||
|
||||
it('round-trips repeated school filters with dedicated URL params', () => {
|
||||
const schoolOne = createSchoolFilterKey('primary', 'good', 2, 1);
|
||||
const schoolTwo = createSchoolFilterKey('secondary', 'outstanding', 5, 2);
|
||||
|
|
@ -141,6 +168,91 @@ describe('url-state', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('round-trips repeated ethnicity filters with dedicated URL params', () => {
|
||||
const white = createEthnicityFilterKey('% White', 3);
|
||||
const southAsian = createEthnicityFilterKey('% South Asian', 4);
|
||||
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{
|
||||
[white]: [10, 80],
|
||||
[southAsian]: [5, 35],
|
||||
},
|
||||
[],
|
||||
new Set(),
|
||||
'area'
|
||||
);
|
||||
|
||||
expect(params.getAll('ethnicity')).toEqual(['% White:10:80', '% South Asian:5:35']);
|
||||
expect(params.getAll('filter')).toEqual([]);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.filters).toEqual({
|
||||
[createEthnicityFilterKey('% White', 0)]: [10, 80],
|
||||
[createEthnicityFilterKey('% South Asian', 1)]: [5, 35],
|
||||
});
|
||||
});
|
||||
|
||||
it('round-trips repeated POI distance filters with dedicated URL params', () => {
|
||||
const park = createPoiDistanceFilterKey('Distance to nearest park (km)', 3);
|
||||
const tesco = createPoiDistanceFilterKey('Distance to nearest Tesco (km)', 4);
|
||||
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{
|
||||
[park]: [0, 0.4],
|
||||
[tesco]: [0, 1.5],
|
||||
},
|
||||
[],
|
||||
new Set(),
|
||||
'area'
|
||||
);
|
||||
|
||||
expect(params.getAll('poiDistance')).toEqual([
|
||||
'Distance%20to%20nearest%20park%20(km):0:0.4',
|
||||
'Distance%20to%20nearest%20Tesco%20(km):0:1.5',
|
||||
]);
|
||||
expect(params.getAll('filter')).toEqual([]);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.filters).toEqual({
|
||||
[createPoiDistanceFilterKey('Distance to nearest park (km)', 0)]: [0, 0.4],
|
||||
[createPoiDistanceFilterKey('Distance to nearest Tesco (km)', 1)]: [0, 1.5],
|
||||
});
|
||||
});
|
||||
|
||||
it('round-trips POI count filters with dedicated URL params', () => {
|
||||
const cafes = createPoiFilterKey(
|
||||
POI_COUNT_2KM_FILTER_NAME,
|
||||
'Number of Cafe POIs within 2km',
|
||||
3
|
||||
);
|
||||
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{
|
||||
[cafes]: [2, 8],
|
||||
},
|
||||
[],
|
||||
new Set(),
|
||||
'area'
|
||||
);
|
||||
|
||||
expect(params.getAll('poiCount2km')).toEqual(['Number%20of%20Cafe%20POIs%20within%202km:2:8']);
|
||||
expect(params.getAll('filter')).toEqual([]);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.filters).toEqual({
|
||||
[createPoiFilterKey(POI_COUNT_2KM_FILTER_NAME, 'Number of Cafe POIs within 2km', 0)]: [2, 8],
|
||||
});
|
||||
});
|
||||
|
||||
it('omits the default area tab', () => {
|
||||
const params = stateToParams(null, {}, [], new Set(), 'area');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue