Validation_Suite/validation-suite/frontend/atlas/tests/validation-result.test.mjs

45 lines
2.2 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
const resultSource = fs.readFileSync(path.resolve("lib/validation-result.tsx"), "utf8");
const dashboardSource = fs.readFileSync(path.resolve("app/(app)/dashboard/page.tsx"), "utf8");
const validationsSource = fs.readFileSync(path.resolve("app/(app)/validations/page.tsx"), "utf8");
const editorSource = fs.readFileSync(path.resolve("components/validations/validation-editor.tsx"), "utf8");
test("central validation result mapping covers supported values and colors", () => {
for (const value of ["BESTANDEN", "BESTANDEN_MIT_AUFLAGEN", "NICHT_BESTANDEN", "OFFEN"]) {
assert.match(resultSource, new RegExp(value));
}
for (const label of ["Bestanden", "Bestanden mit Auflagen", "Nicht bestanden", "Noch nicht bewertet"]) {
assert.match(resultSource, new RegExp(label));
}
for (const token of ["bg-success", "bg-warning", "bg-danger", "bg-slate"]) {
assert.match(resultSource, new RegExp(token));
}
});
test("validations overview renders result badge from central mapping", () => {
assert.match(validationsSource, /ValidationResultBadge/);
assert.match(validationsSource, /validationResultValues\.map/);
assert.doesNotMatch(validationsSource, /<option value="mit_auflagen">/);
assert.doesNotMatch(validationsSource, /<option value="nicht_bestanden">/);
});
test("dashboard renders result badges from central mapping", () => {
assert.match(dashboardSource, /ValidationResultBadge/);
assert.match(dashboardSource, /validation_result_passed/);
assert.match(dashboardSource, /validation_result_conditional/);
assert.match(dashboardSource, /validation_result_failed/);
assert.match(dashboardSource, /validation_result_open/);
});
test("editor uses central options and inline result preview", () => {
assert.match(editorSource, /validationResultValues\.map/);
assert.match(editorSource, /selectedResult\.previewClass/);
assert.match(editorSource, /selectedResult\.label/);
assert.match(editorSource, /normalizeValidationResult\(data\.result\)/);
assert.doesNotMatch(editorSource, /<option value="offen">/);
assert.doesNotMatch(editorSource, /<option value="mit_auflagen">/);
});