test: validate three-arm junction editing workflow

This commit is contained in:
que01 committed 2026-09-11 12:10:53 +08:00
1 parent f40caaa264
commit ff11dc2654
5 files changed
+121 -5

No files matched your search

+93
View File
@@ -398,4 +398,97 @@ test.describe('workbench editing shell', () => {
structure.arms.map((arm: { key: string }) => arm.key),
);
});
test('edits and persists every entry control on a three-arm complex junction', async ({ page }) => {
test.setTimeout(60_000);
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 && item.nodeIds.includes('-91001'),
);
expect(candidate).toBeTruthy();
const accepted = await page.request
.post('/api/junction-clusters', { data: { candidateId: candidate.id, nodeIds: candidate.nodeIds } })
.then((response) => response.json());
const id = accepted.added.id;
const structure = accepted.junctionStructures[`cluster:${id}`];
expect(structure.shape.effectiveArmCount).toBe(3);
await page.goto(`/junction/cluster/${encodeURIComponent(id)}`);
await page.reload();
const workspace = page.getByLabel('路口编辑工作区');
await page.waitForResponse((response) =>
response.url().includes(`/api/edit-state?cluster=${encodeURIComponent(id)}`),
);
const editStateResponse = page.waitForResponse((response) =>
response.url().includes(`/api/edit-state?cluster=${encodeURIComponent(id)}`),
);
await page.getByRole('button', { name: '开启编辑模式' }).click();
const scoped = await (await editStateResponse).json();
const baseline = await page.request
.post('/api/edit-preview', { data: { document: scoped.document, selection: { cluster: id } } })
.then((response) => response.json());
const geometry = (preview: typeof baseline, nativeId: string) =>
preview.layers.roadSurface.features.find(
(feature: { properties: { native_id: string } }) => feature.properties.native_id === nativeId,
)?.geometry;
let persistedHandleId = '';
let persistedValue = '';
for (const edit of [
{ kind: 'cluster-carriageway-position', label: '车行道接入位置', delta: 0.5 },
{ kind: 'cluster-carriageway-direction', label: '车行道接入方向', delta: 1 },
{ kind: 'cluster-carriageway-edge-offset', label: '车行道左右边界', delta: 0.25 },
{ kind: 'cluster-carriageway-transition-length', label: '车行道过渡长度', delta: -0.5 },
]) {
const handle = scoped.handles.handles.find(
(item: { kind: string; value: { current: number; min: number; max: number } }) =>
item.kind === edit.kind &&
item.value.current + edit.delta >= item.value.min &&
item.value.current + edit.delta <= item.value.max,
);
expect(handle).toBeTruthy();
const group = workspace.locator('.parameter-group').filter({ hasText: edit.label }).first();
const expand = group.getByRole('button', { name: '展开单独定制' });
if (await expand.count()) await expand.click();
const input = group.locator(`[data-handle-id="${handle.handleId}"] .parameter-input`);
const nextValue = String(Math.round((handle.value.current + edit.delta) * 100) / 100);
const response = page.waitForResponse(
(item) =>
item.url().endsWith('/api/edit-preview') &&
item
.request()
.postDataJSON()
?.constraints?.some((constraint: { kind: string }) => constraint.kind === edit.kind),
);
await input.fill(nextValue);
await input.press('Enter');
const preview = await (await response).json();
expect(preview.constraintStates.every((state: { applied: boolean }) => state.applied)).toBe(true);
expect(geometry(preview, handle.affects[0])).not.toEqual(geometry(baseline, handle.affects[0]));
if (edit.kind === 'cluster-carriageway-transition-length') {
persistedHandleId = handle.handleId;
persistedValue = nextValue;
} else {
await page.getByRole('button', { name: '撤销', exact: true }).click();
}
}
const saveRequest = page.waitForRequest(
(request) => request.method() === 'POST' && request.url().endsWith('/api/edits'),
);
await workspace.getByRole('button', { name: '保存', exact: true }).click();
const requestedVersion = (await saveRequest).postDataJSON().expectedDocumentVersion;
expect(requestedVersion).toBeLessThanOrEqual(scoped.documentVersion);
if (requestedVersion < scoped.documentVersion) {
await expect(page.getByRole('status')).toContainText(`保存冲突:文档已被改到版本 ${scoped.documentVersion}`);
await workspace.getByRole('button', { name: '保存', exact: true }).click();
}
await expect(page.getByRole('status')).toHaveText('已保存并重新生成', { timeout: 30_000 });
await page.reload();
const refreshedTransitionGroup = workspace.locator('.parameter-group').filter({ hasText: '车行道过渡长度' });
await expect(refreshedTransitionGroup).toBeVisible();
const expandTransition = refreshedTransitionGroup.getByRole('button', { name: '展开单独定制' });
await expect(expandTransition).toBeVisible();
await expandTransition.click();
await expect(
refreshedTransitionGroup.locator(`[data-handle-id="${persistedHandleId}"] .parameter-input`),
).toHaveValue(persistedValue);
});
});