good
This commit is contained in:
parent
c995f12f8b
commit
8dc939d761
44 changed files with 3540 additions and 2159478 deletions
|
|
@ -153,6 +153,27 @@ describe('url-state', () => {
|
|||
expect(state.poiCategories).toEqual(new Set());
|
||||
});
|
||||
|
||||
it('serializes a selected postcode for saved dashboard URLs', () => {
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
'SW1A 1AA'
|
||||
);
|
||||
|
||||
expect(params.get('pc')).toBe('SW1A 1AA');
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
expect(parseUrlState().postcode).toBe('SW1A 1AA');
|
||||
});
|
||||
|
||||
it('round-trips overlay selections', () => {
|
||||
const params = stateToParams(
|
||||
null,
|
||||
|
|
@ -197,6 +218,139 @@ describe('url-state', () => {
|
|||
expect(parseUrlState().basemap).toBe('standard');
|
||||
});
|
||||
|
||||
it('round-trips non-default colour opacity', () => {
|
||||
const defaultParams = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
1
|
||||
);
|
||||
expect(defaultParams.has('colorOpacity')).toBe(false);
|
||||
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
0.45
|
||||
);
|
||||
|
||||
expect(params.get('colorOpacity')).toBe('45');
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
expect(parseUrlState().colorOpacity).toBe(0.45);
|
||||
|
||||
window.history.replaceState({}, '', '/?colorOpacity=not-a-number');
|
||||
expect(parseUrlState().colorOpacity).toBe(1);
|
||||
|
||||
window.history.replaceState({}, '', '/?colorOpacity=0');
|
||||
expect(parseUrlState().colorOpacity).toBe(0.1);
|
||||
});
|
||||
|
||||
it('round-trips a crime-type subset when the crime overlay is active', () => {
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
new Set(['crime-hotspots']),
|
||||
undefined,
|
||||
new Set(['Burglary', 'Robbery'])
|
||||
);
|
||||
|
||||
expect(params.getAll('crimeType')).toEqual(['Burglary', 'Robbery']);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}&crimeType=NotAType`);
|
||||
expect(parseUrlState().crimeTypes).toEqual(new Set(['Burglary', 'Robbery']));
|
||||
});
|
||||
|
||||
it('omits crime types when all are selected or the crime overlay is off', () => {
|
||||
const allSelected = new Set([
|
||||
'Violence and sexual offences',
|
||||
'Anti-social behaviour',
|
||||
'Criminal damage and arson',
|
||||
'Public order',
|
||||
'Shoplifting',
|
||||
'Vehicle crime',
|
||||
'Burglary',
|
||||
'Other theft',
|
||||
'Theft from the person',
|
||||
'Bicycle theft',
|
||||
'Drugs',
|
||||
'Robbery',
|
||||
'Possession of weapons',
|
||||
'Other crime',
|
||||
]);
|
||||
const allParams = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
new Set(['crime-hotspots']),
|
||||
undefined,
|
||||
allSelected
|
||||
);
|
||||
expect(allParams.getAll('crimeType')).toEqual([]);
|
||||
|
||||
// Subset selected but the crime overlay is not active → nothing emitted.
|
||||
const overlayOffParams = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
new Set(['noise']),
|
||||
undefined,
|
||||
new Set(['Burglary'])
|
||||
);
|
||||
expect(overlayOffParams.getAll('crimeType')).toEqual([]);
|
||||
|
||||
expect(parseUrlState().crimeTypes).toBeUndefined();
|
||||
});
|
||||
|
||||
it('round-trips a fully-deselected crime-type state via sentinel', () => {
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
new Set(['crime-hotspots']),
|
||||
undefined,
|
||||
new Set()
|
||||
);
|
||||
|
||||
expect(params.getAll('crimeType')).toEqual(['__none']);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
expect(parseUrlState().crimeTypes).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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue