mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	test(server/share): included text notes
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| import { describe, it, expect } from "vitest"; | ||||
| import { getContent, renderCode, renderText, type Result } from "./content_renderer.js"; | ||||
| import { trimIndentation } from "@triliumnext/commons"; | ||||
| import { buildShareNote } from "../test/shaca_mocking.js"; | ||||
| import { buildShareNote, buildShareNotes } from "../test/shaca_mocking.js"; | ||||
|  | ||||
| describe("content_renderer", () => { | ||||
|     it("Reports protected notes not being renderable", () => { | ||||
| @@ -28,6 +28,29 @@ describe("content_renderer", () => { | ||||
|             const result = getContent(note); | ||||
|             expect(result.content).toStrictEqual(content); | ||||
|         }); | ||||
|  | ||||
|         it("renders included notes", () => { | ||||
|             buildShareNotes([ | ||||
|                 { id: "subnote1", content: `<p>Foo</p><div>Bar</div>` }, | ||||
|                 { id: "subnote2", content: `<strong>Baz</strong>` } | ||||
|             ]); | ||||
|             const note = buildShareNote({ | ||||
|                 id: "note1", | ||||
|                 content: trimIndentation`\ | ||||
|                     <p>Before</p> | ||||
|                     <section class="include-note" data-note-id="subnote1" data-box-size="small"> </section> | ||||
|                     <section class="include-note" data-note-id="subnote2" data-box-size="small"> </section> | ||||
|                     <p>After</p> | ||||
|                 ` | ||||
|             }); | ||||
|             const result = getContent(note); | ||||
|             expect(result.content).toStrictEqual(trimIndentation`\ | ||||
|                 <p>Before</p> | ||||
|                 <p>Foo</p><div>Bar</div> | ||||
|                 <strong>Baz</strong> | ||||
|                 <p>After</p> | ||||
|             `); | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
|     describe("renderCode", () => { | ||||
|   | ||||
| @@ -80,7 +80,7 @@ export function renderText(result: Result, note: SNote) { | ||||
|         if (typeof includedResult.content !== "string") continue; | ||||
|  | ||||
|         const includedDocument = new JSDOM(includedResult.content).window.document; | ||||
|         includeNoteEl.replaceWith(includedDocument.body); | ||||
|         includeNoteEl.replaceWith(...includedDocument.body.childNodes); | ||||
|     } | ||||
|  | ||||
|     result.isEmpty = document.body.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0; | ||||
|   | ||||
| @@ -10,6 +10,7 @@ interface NoteDefinition extends AttributeDefinitions, RelationDefinitions { | ||||
|     id?: string | undefined; | ||||
|     title?: string; | ||||
|     content?: string | Buffer<ArrayBufferLike>; | ||||
|     children?: NoteDefinition[]; | ||||
|     isProtected?: boolean; | ||||
| } | ||||
|  | ||||
| @@ -59,6 +60,15 @@ export function buildShareNote(noteDef: NoteDefinition) { | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     // Handle children. | ||||
|     if (noteDef.children) { | ||||
|         for (const childDef of noteDef.children) { | ||||
|             const childNote = buildShareNote(childDef); | ||||
|  | ||||
|             // TODO: Create corresponding SBranch. | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Handle labels & relations | ||||
|     let position = 0; | ||||
|     for (const [ key, value ] of Object.entries(noteDef)) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user