Internationalization
This commit is contained in:
+42
-20
@@ -1,3 +1,5 @@
|
||||
import { readAppFile } from '../test-support/i18n.js';
|
||||
import { loadI18n } from '../test-support/i18n.js';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
@@ -7,7 +9,7 @@ import vm from 'node:vm';
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
|
||||
async function read(relativePath) {
|
||||
return fs.readFile(path.join(root, relativePath), 'utf8');
|
||||
return readAppFile(relativePath);
|
||||
}
|
||||
|
||||
function tick() {
|
||||
@@ -19,7 +21,7 @@ test('editor markup and source describe local draft creation instead of immediat
|
||||
const css = await read('public/css/editor.css');
|
||||
const ui = await read('public/js/editor-ui.js');
|
||||
|
||||
assert.match(html, /id="editor-button"[^>]+aria-label="Strecken verwalten"/);
|
||||
assert.match(html, /id="editor-button"[^>]+aria-label="Strecken bearbeiten"/);
|
||||
assert.match(html, /id="route-control-button"[\s\S]*?<img[^>]+src="images\/icons\/route-management\.svg"[^>]+alt=""[^>]*>/);
|
||||
assert.doesNotMatch(html, /class="editor-button-icon"/);
|
||||
assert.match(html, /<dialog id="editor-dialog"/);
|
||||
@@ -36,11 +38,11 @@ test('editor markup and source describe local draft creation instead of immediat
|
||||
assert.doesNotMatch(html, /id="editor-poi-(?:lat|lon)"[^>]+step=/);
|
||||
assert.match(html, /id="editor-poi-media-preview"/);
|
||||
assert.match(html, /id="editor-poi-delete"[^>]+editor-danger-button/);
|
||||
assert.match(html, />Streckenpunkte<\/h3>/);
|
||||
assert.match(html, /aria-label="Streckenpunkt hinzufügen"/);
|
||||
assert.match(html, />Stationen<\/h3>/);
|
||||
assert.match(html, /aria-label="Station hinzufügen"/);
|
||||
assert.match(html, /id="editor-route-upload"[^>]+type="button"[^>]+hidden/);
|
||||
assert.doesNotMatch(html, /accept="video\//);
|
||||
assert.match(html, /ausschließlich in diesem Browser/i);
|
||||
assert.match(html, /auf diesem Gerät/i);
|
||||
await fs.access(path.join(root, 'public/images/icons/route-management.svg'));
|
||||
|
||||
assert.match(css, /\.editor-dialog/);
|
||||
@@ -359,11 +361,15 @@ function buildEditorContext() {
|
||||
return { calls, context, elements, packages, saves, storedMediaCalls };
|
||||
}
|
||||
|
||||
test('public editor workflow saves new route and GPX Streckenpunkt locally without POSTing a route', async () => {
|
||||
test('public editor workflow saves new route and GPX Station locally without POSTing a route', async () => {
|
||||
const sourcePath = path.join(root, 'public/js/editor-ui.js');
|
||||
const source = await fs.readFile(sourcePath, 'utf8');
|
||||
const { calls, context, elements, packages, saves } = buildEditorContext();
|
||||
|
||||
await loadI18n(context);
|
||||
|
||||
vm.runInNewContext(await fs.readFile(path.join(root, 'public/js/user-messages.js'), 'utf8'), context, { filename: path.join(root, 'public/js/user-messages.js') });
|
||||
await loadI18n(context);
|
||||
vm.runInNewContext(source, context, { filename: sourcePath });
|
||||
|
||||
await context.Wegwichtel.EditorUi.open();
|
||||
@@ -382,8 +388,8 @@ test('public editor workflow saves new route and GPX Streckenpunkt locally witho
|
||||
assert.ok(packages.has('local-new'));
|
||||
assert.equal(saves.at(-1).route.name, 'Neue lokale Strecke');
|
||||
assert.equal(calls.some(call => call.method === 'POST' && call.url === '/api/routes'), false);
|
||||
assert.match(elements.get('editor-route-activated').textContent, /Lokaler Entwurf/);
|
||||
assert.equal(elements.get('editor-status').textContent, 'Speichern erfolgreich.');
|
||||
assert.match(elements.get('editor-route-activated').textContent, /Dieser Entwurf bleibt auf deinem Gerät/);
|
||||
assert.equal(elements.get('editor-status').textContent, 'Gespeichert.');
|
||||
assert.equal(elements.get('editor-route-upload').hidden, false);
|
||||
assert.equal(elements.get('editor-route-upload').disabled, false);
|
||||
assert.equal(elements.get('editor-route-gpx-group').hidden, true);
|
||||
@@ -399,7 +405,7 @@ test('public editor workflow saves new route and GPX Streckenpunkt locally witho
|
||||
assert.equal(elements.get('editor-poi-lon').value, '10.987654321');
|
||||
assert.equal(elements.get('editor-poi-radius').value, '4.321');
|
||||
elements.get('editor-poi-title').value = 'Aussicht';
|
||||
elements.get('editor-poi-description').value = 'Text zum Streckenpunkt';
|
||||
elements.get('editor-poi-description').value = 'Text zum Station';
|
||||
elements.get('editor-poi-audio').files = [{ name: 'aussicht.mp3', size: 5, type: 'audio/mpeg' }];
|
||||
elements.get('editor-poi-audio').dispatchEvent(new Event('change'));
|
||||
elements.get('editor-poi-images').files = [{ name: 'aussicht.jpg', size: 7, type: 'image/jpeg' }];
|
||||
@@ -447,8 +453,8 @@ test('public editor workflow saves new route and GPX Streckenpunkt locally witho
|
||||
assert.equal(local.route.serverRouteId, '22');
|
||||
assert.ok(local.route.uploadedAt);
|
||||
assert.equal(elements.get('editor-route-upload').disabled, true);
|
||||
assert.equal(elements.get('editor-route-upload').textContent, 'Bereits übertragen');
|
||||
assert.equal(elements.get('editor-status').textContent, 'Upload erfolgreich.');
|
||||
assert.equal(elements.get('editor-route-upload').textContent, 'Schon zur Prüfung gesendet');
|
||||
assert.equal(elements.get('editor-status').textContent, 'Zur Prüfung gesendet.');
|
||||
|
||||
const poiList = elements.get('editor-poi-list');
|
||||
const poiItem = poiList.children.find(child => child.dataset.poiId);
|
||||
@@ -488,11 +494,15 @@ test('public editor workflow saves new route and GPX Streckenpunkt locally witho
|
||||
assert.equal(elements.get('editor-button').attributes.get('aria-expanded'), 'false');
|
||||
});
|
||||
|
||||
test('local Streckenpunkt ids start at zero and increment from the highest existing id', async () => {
|
||||
test('local Station ids start at zero and increment from the highest existing id', async () => {
|
||||
const sourcePath = path.join(root, 'public/js/editor-ui.js');
|
||||
const source = await fs.readFile(sourcePath, 'utf8');
|
||||
const { context, elements, packages } = buildEditorContext();
|
||||
|
||||
await loadI18n(context);
|
||||
|
||||
vm.runInNewContext(await fs.readFile(path.join(root, 'public/js/user-messages.js'), 'utf8'), context, { filename: path.join(root, 'public/js/user-messages.js') });
|
||||
await loadI18n(context);
|
||||
vm.runInNewContext(source, context, { filename: sourcePath });
|
||||
await context.Wegwichtel.EditorUi.openNewLocalRoute();
|
||||
elements.get('editor-route-name').value = 'ID-Test';
|
||||
@@ -502,14 +512,14 @@ test('local Streckenpunkt ids start at zero and increment from the highest exist
|
||||
|
||||
elements.get('editor-add-poi').dispatchEvent(pointerEvent());
|
||||
assert.equal(elements.get('editor-poi-id').value, '0');
|
||||
elements.get('editor-poi-title').value = 'Erster Streckenpunkt';
|
||||
elements.get('editor-poi-title').value = 'Erster Station';
|
||||
elements.get('editor-poi-form').dispatchEvent(submitEvent());
|
||||
await tick();
|
||||
await tick();
|
||||
|
||||
elements.get('editor-add-poi').dispatchEvent(pointerEvent());
|
||||
assert.equal(elements.get('editor-poi-id').value, '1');
|
||||
elements.get('editor-poi-title').value = 'Zweiter Streckenpunkt';
|
||||
elements.get('editor-poi-title').value = 'Zweiter Station';
|
||||
elements.get('editor-poi-form').dispatchEvent(submitEvent());
|
||||
await tick();
|
||||
await tick();
|
||||
@@ -517,18 +527,22 @@ test('local Streckenpunkt ids start at zero and increment from the highest exist
|
||||
const saved = packages.get('local-new');
|
||||
assert.equal(saved.pois.length, 2);
|
||||
assert.deepEqual(Array.from(saved.pois, poi => poi.id), [0, 1]);
|
||||
assert.deepEqual(Array.from(saved.pois, poi => poi.title), ['Erster Streckenpunkt', 'Zweiter Streckenpunkt']);
|
||||
assert.deepEqual(Array.from(saved.pois, poi => poi.title), ['Erster Station', 'Zweiter Station']);
|
||||
|
||||
const pointItems = elements.get('editor-poi-list').children.filter(child => child.dataset.poiId);
|
||||
assert.equal(pointItems.length, 2);
|
||||
});
|
||||
|
||||
|
||||
test('route and Streckenpunkt list expose red delete actions and remove local data', async () => {
|
||||
test('route and Station list expose red delete actions and remove local data', async () => {
|
||||
const sourcePath = path.join(root, 'public/js/editor-ui.js');
|
||||
const source = await fs.readFile(sourcePath, 'utf8');
|
||||
const { context, elements, packages } = buildEditorContext();
|
||||
|
||||
await loadI18n(context);
|
||||
|
||||
vm.runInNewContext(await fs.readFile(path.join(root, 'public/js/user-messages.js'), 'utf8'), context, { filename: path.join(root, 'public/js/user-messages.js') });
|
||||
await loadI18n(context);
|
||||
vm.runInNewContext(source, context, { filename: sourcePath });
|
||||
await context.Wegwichtel.EditorUi.openNewLocalRoute();
|
||||
elements.get('editor-route-name').value = 'Löschtest';
|
||||
@@ -537,7 +551,7 @@ test('route and Streckenpunkt list expose red delete actions and remove local da
|
||||
await tick();
|
||||
|
||||
elements.get('editor-add-poi').dispatchEvent(pointerEvent());
|
||||
elements.get('editor-poi-title').value = 'Streckenpunkt zum Löschen';
|
||||
elements.get('editor-poi-title').value = 'Station zum Löschen';
|
||||
elements.get('editor-poi-form').dispatchEvent(submitEvent());
|
||||
await tick();
|
||||
await tick();
|
||||
@@ -573,6 +587,10 @@ test('editing an activated server route uses PUT and never writes activation sta
|
||||
const source = await fs.readFile(sourcePath, 'utf8');
|
||||
const { calls, context, elements } = buildEditorContext();
|
||||
|
||||
await loadI18n(context);
|
||||
|
||||
vm.runInNewContext(await fs.readFile(path.join(root, 'public/js/user-messages.js'), 'utf8'), context, { filename: path.join(root, 'public/js/user-messages.js') });
|
||||
await loadI18n(context);
|
||||
vm.runInNewContext(source, context, { filename: sourcePath });
|
||||
await context.Wegwichtel.EditorUi.open();
|
||||
|
||||
@@ -597,7 +615,7 @@ test('editing an activated server route uses PUT and never writes activation sta
|
||||
|
||||
assert.equal(elements.get('editor-route-id').value, '1');
|
||||
assert.equal(elements.get('editor-route-gpx-group').hidden, false);
|
||||
assert.match(elements.get('editor-route-activated').textContent, /Veröffentlicht am/);
|
||||
assert.match(elements.get('editor-route-activated').textContent, /für alle freigegeben/);
|
||||
assert.equal(elements.get('editor-route-upload').hidden, true);
|
||||
|
||||
elements.get('editor-route-name').value = 'Freigegebener Waldweg geändert';
|
||||
@@ -612,7 +630,7 @@ test('editing an activated server route uses PUT and never writes activation sta
|
||||
assert.deepEqual(Object.keys(body).sort(), ['description', 'name']);
|
||||
assert.equal('activated_at' in body, false);
|
||||
assert.equal('activatedAt' in body, false);
|
||||
assert.equal(elements.get('editor-status').textContent, 'Speichern erfolgreich.');
|
||||
assert.equal(elements.get('editor-status').textContent, 'Gespeichert.');
|
||||
});
|
||||
|
||||
|
||||
@@ -630,6 +648,10 @@ test('local media picker keeps File System Access handles for later upload', asy
|
||||
return [handle];
|
||||
};
|
||||
|
||||
await loadI18n(context);
|
||||
|
||||
vm.runInNewContext(await fs.readFile(path.join(root, 'public/js/user-messages.js'), 'utf8'), context, { filename: path.join(root, 'public/js/user-messages.js') });
|
||||
await loadI18n(context);
|
||||
vm.runInNewContext(source, context, { filename: sourcePath });
|
||||
await context.Wegwichtel.EditorUi.openNewLocalRoute();
|
||||
elements.get('editor-route-name').value = 'Handle-Strecke';
|
||||
@@ -638,7 +660,7 @@ test('local media picker keeps File System Access handles for later upload', asy
|
||||
await tick();
|
||||
|
||||
elements.get('editor-add-poi').dispatchEvent(pointerEvent());
|
||||
elements.get('editor-poi-title').value = 'Streckenpunkt mit Bild';
|
||||
elements.get('editor-poi-title').value = 'Station mit Bild';
|
||||
elements.get('editor-poi-images-add').dispatchEvent(pointerEvent());
|
||||
await tick();
|
||||
assert.equal(elements.get('editor-poi-images').clickCount, 0);
|
||||
|
||||
Reference in New Issue
Block a user