Docker Image bauen und veroeffentlichen / build-and-push (push) Successful in 2m53s
Admin texts can now contain the placeholder {{USt-IdNr}}. Wherever
content is read (lib/content.ts), it is replaced with the VAT ID
maintained under Admin > Einstellungen > Firmendaten, so every text
follows a change automatically. The placeholder is matched case- and
space-insensitively; an empty VAT ID inserts nothing, and unknown
placeholders stay visible so typos show up. Images, videos, select
fields and the source field itself are never rewritten.
The default imprint text uses the placeholder instead of a hard-coded
number, and the settings page lists the available placeholders.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { describe, test, expect } from "vitest";
|
|
import { TEXT_PLACEHOLDERS, containsPlaceholder, resolvePlaceholders } from "./text-placeholders";
|
|
|
|
const sources = { "company.vatId": "DE123456789" };
|
|
|
|
describe("resolvePlaceholders", () => {
|
|
test("setzt die USt-IdNr. fuer {{USt-IdNr}} ein", () => {
|
|
// Arrange
|
|
const text = "Umsatzsteuer-Identifikationsnummer gemäß § 27a UStG: {{USt-IdNr}}";
|
|
|
|
// Act
|
|
const result = resolvePlaceholders(text, sources);
|
|
|
|
// Assert
|
|
expect(result).toBe("Umsatzsteuer-Identifikationsnummer gemäß § 27a UStG: DE123456789");
|
|
});
|
|
|
|
test("erkennt den Baustein unabhaengig von Gross-/Kleinschreibung und Leerzeichen", () => {
|
|
expect(resolvePlaceholders("{{ ust-idnr }} / {{USTIDNR}}", sources)).toBe("DE123456789 / DE123456789");
|
|
});
|
|
|
|
test("ersetzt jedes Vorkommen", () => {
|
|
expect(resolvePlaceholders("{{USt-IdNr}} und {{USt-IdNr}}", sources)).toBe("DE123456789 und DE123456789");
|
|
});
|
|
|
|
test("laesst Texte ohne Baustein unveraendert", () => {
|
|
expect(resolvePlaceholders("Honig aus den Wäldern", sources)).toBe("Honig aus den Wäldern");
|
|
});
|
|
|
|
test("setzt bei leerer Quelle einen leeren Text ein statt den Baustein stehen zu lassen", () => {
|
|
expect(resolvePlaceholders("USt-IdNr.: {{USt-IdNr}}", { "company.vatId": "" })).toBe("USt-IdNr.: ");
|
|
});
|
|
|
|
test("laesst unbekannte Bausteine unveraendert", () => {
|
|
expect(resolvePlaceholders("{{Unbekannt}}", sources)).toBe("{{Unbekannt}}");
|
|
});
|
|
});
|
|
|
|
describe("containsPlaceholder", () => {
|
|
test("meldet einen bekannten Baustein", () => {
|
|
expect(containsPlaceholder("Nr.: {{USt-IdNr}}")).toBe(true);
|
|
});
|
|
|
|
test("meldet keinen Baustein bei normalem Text oder unbekanntem Baustein", () => {
|
|
expect(containsPlaceholder("Nr.: DE123")).toBe(false);
|
|
expect(containsPlaceholder("{{Unbekannt}}")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("TEXT_PLACEHOLDERS", () => {
|
|
test("verweist nur auf Quellen, die selbst keinen Baustein aufloesen muessen", () => {
|
|
// Eine Quelle, die wiederum Bausteine enthaelt, koennte sich im Kreis aufloesen.
|
|
expect(TEXT_PLACEHOLDERS.map((placeholder) => placeholder.sourceKey)).toEqual(["company.vatId"]);
|
|
});
|
|
});
|