Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(share-theme): cover the app view host and its views
Elian Doran8e063854d423
diff --git a/packages/share-theme/src/content/app_host.spec.tsx b/packages/share-theme/src/content/app_host.spec.tsxnew file mode 100644index 0000000000..8be94e5c69--- /dev/null+++ b/packages/share-theme/src/content/app_host.spec.tsx@@ -0,0 +1,216 @@+// @vitest-environment happy-dom+import { createContext, render } from "preact";+import { useContext } from "preact/hooks";+import { act } from "preact/test-utils";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++import ShareAppHost, { type AppPayload, type HostedApp } from "./app_host.js";++const mocks = vi.hoisted(() => ({+ appContext: {+ tabManager: undefined as unknown,+ child: vi.fn(),+ removeChild: vi.fn()+ },+ froca: {+ notes: new Map<string, { noteId: string }>(),+ setSource: vi.fn(),+ addResp: vi.fn(),+ getNoteFromCache: vi.fn(),+ reloadNotes: vi.fn()+ },+ loadOptions: vi.fn(),+ setImageUrlResolver: vi.fn(),+ setShareLinkResolver: vi.fn(),+ shareSource: {+ getNoteLink: (noteId: string) => (noteId === "unlinked" ? null : `./${noteId}`),+ loadNotes: vi.fn()+ },+ staticSource: {+ getNoteLink: (noteId: string) => `../pages/${noteId}.html`,+ getImageUrl: vi.fn(),+ loadNotes: vi.fn()+ },+ createStaticFrocaSource: vi.fn()+}));++vi.mock("@triliumnext/client/src/components/app_context.js", () => ({ default: mocks.appContext }));+vi.mock("@triliumnext/client/src/components/component.js", () => ({ default: class Component {} }));+vi.mock("@triliumnext/client/src/components/tab_manager.js", () => ({+ default: class TabManager {}+}));+vi.mock("@triliumnext/client/src/menus/link_context_menu.js", () => ({+ default: { setShareLinkResolver: mocks.setShareLinkResolver }+}));+vi.mock("@triliumnext/client/src/services/froca.js", () => ({ default: mocks.froca }));+vi.mock("@triliumnext/client/src/services/image_urls.js", () => ({+ setImageUrlResolver: mocks.setImageUrlResolver+}));+vi.mock("@triliumnext/client/src/services/link.js", () => ({+ parseNavigationStateFromUrl: (href: string | undefined) =>+ ({ notePath: href?.replace(/^#/, "") })+}));+vi.mock("@triliumnext/client/src/services/options.js", () => ({+ default: { load: mocks.loadOptions }+}));+vi.mock("@triliumnext/client/src/widgets/react/react_utils.js", () => ({+ ParentComponent: createContext<unknown>(null)+}));+vi.mock("./share_froca_source.js", () => ({+ createShareFrocaSource: () => mocks.shareSource,+ createStaticFrocaSource: mocks.createStaticFrocaSource+}));++const { ParentComponent } = await import("@triliumnext/client/src/widgets/react/react_utils.js");++describe("ShareAppHost", () => {+ let container: HTMLElement;+ let location: { href: string };++ beforeEach(() => {+ container = document.createElement("div");+ document.body.append(container);+ location = { href: "" };+ vi.spyOn(window, "location", "get").mockReturnValue(location as Location);+ mocks.froca.notes.clear();+ mocks.froca.getNoteFromCache.mockImplementation(+ (noteId: string) => mocks.froca.notes.get(noteId));+ mocks.createStaticFrocaSource.mockReturnValue(mocks.staticSource);+ mocks.appContext.tabManager = undefined;+ });++ afterEach(() => {+ act(() => render(null, container));+ container.remove();+ vi.restoreAllMocks();+ vi.clearAllMocks();+ });++ it("loads the payload into froca, read-only, with its orphans below a root", async () => {+ mocks.froca.notes.set("board", { noteId: "board" });+ let app: HostedApp | undefined;+ let parent: unknown;++ mount(buildPayload(), (hosted) => {+ app = hosted;+ return <ParentReader onRead={(value) => { parent = value; }} />;+ });++ expect(mocks.loadOptions).toHaveBeenCalledWith({ theme: "next" });+ expect(mocks.setImageUrlResolver).toHaveBeenCalledWith(undefined);+ expect(mocks.setShareLinkResolver).toHaveBeenCalledWith(mocks.shareSource.getNoteLink);+ const rows = mocks.froca.addResp.mock.calls[0][0];+ expect(rows.notes.map((note: { noteId: string }) => note.noteId))+ .toEqual([ "root", "board", "card", "_template_board" ]);+ expect(rows.branches.map((branch: { branchId: string }) => branch.branchId))+ .toEqual([ "card_board", "root_board" ]);+ expect(rows.attributes.at(-1)).toMatchObject({ noteId: "board", name: "readOnly" });+ expect(app?.note.noteId).toBe("board");+ expect(app?.parentNoteId).toBe("parent");+ expect(parent).toBe(mocks.appContext.child.mock.calls[1][0]);++ // The source anchors the notes it loads later the same way, now that froca has a root.+ mocks.froca.notes.set("root", { noteId: "root" });+ mocks.shareSource.loadNotes.mockResolvedValue({+ notes: [ { noteId: "later" } ], branches: [], attributes: []+ });+ const source = mocks.froca.setSource.mock.calls[0][0];+ expect(await source.loadNotes([ "later" ])).toMatchObject({+ notes: [ { noteId: "later" } ],+ branches: [ { branchId: "root_later", parentNoteId: "root" } ]+ });++ app?.openNote("card");+ expect(location.href).toBe("./card");+ app?.openNote("unlinked");+ expect(location.href).toBe("./card");+ expect(app?.hasLink("unlinked")).toBe(false);+ });++ it("starts one tab manager for the views and lets go of their component on unmount", () => {+ mocks.froca.notes.set("board", { noteId: "board" });++ mount(buildPayload(), () => null);+ const tabManager = mocks.appContext.tabManager;+ act(() => render(null, container));+ mount(buildPayload(), () => null);++ expect(tabManager).toBeDefined();+ expect(mocks.appContext.tabManager).toBe(tabManager);+ expect(mocks.appContext.removeChild).toHaveBeenCalledOnce();+ });++ it("opens a clicked link into the note tree on the note's shared page", () => {+ mocks.froca.notes.set("board", { noteId: "board" });+ mount(buildPayload(), () => (+ <>+ <span className="reference-link" data-href="#root/board/card"><b>Card</b></span>+ <a href="#root/unlinked">Unlinked</a>+ <a href="https://example.com">External</a>+ </>+ ));++ const click = (element: Element | null) => {+ const event = new MouseEvent("click", { bubbles: true, cancelable: true });+ element?.dispatchEvent(event);+ return event.defaultPrevented;+ };++ expect(click(container.querySelector("b"))).toBe(true);+ expect(location.href).toBe("./card");+ expect(click(container.querySelector("a[href^='#']"))).toBe(false);+ expect(click(container.querySelector("a[href^='https']"))).toBe(false);+ });++ it("reads a static export's notes before it mounts the views", async () => {+ mocks.froca.notes.set("board", { noteId: "board" });+ let resolveReload = () => {};+ mocks.froca.reloadNotes.mockReturnValue(+ new Promise<void>((resolve) => { resolveReload = resolve; }));++ mount({ ...buildPayload(), exportBasePath: "../" }, () => <p className="view" />);++ expect(mocks.createStaticFrocaSource).toHaveBeenCalledWith({ board: "./board" }, "../");+ expect(mocks.setImageUrlResolver).toHaveBeenCalledWith(mocks.staticSource.getImageUrl);+ expect(mocks.froca.reloadNotes).toHaveBeenCalledWith([ "board" ]);+ expect(container.querySelector(".view")).toBeNull();++ await act(async () => resolveReload());+ expect(container.querySelector(".view")).not.toBeNull();+ });++ it("mounts nothing, nor follows links, when froca has no note to show", () => {+ const children = vi.fn(() => null);++ mount(buildPayload(), children);+ const event = new MouseEvent("click", { bubbles: true, cancelable: true });+ document.body.dispatchEvent(event);++ expect(children).not.toHaveBeenCalled();+ expect(event.defaultPrevented).toBe(false);+ });++ function mount(payload: AppPayload, children: (app: HostedApp) => preact.ComponentChildren) {+ act(() => render(+ <ShareAppHost noteId="board" payload={payload}>{children}</ShareAppHost>,+ container+ ));+ }+});++function ParentReader({ onRead }: { onRead(value: unknown): void }) {+ onRead(useContext(ParentComponent));+ return null;+}++function buildPayload(): AppPayload {+ return {+ notes: [ { noteId: "board" }, { noteId: "card" }, { noteId: "_template_board" } ],+ branches: [ { branchId: "card_board", noteId: "card", parentNoteId: "board" } ],+ attributes: [],+ links: { board: "./board" },+ options: { theme: "next", locale: null },+ assetPath: "",+ parentNoteId: "parent"+ } as unknown as AppPayload;+}diff --git a/packages/share-theme/src/content/app_view.spec.ts b/packages/share-theme/src/content/app_view.spec.tsnew file mode 100644index 0000000000..c2fa021e0b--- /dev/null+++ b/packages/share-theme/src/content/app_view.spec.ts@@ -0,0 +1,71 @@+// @vitest-environment happy-dom+import { afterEach, describe, expect, it, vi } from "vitest";++import type { AppPayload } from "./app_host.js";+import setupAppView from "./app_view.js";++const { initLocale } = vi.hoisted(() => ({ initLocale: vi.fn() }));++vi.mock("@triliumnext/client/src/components/app_context.js", () => ({ default: {} }));+vi.mock("@triliumnext/client/src/services/i18n.js", () => ({ initLocale }));++describe("setupAppView", () => {+ afterEach(() => {+ document.body.replaceChildren();+ document.body.className = "";+ document.documentElement.className = "";+ vi.unstubAllGlobals();+ });++ it("shows the content without mounting where the page has no view or payload", async () => {+ const load = vi.fn();+ document.body.innerHTML = `<div id="content"><div class="share-note-view"></div></div>`;++ await setupAppView(".share-note-view", load);+ document.body.innerHTML = `<div id="content"><script class="share-froca"></script></div>`;+ await setupAppView(".share-note-view", load);++ expect(load).not.toHaveBeenCalled();+ expect(document.documentElement.classList.contains("app-view-shown")).toBe(true);+ });++ it("mounts the view with the app's globals and the payload's locale", async () => {+ const glob = { assetPath: "" };+ vi.stubGlobal("glob", glob);+ const mount = vi.fn();+ const container = renderPage({ locale: "de" });++ await setupAppView(".share-note-view", async () => ({ default: mount }));++ expect(mount).toHaveBeenCalledWith(container,+ expect.objectContaining({ assetPath: "assets/v1" }));+ expect(initLocale).toHaveBeenCalledWith("de");+ expect(glob.assetPath).toBe("assets/v1");+ expect(document.body.classList.contains("desktop")).toBe(true);+ const globals = window as unknown as { $: unknown; jQuery: unknown };+ expect(globals.$).toBeDefined();+ expect(globals.$).toBe(globals.jQuery);+ expect(document.documentElement.classList.contains("app-view-shown")).toBe(true);+ });++ it("shows the content when the view fails to mount, in the default locale", async () => {+ vi.stubGlobal("glob", undefined);+ renderPage({ locale: null });++ await expect(setupAppView(".share-note-view", async () => ({+ default: () => { throw new Error("mount failed"); }+ }))).rejects.toThrow("mount failed");++ expect(initLocale).toHaveBeenCalledWith("en");+ expect(document.documentElement.classList.contains("app-view-shown")).toBe(true);+ });+});++function renderPage(options: AppPayload["options"]) {+ const payload: Partial<AppPayload> = { options, assetPath: "assets/v1" };+ document.body.innerHTML = `<div id="content">+ <div class="share-note-view"></div>+ <script type="application/json" class="share-froca">${JSON.stringify(payload)}</script>+ </div>`;+ return document.querySelector(".share-note-view");+}diff --git a/packages/share-theme/src/content/collection_view.spec.tsx b/packages/share-theme/src/content/collection_view.spec.tsxnew file mode 100644index 0000000000..b81ffd1786--- /dev/null+++ b/packages/share-theme/src/content/collection_view.spec.tsx@@ -0,0 +1,41 @@+// @vitest-environment happy-dom+import type { ComponentChildren } from "preact";+import { act } from "preact/test-utils";+import { describe, expect, it, vi } from "vitest";++import type { AppPayload, HostedApp } from "./app_host.js";+import mountCollection from "./collection_view.js";++const { openNote, noteList } = vi.hoisted(() => ({+ openNote: vi.fn(),+ noteList: vi.fn(() => null)+}));++vi.mock("@triliumnext/client/src/widgets/collections/NoteList.js", () => ({+ EmbeddedNoteList: noteList+}));+vi.mock("./app_host.js", () => ({+ default: ({ noteId, children }: {+ noteId: string;+ children(app: HostedApp): ComponentChildren;+ }) =>+ children({ note: { noteId }, openNote } as unknown as HostedApp)+}));++describe("mountCollection", () => {+ it("mounts the app's note list over the collection, opening notes on their pages", () => {+ const container = document.createElement("div");+ container.dataset.noteId = "books";++ act(() => mountCollection(container, {} as AppPayload));++ expect(noteList).toHaveBeenCalledWith(expect.objectContaining({+ note: { noteId: "books" }, notePath: "books", ntxId: null, onOpenNote: openNote+ }), expect.anything());++ delete container.dataset.noteId;+ act(() => mountCollection(container, {} as AppPayload));+ expect(noteList).toHaveBeenLastCalledWith(+ expect.objectContaining({ note: { noteId: "" } }), expect.anything());+ });+});diff --git a/packages/share-theme/src/content/note_view.spec.tsx b/packages/share-theme/src/content/note_view.spec.tsxindex 9899ca5e66..d74637e8be 100644--- a/packages/share-theme/src/content/note_view.spec.tsx+++ b/packages/share-theme/src/content/note_view.spec.tsx@@ -1,69 +1,188 @@// @vitest-environment happy-dom-import type { ComponentChildren } from "preact";+import { type ComponentChildren, render } from "preact";import { act } from "preact/test-utils";import { afterEach, describe, expect, it, vi } from "vitest";import type { AppPayload, HostedApp } from "./app_host.js";import mountNoteView from "./note_view.js";-const { loadCodeView } = vi.hoisted(() => ({ loadCodeView: vi.fn() }));+const mocks = vi.hoisted(() => ({+ loadCodeView: vi.fn(),+ useNoteBlob: vi.fn(),+ openNote: vi.fn(),+ drawMermaid: vi.fn(),+ noteMap: vi.fn(() => null),+ relationMap: vi.fn(() => null)+}));// The real modules reach `window.glob`, which only the app's boot script defines.vi.mock("@triliumnext/client/src/services/i18n.js", () => ({ t: (key: string) => key }));-vi.mock("@triliumnext/client/src/widgets/react/hooks.js", () => ({ useNoteBlob: () => null }));+vi.mock("@triliumnext/client/src/services/image_urls.js", () => ({+ getNoteImageUrl: (noteId: string, title: string, blobId: string) =>+ `api/images/${noteId}/${title}?${blobId}`+}));+vi.mock("@triliumnext/client/src/widgets/react/hooks.js", () => ({+ useNoteBlob: mocks.useNoteBlob+}));+vi.mock("@triliumnext/client/src/widgets/react/RawHtml.js", () => ({+ RawHtmlBlock: ({ className, html }: { className: string; html: string }) =>+ <div className={className} data-html={html} />+}));vi.mock("@triliumnext/client/src/widgets/note_types.js", () => ({- TYPE_MAPPINGS: { code: { view: loadCodeView, className: "note-detail-code" } }+ TYPE_MAPPINGS: { code: { view: mocks.loadCodeView, className: "note-detail-code" } }+}));+vi.mock("@triliumnext/client/src/widgets/note_map/NoteMap.js", () => ({ default: mocks.noteMap }));+vi.mock("@triliumnext/client/src/widgets/type_widgets/relation_map/RelationMap.js", () => ({+ default: mocks.relationMap+}));+vi.mock("mermaid", () => ({ default: {} }));+vi.mock("./mermaid.js", () => ({+ loadMermaid: async () => ({}),+ drawMermaid: mocks.drawMermaid,+ readMermaidTheme: () => document.documentElement.className || "default"+}));+vi.mock("./zoom_viewer.js", () => ({+ ZoomViewer: ({ label, children }: { label: string; children?: ComponentChildren }) =>+ <div className="zoom-viewer" aria-label={label}>{children}</div>}));-vi.mock("./app_host.js", () => ({- default: ({ noteId, children }: {+ default: ({ noteId, payload, children }: {noteId: string;+ payload: AppPayload;children(app: HostedApp): ComponentChildren;- }) =>- children({ note: { noteId, type: "code" }, parentNoteId: null } as unknown as HostedApp)+ }) => children({+ note: payload.notes.find((note) => note.noteId === noteId),+ parentNoteId: "parent",+ openNote: mocks.openNote+ } as unknown as HostedApp)}));+const containers: HTMLElement[] = [];+describe("mountNoteView", () => {afterEach(() => {+ for (const container of containers.splice(0)) {+ act(() => render(null, container));+ }document.body.replaceChildren();- loadCodeView.mockReset();+ document.documentElement.className = "";+ vi.clearAllMocks();+ vi.restoreAllMocks();});it("replaces the rendered content with the note's widget once the widget loads", async () => {- loadCodeView.mockResolvedValue({ default: () => <p className="widget">Widget</p> });- const container = buildContainer();+ mocks.loadCodeView.mockResolvedValue({ default: () => <p className="widget">Widget</p> });+ const container = buildContainer("code");- await act(() => mountNoteView(container, buildPayload()));+ await act(() => mountNoteView(container, buildPayload("code")));expect(container.querySelector(".note-detail-code > p.widget")?.textContent).toBe("Widget");expect(container.querySelector("p.fallback")).toBeNull();++ // A widget module can be the component itself.+ mocks.loadCodeView.mockResolvedValue(() => <p className="bare">Bare</p>);+ await act(() => mountNoteView(container, buildPayload("code")));+ expect(container.querySelector(".note-detail-code > p.bare")).not.toBeNull();});- it("keeps the rendered content when the widget fails to load", async () => {- loadCodeView.mockRejectedValue(new Error("Failed to fetch dynamically imported module"));- const container = buildContainer();+ it("keeps the rendered content when the widget fails to load or no note is named", async () => {+ mocks.loadCodeView.mockRejectedValue(+ new Error("Failed to fetch dynamically imported module"));+ const container = buildContainer("code");await act(async () => {- await expect(mountNoteView(container, buildPayload()))+ await expect(mountNoteView(container, buildPayload("code"))).rejects.toThrow("Failed to fetch");});+ delete container.dataset.noteId;+ await act(async () => {+ await expect(mountNoteView(container, buildPayload("code"))).rejects.toThrow();+ });expect(container.querySelector("p.fallback")?.textContent).toBe("Rendered");expect(container.querySelector(".note-detail-code")).toBeNull();});++ it("shows an image, a canvas or a mind map in the pan and zoom viewer", async () => {+ for (const type of [ "image", "canvas", "mindMap" ]) {+ const container = buildContainer(type);++ await act(() => mountNoteView(container, buildPayload(type)));++ const image = container.querySelector(".zoom-viewer img");+ expect(image?.getAttribute("src"), type).toBe(`api/images/${type}Note/Title?blob`);+ expect(image?.getAttribute("alt")).toBe("Title");+ }+ });++ it("draws a Mermaid note, again when the theme changes, and not once unmounted", async () => {+ mocks.useNoteBlob.mockReturnValue({ content: "graph TD; A-->B" });+ mocks.drawMermaid.mockImplementation(+ async (_mermaid, source, theme) => `<svg>${source} ${theme}</svg>`);+ const container = buildContainer("mermaid");++ await act(() => mountNoteView(container, buildPayload("mermaid")));+ const drawn = () => container.querySelector(".mermaid")?.getAttribute("data-html");+ await vi.waitFor(() => expect(drawn()).toBe("<svg>graph TD; A-->B default</svg>"));++ await act(async () => { document.documentElement.className = "dark"; });+ await vi.waitFor(() => expect(drawn()).toBe("<svg>graph TD; A-->B dark</svg>"));++ let finishDrawing = (_svg: string) => {};+ mocks.drawMermaid.mockReturnValue(new Promise((resolve) => { finishDrawing = resolve; }));+ await act(async () => { document.documentElement.className = "light"; });+ act(() => render(null, container));+ finishDrawing("<svg>late</svg>");+ expect(mocks.drawMermaid).toHaveBeenLastCalledWith({}, "graph TD; A-->B", "light");+ });++ it("draws nothing for a Mermaid note without content and logs a failed drawing", async () => {+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});+ mocks.useNoteBlob.mockReturnValue(null);+ const container = buildContainer("mermaid");++ await act(() => mountNoteView(container, buildPayload("mermaid")));+ expect(mocks.drawMermaid).not.toHaveBeenCalled();++ mocks.useNoteBlob.mockReturnValue({ content: "graph TD; broken" });+ mocks.drawMermaid.mockRejectedValue(new Error("Parse error"));+ await act(() => mountNoteView(buildContainer("mermaid"), buildPayload("mermaid")));++ await vi.waitFor(() => expect(consoleError).toHaveBeenCalledWith(new Error("Parse error")));+ expect(container.querySelector(".mermaid")).toBeNull();+ });++ it("draws a note map and a relation map, opening notes on their pages", async () => {+ await act(() => mountNoteView(buildContainer("noteMap"), buildPayload("noteMap")));+ await act(() => mountNoteView(buildContainer("relationMap"), buildPayload("relationMap")));++ expect(mocks.noteMap).toHaveBeenCalledWith(expect.objectContaining({+ note: expect.objectContaining({ noteId: "noteMapNote" }),+ widgetMode: "type",+ defaultRootNoteId: "parent",+ onOpenNote: mocks.openNote+ }), expect.anything());+ expect(mocks.relationMap).toHaveBeenCalledWith(expect.objectContaining({+ note: expect.objectContaining({ noteId: "relationMapNote" }),+ onOpenNote: mocks.openNote+ }), expect.anything());+ expect(document.querySelector(".note-detail-note-map")).not.toBeNull();+ expect(document.querySelector(".note-detail-relation-map")).not.toBeNull();+ });});-function buildContainer() {+function buildContainer(type: string) {const container = document.createElement("div");- container.dataset.noteId = "codeNote";+ container.dataset.noteId = `${type}Note`;container.innerHTML = `<p class="fallback">Rendered</p>`;document.body.append(container);+ containers.push(container);return container;}-function buildPayload() {+function buildPayload(type: string) {return {- notes: [ { noteId: "codeNote", type: "code" } ],+ notes: [ { noteId: `${type}Note`, type, title: "Title", blobId: "blob" } ],branches: [],attributes: [],links: {},diff --git a/packages/share-theme/src/content/share_froca_source.spec.ts b/packages/share-theme/src/content/share_froca_source.spec.tsindex 30ab2d9c10..21365b50fc 100644--- a/packages/share-theme/src/content/share_froca_source.spec.ts+++ b/packages/share-theme/src/content/share_froca_source.spec.ts@@ -17,6 +17,41 @@ describe("createShareFrocaSource", () => {await source.loadNotes([ "aliased" ]);expect(source.getNoteLink("aliased")).toBe("./nice-name");});++ it("reads what froca lacks from the share's API, relative to the page", async () => {+ const fetch = vi.fn(async (url: string) => Response.json(url.startsWith("api/notes?")+ ? { results: [ { noteId: "found" } ] }+ : { url }));+ vi.stubGlobal("fetch", fetch);+ const source = createShareFrocaSource({});++ await source.getSiblingAttachments("att 1");+ await source.getAttachments("note 1");+ await source.getBlob("notes", "note 1");+ expect(await source.searchNoteIds("tag", "root")).toEqual([ "found" ]);+ await source.saveAttachment("note 1", {} as never);+ await source.removeAttachment("att 1");+ await source.searchInSubtree("#done", "root");+ await source.getAttributeNames("label", "do");+ await source.lintSearch("#done");+ await source.getNoteMap("map 1", "link",+ { excludeRelations: [ "template" ], includeRelations: [ "author" ] });+ await source.getRelationMap("rel 1", []);+ await source.getScriptBundle("script 1");++ expect(fetch.mock.calls.map(([ url ]) => url)).toEqual([+ "api/attachments/att%201/all",+ "api/notes/note%201/attachments",+ "api/notes/note%201/blob",+ "api/notes?search=tag&ancestorNoteId=root",+ "api/search?searchString=%23done&ancestorNoteId=root",+ "api/attribute-names?type=label&query=do",+ "api/search/lint?searchString=%23done",+ "api/note-map/map%201/link?excludeRelation=template&includeRelation=author",+ "api/relation-map/rel%201",+ "api/script/bundle/script%201"+ ]);+ });});describe("createStaticFrocaSource", () => {diff --git a/packages/share-theme/src/index.spec.ts b/packages/share-theme/src/index.spec.tsindex 6e47fab8b7..ad7579213d 100644--- a/packages/share-theme/src/index.spec.ts+++ b/packages/share-theme/src/index.spec.ts@@ -16,7 +16,8 @@ const mocks = vi.hoisted(() => ({setupMermaid: vi.fn(),applyTabs: vi.fn(),revealFragment: vi.fn(),- enhanceLinkPreviews: vi.fn()+ enhanceLinkPreviews: vi.fn(),+ setupAppView: vi.fn()}));vi.mock("./page/layout.js", () => ({ default: mocks.setupLayout }));@@ -31,6 +32,9 @@ vi.mock("./page/speculation.js", () => ({}));vi.mock("./content/math.js", () => ({ default: mocks.setupMath }));vi.mock("./content/mermaid.js", () => ({ default: mocks.setupMermaid }));+vi.mock("./content/app_view.js", () => ({ default: mocks.setupAppView }));+vi.mock("./content/note_view.js", () => ({ default: "mountNoteView" }));+vi.mock("./content/collection_view.js", () => ({ default: "mountCollection" }));vi.mock("@triliumnext/ckeditor5/src/plugins/tabs/tabs_read_only.js", () => ({applyTabs: mocks.applyTabs,revealFragment: mocks.revealFragment@@ -122,6 +126,22 @@ describe("share theme entry", () => {expect(mocks.applyTabs).not.toHaveBeenCalled();});+ it("mounts the app view of a hosted note or a collection with its own module", async () => {+ const mountedModules = async () => Promise.all(mocks.setupAppView.mock.calls+ .map(async ([ container, load ]) => [ container, (await load()).default ]));++ document.body.className = "type-noteMap";+ document.body.innerHTML = `<div id="content"><div class="share-note-view"></div></div>`;+ document.dispatchEvent(new Event("DOMContentLoaded"));+ expect(await mountedModules()).toEqual([ [ ".share-note-view", "mountNoteView" ] ]);++ mocks.setupAppView.mockClear();+ document.body.className = "type-book";+ document.body.innerHTML = `<div id="content"></div>`;+ document.dispatchEvent(new Event("DOMContentLoaded"));+ expect(await mountedModules()).toEqual([ [ ".share-collection", "mountCollection" ] ]);+ });+it("draws a Mermaid note's diagram and leaves other notes alone", () => {document.body.className = "type-mermaid";document.dispatchEvent(new Event("DOMContentLoaded"));