Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(text): cover include-note edge cases flagged by patch coverage
Elian Doran232b8a643623
diff --git a/apps/client/src/services/content_renderer_text.spec.ts b/apps/client/src/services/content_renderer_text.spec.tsindex bddde7b18f..8e0a57fb85 100644--- a/apps/client/src/services/content_renderer_text.spec.ts+++ b/apps/client/src/services/content_renderer_text.spec.ts@@ -331,6 +331,25 @@ describe("Nested include notes (single-level display vs recursive print)", () =>expect(contentEl.querySelector('section.include-note[data-note-id="nestC"]')).toBeNull();expect(contentEl.querySelector("a.reference-link")?.getAttribute("href")).toContain("nestC");});++ it("leaves include-note sections with a missing or invalid note ID untouched when degrading to reference links", async () => {+ const note = buildNote({+ id: "badRefHost",+ title: "Host",+ content: trimIndentation`+ <p>host</p>+ <section class="include-note" data-box-size="medium"> </section>+ <section class="include-note" data-note-id="bad id!" data-box-size="medium"> </section>+ `+ });+ const contentEl = document.createElement("div");+ await renderText(note, $(contentEl), { includesAsReferenceLinks: true });++ // Neither the missing-id nor the invalid-id section is converted to a reference link;+ // both are left in place.+ expect(contentEl.querySelector("a.reference-link")).toBeNull();+ expect(contentEl.querySelectorAll("section.include-note").length).toBe(2);+ });});describe("renderIncludedNotes via postProcessRichContent", () => {diff --git a/apps/client/src/widgets/type_widgets/text/utils.spec.ts b/apps/client/src/widgets/type_widgets/text/utils.spec.tsindex 9eafb1d3de..5a0faf4889 100644--- a/apps/client/src/widgets/type_widgets/text/utils.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/utils.spec.ts@@ -51,6 +51,18 @@ describe("loadIncludedNote", () => {expect(wrappers.children(".include-note-content").length).toBe(1);});+ it("builds an expandable include (toggle) and degrades the note's own includes to reference links", async () => {+ const $el = $('<div class="include-note-wrapper">');++ await loadIncludedNote("noteY", $el, "expandable");++ // The expandable branch adds a title row with a toggle button.+ expect($el.children(".include-note-title-row").length).toBe(1);+ expect($el.find("button.include-note-toggle").length).toBe(1);+ // The included note is rendered with its own includes reduced to reference links.+ expect(content_renderer.getRenderedContent).toHaveBeenCalledWith(note, { interactive: true, includesAsReferenceLinks: true });+ });+it("disposes interactive content of a previous render before replacing it", async () => {const $el = $('<div class="include-note-wrapper">');diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.tsindex b1b6339637..f8c44b44b8 100644--- a/apps/server/src/share/content_renderer.spec.ts+++ b/apps/server/src/share/content_renderer.spec.ts@@ -128,6 +128,19 @@ describe("content_renderer", () => {expect(result.content).toContain("reference-link");});+ it("leaves an include-note section untouched when the referenced note is missing", () => {+ const note = buildShareNote({+ id: "missingRefHost",+ content: `<p>host</p><section class="include-note" data-note-id="ghostNote" data-box-size="medium"> </section>`+ });+ const result = getContent(note);+ if (typeof result.content !== "string") throw new Error("expected string content");+ // The missing note is skipped: the section stays, nothing is expanded or reference-linked.+ expect(result.content).toContain("host");+ expect(result.content).toContain(`data-note-id="ghostNote"`);+ expect(result.content).not.toContain("reference-link");+ });+it("renders an included large code note without hanging or re-parsing it as HTML (#9717)", () => {// ~2 MiB of angle-bracket-heavy code that previously exploded node-html-parser.const codeLine = `const x: Array<Map<string, List<number>>> = a < b && c > d; // <div>\n`;