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, /