import { loadI18n } from '../test-support/i18n.js';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import path from 'node:path';
import test from 'node:test';
import vm from 'node:vm';
import { localizeHtml } from '../scripts/localize-html.js';
const root = path.resolve(import.meta.dirname, '..');
test('German legal pages and contacts remain static when the app uses English', async () => {
const context = { navigator: { language: 'en-GB' } };
const i18n = await loadI18n(context);
const html = await fs.readFile(path.join(root, 'public/index.html'), 'utf8');
const englishHtml = localizeHtml(html, key => i18n.t(key));
for (const name of ['privacy', 'imprint']) {
const pattern = new RegExp(`]+data-info-page="${name}"[^>]*>[\\s\\S]*?`);
const page = pattern.exec(html)?.[0];
assert.ok(page, name);
assert.match(page, /lang="de"/);
assert.doesNotMatch(page, /data-i18n/);
assert.equal(pattern.exec(englishHtml)?.[0], page);
}
for (const catalog of context.Wegwichtel.TextCatalogs.values()) {
for (const key of ['privacy', 'imprint', 'contacts']) {
assert.equal(Object.hasOwn(catalog, key), false, key);
}
}
});
test('checked-in HTML has synchronized German defaults and accessible headings, labels and links before scripts load', async () => {
const i18n = await loadI18n({});
const html = await fs.readFile(path.join(root, 'public/index.html'), 'utf8');
assert.equal(localizeHtml(html, key => i18n.t(key)), html, 'Run node scripts/localize-html.js after editing German texts');
for (const match of html.matchAll(/]*>([\s\S]*?)<\/h[1-6]>/g)) assert.ok(match[1].replaceAll(/<[^>]*>/g, '').trim(), match[0]);
for (const match of html.matchAll(/\baria-label="([^"]*)"/g)) assert.ok(match[1].trim(), 'Empty accessible label');
for (const match of html.matchAll(/]*>([\s\S]*?)<\/a>/g)) assert.ok(match[1].replaceAll(/<[^>]*>/g, '').trim(), match[0]);
for (const match of html.matchAll(/