69 lines
2.5 KiB
JavaScript
69 lines
2.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import test from "node:test";
|
|
import path from "node:path";
|
|
|
|
const page = fs.readFileSync(path.resolve("app/(app)/settings/report-layout/page.tsx"), "utf8");
|
|
const shell = fs.readFileSync(path.resolve("components/app-shell.tsx"), "utf8");
|
|
const bff = fs.readFileSync(path.resolve("app/api/report-settings/route.ts"), "utf8");
|
|
const previewBff = fs.readFileSync(path.resolve("app/api/report-settings/preview/route.ts"), "utf8");
|
|
|
|
test("admin navigation contains report settings only for admins", () => {
|
|
assert.match(shell, /href: "\/settings\/report-layout"/);
|
|
assert.match(shell, /label: "Berichtseinstellungen"/);
|
|
assert.match(shell, /adminOnly: true/);
|
|
});
|
|
|
|
test("report settings page gates non-admin users and loads saved settings", () => {
|
|
assert.match(page, /user\?\.role !== "admin"/);
|
|
assert.match(page, /fetch\("\/api\/report-settings"/);
|
|
assert.match(page, /queryKey: \["report-settings"\]/);
|
|
assert.match(page, /Berichtseinstellungen werden geladen/);
|
|
});
|
|
|
|
test("dirty state controls reset and save behavior", () => {
|
|
assert.match(page, /const dirty = !sameSettings\(draft, saved\)/);
|
|
assert.match(page, /disabled=\{!dirty \|\| saveMutation\.isPending/);
|
|
assert.match(page, /setDraft\(saved\)/);
|
|
assert.match(page, /Änderungen verworfen/);
|
|
});
|
|
|
|
test("page sends PUT and preview PDF through Atlas BFF", () => {
|
|
assert.match(page, /method: "PUT"/);
|
|
assert.match(page, /JSON\.stringify\(values\)/);
|
|
assert.match(page, /\/api\/report-settings\/preview/);
|
|
assert.match(page, /Vorschau aktualisieren/);
|
|
assert.match(page, /PDF wird erzeugt/);
|
|
assert.match(page, /<iframe title="Orion PDF-Vorschau"/);
|
|
assert.match(page, /URL\.createObjectURL/);
|
|
});
|
|
|
|
test("report settings page exposes v1.1 setting groups", () => {
|
|
for (const label of [
|
|
"Seitenlayout",
|
|
"Seitenränder",
|
|
"Abschnittsabstände",
|
|
"Deckblatt kompakt",
|
|
"Tabellen",
|
|
"Tabellenlayout",
|
|
"Tabellenschrift",
|
|
"Bildposition",
|
|
"Maximale Bilder pro Seite",
|
|
"Bildbeschriftungen",
|
|
"Kopf- und Fußzeile",
|
|
"Kopfzeile anzeigen",
|
|
"Fußzeile anzeigen",
|
|
"Firmenlogo"
|
|
]) {
|
|
assert.match(page, new RegExp(label));
|
|
}
|
|
});
|
|
|
|
test("BFF routes use HttpOnly cookie and forward PDF content", () => {
|
|
assert.match(bff, /AUTH_COOKIE_NAME/);
|
|
assert.match(bff, /Authorization: `Bearer \$\{token\}`/);
|
|
assert.match(bff, /\/report-settings/);
|
|
assert.match(previewBff, /content-type/);
|
|
assert.match(previewBff, /application\/pdf/);
|
|
assert.match(previewBff, /orion-layout-preview\.pdf/);
|
|
});
|