these too
This commit is contained in:
parent
d4dde21ad2
commit
90c47afe17
11 changed files with 1045 additions and 0 deletions
87
frontend/src/lib/url-state.test.ts
Normal file
87
frontend/src/lib/url-state.test.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import type { FeatureMeta } from '../types';
|
||||
import { parseUrlState, stateToParams } from './url-state';
|
||||
|
||||
describe('url-state', () => {
|
||||
beforeEach(() => {
|
||||
window.history.replaceState({}, '', '/');
|
||||
});
|
||||
|
||||
it('parses view, filters, POIs, tab, postcode, and travel-time params', () => {
|
||||
window.history.replaceState(
|
||||
{},
|
||||
'',
|
||||
'/?lat=51.5074&lon=-0.1278&zoom=12.5&filter=Last%20known%20price:100000:500000&filter=Property%20type:Flat|House&poi=supermarket&tab=properties&pc=SW1A%201AA&tt=transit:kings-cross:Kings%20Cross:b:0:30'
|
||||
);
|
||||
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.viewState).toEqual({
|
||||
latitude: 51.5074,
|
||||
longitude: -0.1278,
|
||||
zoom: 12.5,
|
||||
pitch: 0,
|
||||
});
|
||||
expect(state.filters).toEqual({
|
||||
'Last known price': [100000, 500000],
|
||||
'Property type': ['Flat', 'House'],
|
||||
});
|
||||
expect(state.poiCategories).toEqual(new Set(['supermarket']));
|
||||
expect(state.tab).toBe('properties');
|
||||
expect(state.postcode).toBe('SW1A 1AA');
|
||||
expect(state.travelTime?.entries).toEqual([
|
||||
{
|
||||
mode: 'transit',
|
||||
slug: 'kings-cross',
|
||||
label: 'Kings Cross',
|
||||
timeRange: [0, 30],
|
||||
useBest: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('serializes map state and active filters into stable URL params', () => {
|
||||
const features: FeatureMeta[] = [
|
||||
{ name: 'Last known price', type: 'numeric' },
|
||||
{ name: 'Property type', type: 'enum', values: ['Flat', 'House'] },
|
||||
];
|
||||
|
||||
const params = stateToParams(
|
||||
{ latitude: 51.50742, longitude: -0.12781, zoom: 12.47 },
|
||||
{
|
||||
'Last known price': [100000, 500000],
|
||||
'Property type': ['Flat', 'House'],
|
||||
},
|
||||
features,
|
||||
new Set(['supermarket']),
|
||||
'properties',
|
||||
[
|
||||
{
|
||||
mode: 'bicycle',
|
||||
slug: 'bank',
|
||||
label: 'Bank',
|
||||
useBest: false,
|
||||
timeRange: [5, 25],
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
expect(params.get('lat')).toBe('51.5074');
|
||||
expect(params.get('lon')).toBe('-0.1278');
|
||||
expect(params.get('zoom')).toBe('12.5');
|
||||
expect(params.getAll('filter')).toEqual([
|
||||
'Last known price:100000:500000',
|
||||
'Property type:Flat|House',
|
||||
]);
|
||||
expect(params.getAll('poi')).toEqual(['supermarket']);
|
||||
expect(params.get('tab')).toBe('properties');
|
||||
expect(params.getAll('tt')).toEqual(['bicycle:bank:Bank:5:25']);
|
||||
});
|
||||
|
||||
it('omits the default area tab', () => {
|
||||
const params = stateToParams(null, {}, [], new Set(), 'area');
|
||||
|
||||
expect(params.has('tab')).toBe(false);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue