mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
test(server/share): included text notes
This commit is contained in:
parent
1ad8b1bf85
commit
8b5e53e579
@ -1,7 +1,7 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { getContent, renderCode, renderText, type Result } from "./content_renderer.js";
|
import { getContent, renderCode, renderText, type Result } from "./content_renderer.js";
|
||||||
import { trimIndentation } from "@triliumnext/commons";
|
import { trimIndentation } from "@triliumnext/commons";
|
||||||
import { buildShareNote } from "../test/shaca_mocking.js";
|
import { buildShareNote, buildShareNotes } from "../test/shaca_mocking.js";
|
||||||
|
|
||||||
describe("content_renderer", () => {
|
describe("content_renderer", () => {
|
||||||
it("Reports protected notes not being renderable", () => {
|
it("Reports protected notes not being renderable", () => {
|
||||||
@ -28,6 +28,29 @@ describe("content_renderer", () => {
|
|||||||
const result = getContent(note);
|
const result = getContent(note);
|
||||||
expect(result.content).toStrictEqual(content);
|
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", () => {
|
describe("renderCode", () => {
|
||||||
|
@ -80,7 +80,7 @@ export function renderText(result: Result, note: SNote) {
|
|||||||
if (typeof includedResult.content !== "string") continue;
|
if (typeof includedResult.content !== "string") continue;
|
||||||
|
|
||||||
const includedDocument = new JSDOM(includedResult.content).window.document;
|
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;
|
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;
|
id?: string | undefined;
|
||||||
title?: string;
|
title?: string;
|
||||||
content?: string | Buffer<ArrayBufferLike>;
|
content?: string | Buffer<ArrayBufferLike>;
|
||||||
|
children?: NoteDefinition[];
|
||||||
isProtected?: boolean;
|
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
|
// Handle labels & relations
|
||||||
let position = 0;
|
let position = 0;
|
||||||
for (const [ key, value ] of Object.entries(noteDef)) {
|
for (const [ key, value ] of Object.entries(noteDef)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user