Files
osmWorkflow/scripts/test-road-workbench.js

81 lines
4.3 KiB
JavaScript

#!/usr/bin/env node
"use strict";
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const html = fs.readFileSync(path.join(__dirname, "workbench", "index.html"), "utf8");
assert.match(html, /id="width" type="number" min="1" step="0\.01"/);
assert.match(html, /data-layer="sidewalks" type="checkbox" checked> 路缘与步行带/);
assert.match(html, /id="scene-preview" type="checkbox"/);
assert.match(html, /id="selected-junction" hidden/);
const app = fs.readFileSync(path.join(__dirname, "workbench", "app.js"), "utf8");
assert.match(app, /async function saveStagedChanges\(\)/);
assert.match(app, /if \(!await saveStagedChanges\(\)\) return;/);
assert.match(app, /function stageRoadOverride\(road, changes\)/);
assert.match(app, /road\.segmentId === selectedRoad\.segmentId/);
assert.match(app, /sidewalkLeft: rightInput\.checked, sidewalkRight: leftInput\.checked/);
assert.match(app, /function nativeSurfaceStyle\(feature\)/);
assert.match(app, /reference: new VectorLayer\(\{ source: source\(\), visible: false/);
assert.match(app, /scene mode must render fills only/);
assert.match(app, /scenePreviewToggle\.onchange/);
assert.match(app, /layers\.sidewalks\.setVisible\(document\.querySelector\('\[data-layer="sidewalks"\]'\)\.checked\)/);
assert.match(app, /function selectJunction\(feature\)/);
assert.match(app, /candidate\.get\("native_id"\) === item\.subjectId/);
assert.match(app, /外缘扩张倍率/);
assert.match(app, /最大外缘扩张/);
assert.match(app, /道路方向箭头/);
assert.match(app, /native-road-direction-arrow\/v1/);
assert.match(app, /data-layer="centerLines" type="checkbox" checked> 道路中心线/);
assert.match(app, /centerLines: new VectorLayer/);
assert.match(app, /state\.layers\.centerLines/);
assert.match(app, /native-road-center-line\/v1/);
assert.match(app, /lane-separator-style/);
assert.match(app, /车道分隔线/);
assert.match(app, /center-line-style/);
assert.match(app, /centerLineStyleInput\.onchange = stageSelectedCenterLineStyle/);
assert.match(html, /道路中心线样式/);
assert.match(html, /white-solid/);
assert.match(app, /double-yellow-solid/);
assert.match(app, /const double = parts\[0\] === "double"/);
assert.match(app, /function selectEdgeLine\(feature\)/);
assert.match(app, /edge-line-style/);
assert.match(app, /道路外缘线样式/);
assert.match(app, /data-layer="edgeLines" type="checkbox"> 道路外缘线/);
assert.match(app, /edgeLines: new VectorLayer\(\{ source: source\(\), visible: false/);
assert.match(html, /id="marking-style-heading"/);
assert.match(app, /data-layer="controls" type="checkbox" checked> 斑马线与停止线/);
assert.match(app, /controls: new VectorLayer/);
assert.match(app, /state\.layers\.crosswalks/);
assert.match(app, /state\.layers\.vehicleStopLines/);
assert.match(app, /native-road-crosswalk\/v1/);
assert.match(app, /native-road-stop-line\/v1/);
assert.match(app, /term\.textContent = label; detail\.textContent = value; summary\.append\(term, detail\)/);
assert.match(app, /原生红绿灯/);
assert.match(app, /function selectSignal\(feature\)/);
assert.match(app, /\/api\/traffic-signals/);
assert.match(app, /从 OSM 生成缺失信号灯/);
assert.match(app, /data-layer="signals" type="checkbox" checked> 红绿灯设施/);
assert.match(app, /红绿灯设施/);
assert.match(app, /signalAssemblyStyle/);
assert.match(app, /signal_component: "mast"/);
assert.match(app, /signal_component: "face"/);
assert.match(app, /signal_component: "head"/);
assert.match(app, /faceHeadingDegrees/);
assert.match(app, /横杆方向(度)/);
assert.match(app, /横杆长度(米)/);
assert.match(app, /灯面朝向(度)/);
assert.match(app, /检查信号灯<select name="signal-picker">/);
assert.match(app, /signalPicker\.onchange/);
assert.match(app, /map\.getView\(\)\.fit\(\[x - 25, y - 25, x \+ 25, y \+ 25\]/);
assert.match(app, /fromLonLat/);
assert.match(app, /armFeatures\.push\(new Feature/);
assert.match(app, /headFeatures\.push\(new Feature/);
assert.match(app, /faceFeatures\.push\(new Feature/);
const server = fs.readFileSync(path.join(__dirname, "road-workbench.js"), "utf8");
assert.match(server, /\/api\/traffic-signals\/generate/);
assert.doesNotMatch(app, /导入 QGIS|导出 QGIS/);
assert.doesNotMatch(server, /traffic-signals\/(?:import|export)-qgis/);
console.log("road workbench tests passed");