feat(junction): establish stable complex junction structure

This commit is contained in:
que01 committed 2026-09-08 11:25:57 +08:00
1 parent bd8b55e58b
commit 0a5a229ce3
22 files changed
+1386 -125

No files matched your search

+60
View File
@@ -1,6 +1,9 @@
import fs from 'node:fs';
import { expect, test } from '@playwright/test';
import { strFromU8, unzipSync } from 'fflate';
import type OLMap from 'ol/Map';
import type VectorLayer from 'ol/layer/Vector';
import type VectorSource from 'ol/source/Vector';
test.describe('workbench editing shell', () => {
test.beforeEach(async ({ page }) => {
@@ -194,4 +197,61 @@ test.describe('workbench editing shell', () => {
await page.getByRole('button', { name: '放弃草稿' }).click();
await expect(heading).toHaveValue(original);
});
test('keeps complex junction structure and map selection linked across reload', async ({ page }) => {
const initial = await page.request.get('/api/state').then((response) => response.json());
const candidate = initial.debug.junctionCandidates.find((item: { nodeIds: string[] }) => item.nodeIds.length >= 3);
expect(candidate).toBeTruthy();
const acceptedResponse = await page.request.post('/api/junction-clusters', {
data: { candidateId: candidate.id, nodeIds: candidate.nodeIds },
});
expect(acceptedResponse.ok()).toBe(true);
const accepted = await acceptedResponse.json();
const id = accepted.added.id;
const structure = accepted.junctionStructures[`cluster:${id}`];
expect(structure.arms.length).toBeGreaterThanOrEqual(3);
await page.goto(`/junction/cluster/${encodeURIComponent(id)}`);
const workspace = page.getByLabel('路口编辑工作区');
await expect(workspace).toBeVisible();
const armButtons = workspace.locator('.junction-workspace__object-list').first().getByRole('button');
await expect(armButtons).toHaveCount(structure.arms.length);
const map = await page
.getByLabel('道路地图')
.evaluateHandle((element) => (element as HTMLDivElement & { __roadWorkbenchMap: OLMap }).__roadWorkbenchMap);
await armButtons.first().click();
await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'true');
await expect
.poll(async () =>
page.getByLabel('道路地图').evaluate((element) => {
const map = (element as HTMLDivElement & { __roadWorkbenchMap: OLMap }).__roadWorkbenchMap;
const layer = map
.getLayers()
.getArray()
.find((item) => item.getZIndex() === 89) as VectorLayer<VectorSource> | undefined;
return layer?.getSource()?.getFeatures().length || 0;
}),
)
.toBeGreaterThan(0);
const sameMap = await page
.getByLabel('道路地图')
.evaluate(
(element, original) =>
(element as HTMLDivElement & { __roadWorkbenchMap: OLMap }).__roadWorkbenchMap === original,
map,
);
expect(sameMap).toBe(true);
await expect(workspace.getByText('路口参数', { exact: true })).toHaveCount(0);
const scoped = await page.request
.get(`/api/edit-state?cluster=${encodeURIComponent(id)}`)
.then((response) => response.json());
expect(scoped.handles.handles).toEqual([]);
expect(scoped.junctionStructure.topologyFingerprint).toBe(structure.topologyFingerprint);
await page.reload();
await expect(armButtons).toHaveCount(structure.arms.length);
await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'false');
const refreshed = await page.request.get('/api/state').then((response) => response.json());
expect(refreshed.junctionStructures[`cluster:${id}`].arms.map((arm: { key: string }) => arm.key)).toEqual(
structure.arms.map((arm: { key: string }) => arm.key),
);
});
});