import { describe, it, expect } from "vitest"; import { getContent, renderCode, type Result } from "./content_renderer.js"; import { trimIndentation } from "@triliumnext/commons"; import { buildShareNote, buildShareNotes } from "../test/shaca_mocking.js"; describe("content_renderer", () => { beforeAll(() => { vi.mock("../becca/becca_loader.js", () => ({ default: { load: vi.fn(), loaded: Promise.resolve() } })); }); it("Reports protected notes not being renderable", () => { const note = buildShareNote({ isProtected: true }); const result = getContent(note); expect(result.content).toStrictEqual("
Protected note cannot be displayed
"); }); describe("Text note", () => { it("parses simple note", () => { const content = trimIndentation`\Welcome to Trilium Notes!
`; const note = buildShareNote({ content }); const result = getContent(note); expect(result.content).toStrictEqual(content); }); it("renders included notes", () => { buildShareNotes([ { id: "subnote1", content: `Foo
Before
After
` }); const result = getContent(note); expect(result.content).toStrictEqual(trimIndentation`\Before
Foo
After
`); }); it("handles syntax highlight for code blocks with escaped syntax", () => { const note = buildShareNote({ id: "note", content: trimIndentation`\
<t t-name="module.SectionWidthOption">
<BuilderRow label.translate="Section Width">
</BuilderRow>
</t>
`
});
const result = getContent(note);
expect(result.content).toStrictEqual(trimIndentation`\
<t t-name="module.SectionWidthOption">
<BuilderRow label.translate="Section Width">
</BuilderRow>
</t>
`)
});
describe("Reference links", () => {
it("handles attachment link", () => {
const content = trimIndentation`\
The quick <strong>brown</strong> fox
`); }); }); }); describe("renderCode", () => { it("identifies empty content", () => { const emptyResult: Result = { header: "", content: " " }; renderCode(emptyResult); expect(emptyResult.isEmpty).toBeTruthy(); }); it("identifies unsupported content type", () => { const emptyResult: Result = { header: "", content: Buffer.from("Hello world") }; renderCode(emptyResult); expect(emptyResult.isEmpty).toBeTruthy(); }); it("wraps code in", () => {
const result: Result = {
header: "",
content: "\tHello\nworld"
};
renderCode(result);
expect(result.isEmpty).toBeFalsy();
expect(result.content).toBe("\tHello\nworld
");
});
});
});