99 lines
2.5 KiB
TypeScript
99 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { EditHandle } from '../edit/types';
|
|
import type { Road } from '../types/state';
|
|
import { junctionLabelForHandle } from './labels';
|
|
|
|
const roads = [
|
|
{
|
|
id: 'road-north',
|
|
segmentId: 'segment:way/-3254/0',
|
|
centerline: [
|
|
[120, 30],
|
|
[120, 30.001],
|
|
],
|
|
sourceNodeIds: ['junction'],
|
|
osmWayIds: [],
|
|
tags: { name: '创新大道' },
|
|
highway: 'primary',
|
|
direction: 'forward',
|
|
widthMeters: 7,
|
|
laneCount: 2,
|
|
sidewalkLeft: false,
|
|
sidewalkRight: false,
|
|
},
|
|
{
|
|
id: 'road-east',
|
|
segmentId: 'segment:way/-3255/0',
|
|
centerline: [
|
|
[120, 30],
|
|
[120.001, 30],
|
|
],
|
|
sourceNodeIds: ['junction'],
|
|
osmWayIds: [],
|
|
tags: {},
|
|
highway: 'residential',
|
|
direction: 'forward',
|
|
widthMeters: 6,
|
|
laneCount: 2,
|
|
sidewalkLeft: false,
|
|
sidewalkRight: false,
|
|
},
|
|
] as const;
|
|
|
|
function handle(anchor: EditHandle['anchor'], kind: EditHandle['kind']): EditHandle {
|
|
return {
|
|
handleId: 'h',
|
|
kind,
|
|
anchor,
|
|
position: [120, 30],
|
|
axisAzimuth: 0,
|
|
value: { current: 3, min: 1, max: 8, unit: 'meter' },
|
|
affects: [],
|
|
editable: true,
|
|
};
|
|
}
|
|
|
|
describe('junction handle labels', () => {
|
|
it('uses road name and geographic approach direction', () => {
|
|
expect(
|
|
junctionLabelForHandle(
|
|
handle(
|
|
{ type: 'junction-approach', nodeId: 'junction', segmentId: roads[0].segmentId },
|
|
'junction-approach-width',
|
|
),
|
|
roads as unknown as Road[],
|
|
[120, 30],
|
|
),
|
|
).toBe('创新大道 · 北进口 · 进口宽度');
|
|
});
|
|
|
|
it('uses a readable fallback when a road has no name', () => {
|
|
expect(
|
|
junctionLabelForHandle(
|
|
handle({ type: 'junction-approach', nodeId: 'junction', segmentId: roads[1].segmentId }, 'junction-cutback'),
|
|
roads as unknown as Road[],
|
|
[120, 30],
|
|
),
|
|
).toBe('道路2 · 东进口 · 进口收口距离');
|
|
});
|
|
|
|
it('names a complex carriageway by its source road', () => {
|
|
expect(
|
|
junctionLabelForHandle(
|
|
handle(
|
|
{
|
|
type: 'cluster-carriageway',
|
|
clusterId: 'cluster-1',
|
|
carriagewayKey: 'cluster:cluster-1:carriageway:stable',
|
|
sourceNodeIds: ['junction'],
|
|
sourceRoadIds: ['road-north'],
|
|
},
|
|
'cluster-carriageway-width',
|
|
),
|
|
roads as unknown as Road[],
|
|
[120, 30],
|
|
),
|
|
).toBe('创新大道 · 北进口 · 车行道宽度');
|
|
});
|
|
});
|