Preserve rich formatting when restoring selected text
This commit is contained in:
77
tests/rich-text.test.ts
Normal file
77
tests/rich-text.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { restoreRichHtml } from "../src/lib/rich-text";
|
||||
|
||||
const mapping = {
|
||||
PERSON_01: { original: "Max Mustermann", type: "PERSON" },
|
||||
ORG_01: { original: "Müller & Söhne", type: "ORG" },
|
||||
};
|
||||
|
||||
describe("formatierte Textwiederherstellung", () => {
|
||||
it("behält Formatierung bei und maskiert Originale HTML-sicher", () => {
|
||||
const html = "<p>Hallo <strong>PERSON_01</strong> bei <em>ORG_01</em>.</p>";
|
||||
expect(
|
||||
restoreRichHtml(
|
||||
html,
|
||||
"Hallo PERSON_01 bei ORG_01.",
|
||||
"Hallo Max Mustermann bei Müller & Söhne.",
|
||||
mapping,
|
||||
),
|
||||
).toBe(
|
||||
"<p>Hallo <strong>Max Mustermann</strong> bei <em>Müller & Söhne</em>.</p>",
|
||||
);
|
||||
});
|
||||
|
||||
it("ändert weder Attribute noch unsichtbare Inhalte", () => {
|
||||
const html =
|
||||
'<div data-label="PERSON_01"><style>.PERSON_01{color:red}</style><b>PERSON_01</b></div>';
|
||||
expect(restoreRichHtml(html, "PERSON_01", "Max Mustermann", mapping)).toBe(
|
||||
'<div data-label="PERSON_01"><style>.PERSON_01{color:red}</style><b>Max Mustermann</b></div>',
|
||||
);
|
||||
});
|
||||
|
||||
it("übernimmt kodierte Sitzungsplatzhalter", () => {
|
||||
const html = "<span><PERSON_01></span>";
|
||||
expect(
|
||||
restoreRichHtml(
|
||||
html,
|
||||
"<PERSON_01>",
|
||||
"Max Mustermann",
|
||||
mapping,
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
).toBe("<span>Max Mustermann</span>");
|
||||
});
|
||||
|
||||
it("verwirft nicht passende oder über mehrere Textknoten verteilte HTML-Daten", () => {
|
||||
expect(
|
||||
restoreRichHtml(
|
||||
"<b>PERSON_01</b>",
|
||||
"anderer Text",
|
||||
"Max Mustermann",
|
||||
mapping,
|
||||
),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
restoreRichHtml(
|
||||
"<b>PERSON_</b><i>01</i>",
|
||||
"PERSON_01",
|
||||
"Max Mustermann",
|
||||
mapping,
|
||||
),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("beachtet projektbezogene Ersetzung innerhalb zusammengesetzter Begriffe", () => {
|
||||
const html = "<b>abcPERSON_01xyz</b>";
|
||||
expect(
|
||||
restoreRichHtml(
|
||||
html,
|
||||
"abcPERSON_01xyz",
|
||||
"abcMax Mustermannxyz",
|
||||
mapping,
|
||||
{ PERSON_01: "anywhere" },
|
||||
),
|
||||
).toBe("<b>abcMax Mustermannxyz</b>");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user