test: validate three-arm junction editing workflow
This commit is contained in:
1 parent
f40caaa264
commit
ff11dc2654
5 files changed
+121
-5
No files matched your search
+15
-1
@@ -8,7 +8,21 @@ const { startWorkbench } = require('../workbench/server');
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'road-compiler-e2e-'));
|
||||
const source = path.join(__dirname, 'fixtures', 'fengshu-er-road.osm');
|
||||
const osmFile = path.join(root, 'source.osm');
|
||||
fs.copyFileSync(source, osmFile);
|
||||
const sourceXml = fs.readFileSync(source, 'utf8');
|
||||
const threeArmFixture = `
|
||||
<node id="-91001" lat="30.470000" lon="114.110000" />
|
||||
<node id="-91002" lat="30.470000" lon="114.110100" />
|
||||
<node id="-91003" lat="30.470086" lon="114.110050" />
|
||||
<node id="-91011" lat="30.469600" lon="114.109600" />
|
||||
<node id="-91012" lat="30.469600" lon="114.110500" />
|
||||
<node id="-91013" lat="30.470550" lon="114.110050" />
|
||||
<way id="-91101"><nd ref="-91001"/><nd ref="-91002"/><tag k="highway" v="secondary"/></way>
|
||||
<way id="-91102"><nd ref="-91002"/><nd ref="-91003"/><tag k="highway" v="secondary"/></way>
|
||||
<way id="-91103"><nd ref="-91003"/><nd ref="-91001"/><tag k="highway" v="secondary"/></way>
|
||||
<way id="-91111"><nd ref="-91011"/><nd ref="-91001"/><tag k="highway" v="secondary"/></way>
|
||||
<way id="-91112"><nd ref="-91012"/><nd ref="-91002"/><tag k="highway" v="secondary"/></way>
|
||||
<way id="-91113"><nd ref="-91013"/><nd ref="-91003"/><tag k="highway" v="secondary"/></way>`;
|
||||
fs.writeFileSync(osmFile, sourceXml.replace('</osm>', `${threeArmFixture}\n</osm>`));
|
||||
const input = {
|
||||
areaId: 'e2e-fengshu-er-road',
|
||||
osmFile,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user