test(workbench): add browser regression coverage
This commit is contained in:
1 parent
2fb9db65e5
commit
fcb07b8396
6 files changed
+230
-1
No files matched your search
@@ -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);
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user