feat(workbench): stabilize junction tools workspace
This commit is contained in:
1 parent
e6b822416d
commit
f10a5da325
22 files changed
+1078
-53
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { localJunctionPreview, localJunctionState } from './local-state';
|
||||
import type { JunctionDescriptor } from './hotspots';
|
||||
import type { WorkbenchState } from '../types/state';
|
||||
|
||||
const descriptor: JunctionDescriptor = {
|
||||
ref: { type: 'node', id: 'junction-1' },
|
||||
status: 'editable',
|
||||
coordinate: [120, 30],
|
||||
radiusMeters: 10,
|
||||
nodeIds: ['junction-1'],
|
||||
approachRoadIds: ['road-a'],
|
||||
diagnosticIds: [],
|
||||
source: 'junction-plan',
|
||||
};
|
||||
|
||||
const state = {
|
||||
areaId: 'test',
|
||||
compiled: {
|
||||
model: {
|
||||
roads: [
|
||||
{
|
||||
id: 'road-a',
|
||||
segmentId: 'segment-a',
|
||||
sourceNodeIds: ['junction-1', 'end-a'],
|
||||
centerline: [],
|
||||
osmWayIds: [],
|
||||
tags: {},
|
||||
highway: 'residential',
|
||||
direction: 'forward',
|
||||
widthMeters: 6,
|
||||
laneCount: 2,
|
||||
sidewalkLeft: false,
|
||||
sidewalkRight: false,
|
||||
},
|
||||
{
|
||||
id: 'road-b',
|
||||
segmentId: 'segment-b',
|
||||
sourceNodeIds: ['other', 'end-b'],
|
||||
centerline: [],
|
||||
osmWayIds: [],
|
||||
tags: {},
|
||||
highway: 'residential',
|
||||
direction: 'forward',
|
||||
widthMeters: 6,
|
||||
laneCount: 2,
|
||||
sidewalkLeft: false,
|
||||
sidewalkRight: false,
|
||||
},
|
||||
],
|
||||
endpoints: [
|
||||
{ id: 'endpoint-a', roadId: 'road-a', side: 'end', nodeId: 'junction-1', coordinate: [120, 30] },
|
||||
{ id: 'endpoint-b', roadId: 'road-b', side: 'end', nodeId: 'other', coordinate: [121, 31] },
|
||||
],
|
||||
connections: [{ id: 'connection-a', fromEndpointId: 'endpoint-a', toEndpointId: 'endpoint-a', enabled: true }],
|
||||
},
|
||||
movements: [],
|
||||
diagnostics: [],
|
||||
},
|
||||
layers: {
|
||||
nativeRoadSurface: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{ type: 'Feature', properties: { road_id: 'road-a' }, geometry: null },
|
||||
{ type: 'Feature', properties: { road_id: 'road-b' }, geometry: null },
|
||||
],
|
||||
},
|
||||
crosswalks: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{ type: 'Feature', properties: { crossing_node_id: 'junction-1' }, geometry: null },
|
||||
{ type: 'Feature', properties: { crossing_node_id: 'other' }, geometry: null },
|
||||
],
|
||||
},
|
||||
},
|
||||
overrides: { schema: 'test', overrides: [] },
|
||||
trafficSignals: { provenance: 'test', assemblies: { type: 'FeatureCollection', features: [] } },
|
||||
trafficRuntime: { signals: [] },
|
||||
comparison: {},
|
||||
} as unknown as WorkbenchState;
|
||||
|
||||
describe('local junction state', () => {
|
||||
it('keeps only the selected junction roads and related features', () => {
|
||||
const local = localJunctionState(state, descriptor);
|
||||
expect(local.compiled.model.roads.map((road) => road.id)).toEqual(['road-a']);
|
||||
expect(local.layers.nativeRoadSurface?.features).toHaveLength(1);
|
||||
expect(local.layers.crosswalks?.features).toHaveLength(1);
|
||||
expect(local.compiled.model.endpoints.map((endpoint) => endpoint.id)).toEqual(['endpoint-a']);
|
||||
});
|
||||
|
||||
it('scopes preview collections to the selected junction', () => {
|
||||
const preview = localJunctionPreview(
|
||||
{
|
||||
roadSurface: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{ type: 'Feature', properties: { road_id: 'road-a' }, geometry: null },
|
||||
{ type: 'Feature', properties: { road_id: 'road-b' }, geometry: null },
|
||||
],
|
||||
},
|
||||
crosswalks: {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{ type: 'Feature', properties: { crossing_node_id: 'junction-1' }, geometry: null },
|
||||
{ type: 'Feature', properties: { crossing_node_id: 'other' }, geometry: null },
|
||||
],
|
||||
},
|
||||
},
|
||||
descriptor,
|
||||
state.compiled.model.roads,
|
||||
);
|
||||
expect(preview?.roadSurface?.features).toHaveLength(1);
|
||||
expect(preview?.crosswalks?.features).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user