import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; import path from 'node:path'; import test from 'node:test'; const root = path.resolve(import.meta.dirname, '..'); async function read(relativePath) { return fs.readFile(path.join(root, relativePath), 'utf8'); } test('route editor entry point, dialog and forms are present', async () => { const html = await read('public/index.html'); const css = await read('public/css/editor.css'); const ui = await read('public/js/editor-ui.js'); assert.match(html, /id="editor-button"/); assert.match(html, /aria-label="Streckeneditor öffnen"/); assert.match(html, /]+accept="audio\/\*"/); assert.match(html, /id="editor-poi-images"[^>]+accept="image\/\*"[^>]+multiple/); assert.match(html, /Neue Strecken bleiben unveröffentlicht/); assert.match(css, /\.editor-entry-panel/); assert.match(css, /\.editor-dialog/); assert.match(css, /\.editor-poi-list/); assert.match(ui, /pointerup/); assert.doesNotMatch(ui, /addEventListener\(['"]click['"]/); }); test('route editor references all static editor classes for the project markup checks', async () => { const html = await read('public/index.html'); const ui = await read('public/js/editor-ui.js'); const classNames = [...html.matchAll(/class="([^"]*\beditor-[^"]*)"/g)] .flatMap(match => match[1].split(/\s+/)) .filter(name => name.startsWith('editor-')); for (const className of new Set(classNames)) { assert.match(ui, new RegExp(className), `editor class is not referenced by editor-ui.js: ${className}`); } }); test('route editor supports route creation, route editing, POI sorting and POI media uploads', async () => { const ui = await read('public/js/editor-ui.js'); assert.match(ui, /readJson\('\/routes'\)/); assert.match(ui, /readJson\(`\/routes\/\$\{encodeURIComponent\(id\)\}`\)/); assert.match(ui, /const method = id \? 'PUT' : 'POST'/); assert.match(ui, /const method = currentPoiId \? 'PUT' : 'POST'/); assert.match(ui, /move-poi-up/); assert.match(ui, /move-poi-down/); assert.match(ui, /sortOrder: index/); assert.match(ui, /uploadPoiMedia/); assert.match(ui, /\/audio`/); assert.match(ui, /\/images`/); });