here<\/b>/);
});
it("strips an event handler smuggled onto an allowed tag", () => {
const { html } = patchTitle("safe", 'x', "rich-text");
expect(html).not.toContain("onclick");
expect(html).toContain("x");
});
it("keeps only the allowlisted style properties", () => {
const { html } = patchTitle(
"safe",
'x',
"rich-text",
);
expect(html).toContain("color: red");
expect(html).not.toContain("position: fixed");
});
it("unwraps a structural tag rather than losing the text inside it", () => {
const { html } = patchTitle("safe", "kept
", "rich-text");
expect(html).toContain("kept");
expect(html).not.toContain("kept");
});
it("replaces the previous contents rather than appending to them", () => {
const { html } = patchTitle("old words", "new words", "rich-text");
expect(html).toContain("new words");
expect(html).not.toContain("old words");
});
it("reports unmatched for an element that is not there", () => {
const result = patchElementInHtml(DOC("x"), { id: "absent" }, [
{ type: "rich-text", property: "", value: "y" },
]);
expect(result.matched).toBe(false);
});
it("leaves the source alone when the value is null", () => {
const before = DOC("keep me");
const { html } = patchElementInHtml(before, { id: "title" }, [
{ type: "rich-text", property: "", value: null },
]);
expect(html).toContain("keep me");
});
});
describe("text-content is still not a markup sink", () => {
it("escapes markup handed to the older operation, exactly as before", () => {
const { html } = patchTitle("safe", 'x', "text-content");
expect(html).not.toContain('');
expect(html).toContain("<span");
});
});
describe("rich-text round trips what a real composition contains", () => {
it("keeps text that looks like markup as text", () => {
const { html } = patchTitle("safe", "a <b> & c", "rich-text");
expect(html).toContain("<b>");
expect(html).not.toContain("");
});
it("keeps non-ASCII text intact", () => {
const { html } = patchTitle("safe", "héllo 👍 世界", "rich-text");
expect(html).toContain("héllo");
expect(html).toContain("👍");
expect(html).toContain("世界");
});
it("keeps a line break", () => {
const { html } = patchTitle("safe", "a
b", "rich-text");
expect(html).toMatch(/
/);
});
it("keeps the wrapper span a flex element needs", () => {
const { html } = patchTitle(
"safe",
'a b c',
"rich-text",
);
expect(html).toMatch(
/a b<\/span> c<\/span>/,
);
});
it("empties the element when every character was deleted", () => {
const { html } = patchTitle("gone", "", "rich-text");
expect(html).toContain('id="title">');
});
it("does not accumulate markup when the same value is written twice", () => {
const value = 'x';
const once = patchTitle("safe", value, "rich-text").html;
const twice = patchElementInHtml(once, { id: "title" }, [
{ type: "rich-text", property: "", value },
]).html;
expect(twice).toBe(once);
});
});