23 lines
1,004 B
TypeScript
23 lines
1,004 B
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { createPdfByteStore } from "./byte-store";
|
||
|
|
import { markdownSourceToViewerHtml, resolveDomViewerHtml } from "./view-html";
|
||
|
|
import { ingestHtmlFromFile } from "./upload";
|
||
|
|
|
||
|
|
const HTML = `<!DOCTYPE html><html><body><p>Hello HTML viewer</p></body></html>`;
|
||
|
|
|
||
|
|
describe("resolveDomViewerHtml", () => {
|
||
|
|
it("returns sanitized HTML for html-dom representations", async () => {
|
||
|
|
const store = createPdfByteStore();
|
||
|
|
const file = new File([HTML], "sample.html", { type: "text/html" });
|
||
|
|
const { document, representation } = await ingestHtmlFromFile(file, store);
|
||
|
|
const html = resolveDomViewerHtml(document, representation, store);
|
||
|
|
expect(html).toContain("Hello HTML viewer");
|
||
|
|
expect(html).not.toMatch(/<script/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("renders markdown as paragraph HTML", () => {
|
||
|
|
const html = markdownSourceToViewerHtml("# Title\n\nBody paragraph.");
|
||
|
|
expect(html).toContain("<p>");
|
||
|
|
expect(html).toContain("Body paragraph.");
|
||
|
|
});
|
||
|
|
});
|