47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
|
|
// @vitest-environment happy-dom
|
||
|
|
|
||
|
|
import { useEffect } from "react";
|
||
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { render, screen } from "@testing-library/react";
|
||
|
|
import { createEngine, type Engine } from "@engine/index";
|
||
|
|
import { ingestHtmlFromFile } from "@source/index";
|
||
|
|
import { EngineProvider, useActiveDocumentId, usePdfByteStore } from "./EngineContext";
|
||
|
|
import { ViewerShell } from "./ViewerShell";
|
||
|
|
|
||
|
|
function BootstrapHtmlDoc({
|
||
|
|
engine,
|
||
|
|
file,
|
||
|
|
}: {
|
||
|
|
readonly engine: Engine;
|
||
|
|
readonly file: File;
|
||
|
|
}) {
|
||
|
|
const byteStore = usePdfByteStore();
|
||
|
|
const { setId } = useActiveDocumentId();
|
||
|
|
useEffect(() => {
|
||
|
|
void ingestHtmlFromFile(file, byteStore).then(({ document, representation }) => {
|
||
|
|
engine.documents.register({ document, representation });
|
||
|
|
setId(document.id);
|
||
|
|
});
|
||
|
|
}, [byteStore, engine, file, setId]);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
describe("ViewerShell (dom)", () => {
|
||
|
|
it("renders HtmlViewerAdapter content for html-dom documents", async () => {
|
||
|
|
const engine = createEngine();
|
||
|
|
const file = new File(
|
||
|
|
["<!DOCTYPE html><html><body><p>Dom viewer smoke test</p></body></html>"],
|
||
|
|
"sample.html",
|
||
|
|
{ type: "text/html" },
|
||
|
|
);
|
||
|
|
|
||
|
|
render(
|
||
|
|
<EngineProvider engine={engine}>
|
||
|
|
<BootstrapHtmlDoc engine={engine} file={file} />
|
||
|
|
<ViewerShell />
|
||
|
|
</EngineProvider>,
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(await screen.findByText("Dom viewer smoke test")).toBeTruthy();
|
||
|
|
});
|
||
|
|
});
|