test(workbench): add browser regression coverage

This commit is contained in:
que01 committed 2026-09-02 17:39:25 +08:00
1 parent 2fb9db65e5
commit fcb07b8396
6 files changed
+230 -1

No files matched your search

+65 -1
View File
@@ -18,12 +18,13 @@
"road-compiler": "bin/road-compiler.js" "road-compiler": "bin/road-compiler.js"
}, },
"devDependencies": { "devDependencies": {
"@playwright/test": "^1.62.1",
"@types/react": "^19.0.8", "@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3", "@types/react-dom": "^19.0.3",
"prettier": "^3.9.6", "prettier": "^3.9.6",
"typescript": "^5.7.3", "typescript": "^5.7.3",
"vite": "^6.1.0", "vite": "^6.1.0",
"vitest": "^4.1.11" "vitest": "4.1.11"
} }
}, },
"node_modules/@esbuild/aix-ppc64": { "node_modules/@esbuild/aix-ppc64": {
@@ -481,6 +482,22 @@
"integrity": "sha512-8awtpHXCx/bNpFt4mt2xdkgtgVvKqty8VbjHI/WWWQuEw+KLzFot3f4+LkQY9YmOtq7A5GdOnqoIC8Pdygjk2g==", "integrity": "sha512-8awtpHXCx/bNpFt4mt2xdkgtgVvKqty8VbjHI/WWWQuEw+KLzFot3f4+LkQY9YmOtq7A5GdOnqoIC8Pdygjk2g==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@playwright/test": {
"version": "1.62.1",
"resolved": "http://172.16.1.86:4873/@playwright/test/-/test-1.62.1.tgz",
"integrity": "sha512-DTcUc8qii+cpHvtOwggMtBRMjKZHXYWdw8syRYu2vtzuq4Wxphqq4NfCs5Zt44L6mA8rfDfj+PHnxFc/FeK6mQ==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright": "1.62.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/@rollup/rollup-android-arm-eabi": { "node_modules/@rollup/rollup-android-arm-eabi": {
"version": "4.63.0", "version": "4.63.0",
"resolved": "http://172.16.1.86:4873/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.63.0.tgz", "resolved": "http://172.16.1.86:4873/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.63.0.tgz",
@@ -1324,6 +1341,53 @@
"url": "https://github.com/sponsors/jonschlinkert" "url": "https://github.com/sponsors/jonschlinkert"
} }
}, },
"node_modules/playwright": {
"version": "1.62.1",
"resolved": "http://172.16.1.86:4873/playwright/-/playwright-1.62.1.tgz",
"integrity": "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.62.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=20"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/playwright-core": {
"version": "1.62.1",
"resolved": "http://172.16.1.86:4873/playwright-core/-/playwright-core-1.62.1.tgz",
"integrity": "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/playwright/node_modules/fsevents": {
"version": "2.3.2",
"resolved": "http://172.16.1.86:4873/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/postcss": { "node_modules/postcss": {
"version": "8.5.26", "version": "8.5.26",
"resolved": "http://172.16.1.86:4873/postcss/-/postcss-8.5.26.tgz", "resolved": "http://172.16.1.86:4873/postcss/-/postcss-8.5.26.tgz",
+2
View File
@@ -16,6 +16,7 @@
"dev": "vite --config workbench/client/vite.config.ts", "dev": "vite --config workbench/client/vite.config.ts",
"test:client": "tsc --noEmit -p workbench/client/tsconfig.json", "test:client": "tsc --noEmit -p workbench/client/tsconfig.json",
"test:client:unit": "vitest run --passWithNoTests", "test:client:unit": "vitest run --passWithNoTests",
"test:e2e": "npm run build && playwright test",
"format": "prettier --write \"{src,bin,test,workbench}/**/*.{js,ts,tsx,css,html}\" \"*.{json,js,ts}\"", "format": "prettier --write \"{src,bin,test,workbench}/**/*.{js,ts,tsx,css,html}\" \"*.{json,js,ts}\"",
"format:check": "prettier --check \"{src,bin,test,workbench}/**/*.{js,ts,tsx,css,html}\" \"*.{json,js,ts}\"" "format:check": "prettier --check \"{src,bin,test,workbench}/**/*.{js,ts,tsx,css,html}\" \"*.{json,js,ts}\""
}, },
@@ -27,6 +28,7 @@
"react-dom": "^19.1.0" "react-dom": "^19.1.0"
}, },
"devDependencies": { "devDependencies": {
"@playwright/test": "^1.62.1",
"@types/react": "^19.0.8", "@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3", "@types/react-dom": "^19.0.3",
"prettier": "^3.9.6", "prettier": "^3.9.6",
+41
View File
@@ -0,0 +1,41 @@
import { defineConfig, devices } from '@playwright/test';
import fs from 'node:fs';
import path from 'node:path';
function cachedChromium() {
if (process.env.PLAYWRIGHT_EXECUTABLE_PATH) return process.env.PLAYWRIGHT_EXECUTABLE_PATH;
const cache =
process.env.PLAYWRIGHT_BROWSERS_PATH || path.join(process.env.HOME || '', 'Library/Caches/ms-playwright');
if (!fs.existsSync(cache)) return undefined;
const candidates = fs
.readdirSync(cache)
.filter((name) => name.startsWith('chromium_headless_shell-'))
.sort()
.reverse()
.map((name) => path.join(cache, name, 'chrome-headless-shell-mac-x64', 'chrome-headless-shell'));
return candidates.find((candidate) => fs.existsSync(candidate));
}
export default defineConfig({
testDir: './test/e2e',
fullyParallel: false,
forbidOnly: Boolean(process.env.CI),
reporter: process.env.CI ? 'line' : 'list',
use: {
baseURL: 'http://127.0.0.1:8899',
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
},
webServer: {
command: 'node test/e2e-server.js',
url: 'http://127.0.0.1:8899/',
reuseExistingServer: !process.env.CI,
timeout: 30_000,
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], launchOptions: { executablePath: cachedChromium() } },
},
],
});
+32
View File
@@ -0,0 +1,32 @@
'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');
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 input = {
areaId: 'e2e-fengshu-er-road',
osmFile,
outDir: path.join(root, 'native-road'),
stagingDir: path.join(root, 'pipeline'),
overridesFile: path.join(root, 'native-road-overrides.json'),
trafficSignalsFile: path.join(root, 'native-traffic-signals.json'),
options: { edgeLines: false, junctionTemplates: { enabled: false, references: [] } },
};
fs.writeFileSync(input.overridesFile, JSON.stringify({ schema: 'native-road-overrides/v1', overrides: [] }));
fs.writeFileSync(
input.trafficSignalsFile,
fs.readFileSync(path.join(__dirname, '..', 'outputs', 'fengshu-er-road', 'native-traffic-signals.json')),
);
const server = startWorkbench({ input, repoRoot: path.resolve(__dirname, '..'), dataRoot: root, port: 8899 });
const cleanup = () => {
server.close(() => fs.rmSync(root, { recursive: true, force: true }));
};
process.once('SIGINT', cleanup);
process.once('SIGTERM', cleanup);
+86
View File
@@ -0,0 +1,86 @@
import { expect, test } from '@playwright/test';
test.describe('workbench editing shell', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await expect(page.getByText('道路编译工作台', { exact: true })).toBeVisible();
});
test('starts in browse mode and persists the edit switch', async ({ page }) => {
const mode = page.getByRole('switch', { name: '编辑模式' });
await expect(mode).not.toBeChecked();
await expect(page.getByRole('button', { name: '放弃' })).toHaveCount(0);
await mode.check();
await expect(mode).toBeChecked();
await expect(page.getByRole('button', { name: '放弃' })).toBeVisible();
await page.reload();
await expect(page.getByRole('switch', { name: '编辑模式' })).toBeChecked();
});
test('keeps the map mounted while compiling the current edits', async ({ page }) => {
const map = page.getByLabel('道路地图');
await expect(map).toBeVisible();
const canvasCount = await map.locator('canvas').count();
expect(canvasCount).toBeGreaterThan(0);
await page.getByRole('button', { name: '保存并重新生成' }).click();
await expect(page.getByText('已保存并重新生成')).toBeVisible({ timeout: 30_000 });
await expect(map).toBeVisible();
await expect(map.locator('canvas')).toHaveCount(canvasCount);
});
test('supports layer visibility and inspector accordion state', async ({ page }) => {
const roads = page.getByLabel('自研道路与路口面');
await expect(roads).toBeChecked();
await roads.uncheck();
await expect(roads).not.toBeChecked();
await roads.check();
const issues = page.getByText(/待检查问题(/).locator('..');
await expect(issues).not.toHaveAttribute('open', '');
await issues.locator('summary').click();
await expect(issues).toHaveAttribute('open', '');
await issues.locator('summary').click();
await expect(issues).not.toHaveAttribute('open', '');
const overview = page.getByText('当前编译概览').locator('..');
await overview.locator('summary').click();
await expect(overview).toHaveAttribute('open', '');
});
test('edits a signal field and can discard the draft', async ({ page }) => {
await page.getByRole('switch', { name: '编辑模式' }).check();
await page.getByText('元素', { exact: true }).click();
const signalSelect = page.getByLabel('检查信号灯');
await expect(signalSelect.locator('option')).not.toHaveCount(1);
await signalSelect.selectOption({ index: 1 });
const heading = page.getByLabel('横杆方向(度)');
const original = await heading.inputValue();
await heading.fill(String((Number(original) + 15) % 360));
await expect(page.getByText('未保存修改 0 项')).toHaveCount(0);
await expect(page.getByRole('button', { name: '放弃' })).toBeEnabled();
await page.getByRole('button', { name: '放弃' }).click();
await expect(page.getByRole('button', { name: '放弃' })).toBeDisabled();
await expect(heading).toHaveValue(original);
});
test('sends the compile request through the browser workflow', async ({ page }) => {
const compile = page.waitForRequest(
(request) => request.method() === 'POST' && request.url().endsWith('/api/compile'),
);
await page.getByRole('button', { name: '保存并重新生成' }).click();
await compile;
await expect(page.getByText('已保存并重新生成')).toBeVisible({ timeout: 30_000 });
});
test('exposes the edit-only history controls without changing browse controls', async ({ page }) => {
await expect(page.getByRole('button', { name: '撤销' })).toHaveCount(0);
await page.getByRole('switch', { name: '编辑模式' }).check();
await expect(page.getByRole('button', { name: '撤销' })).toBeVisible();
await expect(page.getByRole('button', { name: '重做' })).toBeVisible();
await expect(page.getByRole('button', { name: '放弃' })).toBeVisible();
await page.getByRole('switch', { name: '编辑模式' }).uncheck();
await expect(page.getByRole('button', { name: '撤销' })).toHaveCount(0);
});
});
@@ -238,6 +238,9 @@ export function MapCanvas({
view: new View({ center: [0, 0], zoom: 2 }), view: new View({ center: [0, 0], zoom: 2 }),
}); });
mapRef.current = map; mapRef.current = map;
// Non-visual probe for browser regression tests; production interactions still
// go through OpenLayers and the normal pointer handlers below.
(target.current as HTMLDivElement & { __roadWorkbenchMap?: Map }).__roadWorkbenchMap = map;
const select = new Select({ const select = new Select({
condition: click, condition: click,
// Handles are not selectable features: clicking one must not re-target the // Handles are not selectable features: clicking one must not re-target the
@@ -396,6 +399,7 @@ export function MapCanvas({
return () => { return () => {
select.un('select', listener); select.un('select', listener);
map.setTarget(undefined); map.setTarget(undefined);
delete (target.current as HTMLDivElement & { __roadWorkbenchMap?: Map })?.__roadWorkbenchMap;
}; };
// Map construction must be once per mounted canvas; state changes update sources below. // Map construction must be once per mounted canvas; state changes update sources below.
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps