84 lines
3.2 KiB
JavaScript
84 lines
3.2 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { access, readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import berater from "../shared/berater-daten.json" with { type: "json" };
|
|
import { advisorDisplayName, findAdvisor } from "../shared/berater.js";
|
|
|
|
const projectRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
|
|
test("Beraterdaten haben eindeutige IDs und vollständige Profilfelder", () => {
|
|
assert.ok(berater.length >= 2);
|
|
assert.equal(new Set(berater.map(({ id }) => id)).size, berater.length);
|
|
|
|
for (const person of berater) {
|
|
assert.ok(person.id.trim());
|
|
assert.ok(person.name.trim());
|
|
assert.match(person.email, /^[^@\s]+@tri-hub\.de$/);
|
|
assert.ok(person.biographie.trim());
|
|
assert.ok(Array.isArray(person.qualifikationen));
|
|
assert.ok(Array.isArray(person.schwerpunkte));
|
|
assert.ok("bildquelle" in person);
|
|
}
|
|
});
|
|
|
|
test("Berater lassen sich per ID finden; unbekannte IDs liefern undefined", () => {
|
|
assert.equal(findAdvisor("relindis-agethen")?.spitzname, "Lilli");
|
|
assert.equal(findAdvisor("maren-hoffmann")?.vorname, "Maren");
|
|
assert.equal(findAdvisor("nicht-vorhanden"), undefined);
|
|
assert.equal(findAdvisor(null), undefined);
|
|
});
|
|
|
|
test("Kontaktname bevorzugt Spitzname und fällt auf den Vornamen zurück", () => {
|
|
assert.equal(
|
|
advisorDisplayName({ spitzname: " Lilli ", vorname: "Relindis" }),
|
|
"Lilli",
|
|
);
|
|
assert.equal(
|
|
advisorDisplayName({ spitzname: "", vorname: "Maren" }),
|
|
"Maren",
|
|
);
|
|
assert.equal(
|
|
advisorDisplayName({ spitzname: null, vorname: "Maren" }),
|
|
"Maren",
|
|
);
|
|
assert.equal(advisorDisplayName({ spitzname: " ", vorname: " " }), "");
|
|
});
|
|
|
|
test("jedes Profil hat Porträt und Aktionsbild, deren Dateien vorhanden sind", async () => {
|
|
for (const person of berater) {
|
|
assert.equal(
|
|
person.bilder?.length,
|
|
2,
|
|
`${person.id} muss zwei Bilder haben`,
|
|
);
|
|
assert.deepEqual(
|
|
person.bilder.map(({ typ }) => typ),
|
|
["Porträt", "Aktionsbild"],
|
|
);
|
|
|
|
for (const { quelle } of person.bilder) {
|
|
assert.match(quelle, /^\/images\//);
|
|
await access(join(projectRoot, "public", quelle.slice(1)));
|
|
}
|
|
}
|
|
});
|
|
|
|
test("Profilseite ist separat verlinkt und die Landingpage rendert keine Beraterkarten", async () => {
|
|
const [page, landingPage, navigation] = await Promise.all([
|
|
readFile(join(projectRoot, "berater.html"), "utf8"),
|
|
readFile(join(projectRoot, "index.html"), "utf8"),
|
|
readFile(
|
|
join(projectRoot, "src/components/navigationsbar/navigation.html"),
|
|
"utf8",
|
|
),
|
|
]);
|
|
|
|
assert.match(page, /id="advisor-profiles"/);
|
|
assert.match(page, /src="\/src\/features\/berater\/berater-entry\.js"/);
|
|
assert.match(navigation, /href="\/berater\.html"[^>]*>Beraterprofil/);
|
|
assert.doesNotMatch(landingPage, /id="advisor-profiles"/);
|
|
assert.doesNotMatch(landingPage, /berater-entry\.js/);
|
|
});
|