39 lines
1.9 KiB
JavaScript
39 lines
1.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import vm from "node:vm";
|
|
import { createRequire } from "node:module";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const require = createRequire(new URL("../../../govoplan-core/webui/package.json", import.meta.url));
|
|
const ts = require("typescript");
|
|
|
|
function evaluate(relativePath, imports = () => ({})) {
|
|
const filename = fileURLToPath(new URL(relativePath, import.meta.url));
|
|
const source = fs.readFileSync(filename, "utf8");
|
|
const compiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }).outputText;
|
|
const exports = {};
|
|
vm.runInNewContext(compiled, { exports, require: imports }, { filename });
|
|
return exports;
|
|
}
|
|
|
|
const catalogue = evaluate("../src/i18n/generatedTranslations.ts");
|
|
// Evaluate the actual module descriptor; unrelated page rendering and optional
|
|
// capability imports are inert. The real translation catalogue is not mocked.
|
|
const { campaignModule } = evaluate("../src/module.ts", (name) => {
|
|
if (name === "react") return { lazy: () => () => null };
|
|
if (name === "./i18n/generatedTranslations") return catalogue;
|
|
return {};
|
|
});
|
|
const sections = campaignModule.uiCapabilities["admin.sections"].sections;
|
|
assert.equal(sections.length, 2);
|
|
for (const section of sections) {
|
|
assert.equal(campaignModule.translations.en[section.label], "Campaign delivery");
|
|
assert.equal(campaignModule.translations.de[section.label], "Campaign-Versand");
|
|
assert.ok(campaignModule.viewSurfaces.some((surface) => surface.id === section.surfaceId));
|
|
}
|
|
assert.equal(sections[0].id, "system-campaign-delivery");
|
|
assert.deepEqual(Array.from(sections[0].allOf), ["system:settings:read"]);
|
|
assert.equal(sections[1].id, "tenant-campaign-delivery");
|
|
assert.deepEqual(Array.from(sections[1].allOf), ["admin:policies:read"]);
|
|
console.log("Campaign delivery administration labels resolve in the real EN/DE module catalogue.");
|