Add ~330 tests across server (Jest), client (Vitest), editor-ext (Vitest)
and packages/mcp (node:test) for the gitmost features added since
053a9c0d: AI chat, AI agent roles, public-share assistant, MCP per-user
auth, HTML embed, page templates/embed, realtime tree, tree
expand/collapse, and the AI-settings UI.
Test-tooling fixes (prerequisite, were silently hiding coverage):
- Repair 3 page-template specs broken by the 11-arg TransclusionService
constructor; they never compiled, so template access-control / content
-leak / unsync-strip coverage was fictitious.
- Build @docmost/editor-ext before server tests via a `pretest` hook;
the stale dist omitted the new HtmlEmbed/PageEmbed exports (TS2305).
- Let jest resolve the .tsx email templates: add `tsx` to
moduleFileExtensions and widen the ts-jest transform to (t|j)sx?.
Behaviour-preserving "extract pure core" refactors that the tests drive:
- server: resolveShareAssistantRequest + uiMessageTextLength
(public-share controller), decideBasicGate + mapAuthResultToResponse
(mcp), buildErrorAssistantRecord (ai-chat), jsonbObject export (roles).
- client: render-raw-html + shouldExecute/canEdit, decide-embed-state,
page-embed picker utils, tree-socket reducers, open/close branch maps,
isEndpointConfigured/resolveKeyField; buildTreeWithChildren now treats
a permission-trimmed orphan as a root instead of crashing.
Deferred (need a test DB or HTTP harness, documented in the specs):
repo-level Postgres integration tests and the public-share XFF E2E.
Pre-existing DI/lib0-ESM suite failures are untouched and out of scope.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { render } from "@testing-library/react";
|
|
import {
|
|
PageEmbedAncestryProvider,
|
|
usePageEmbedAncestry,
|
|
} from "./page-embed-ancestry-context";
|
|
|
|
// Probe child: renders the current ancestry context value as JSON so the test
|
|
// can assert on the accumulated chain and host without any Tiptap editor.
|
|
function Probe({ testId }: { testId: string }) {
|
|
const ancestry = usePageEmbedAncestry();
|
|
return <div data-testid={testId}>{JSON.stringify(ancestry)}</div>;
|
|
}
|
|
|
|
function read(el: HTMLElement) {
|
|
return JSON.parse(el.textContent || "{}") as {
|
|
chain: string[];
|
|
hostPageId: string | null;
|
|
};
|
|
}
|
|
|
|
describe("PageEmbedAncestryProvider", () => {
|
|
it("accumulates the chain in order across nested providers", () => {
|
|
const { getByTestId } = render(
|
|
<PageEmbedAncestryProvider sourcePageId="a" hostPageId="host">
|
|
<PageEmbedAncestryProvider sourcePageId="b">
|
|
<PageEmbedAncestryProvider sourcePageId="c">
|
|
<Probe testId="leaf" />
|
|
</PageEmbedAncestryProvider>
|
|
</PageEmbedAncestryProvider>
|
|
</PageEmbedAncestryProvider>,
|
|
);
|
|
const value = read(getByTestId("leaf"));
|
|
expect(value.chain).toEqual(["a", "b", "c"]);
|
|
expect(value.hostPageId).toBe("host");
|
|
});
|
|
|
|
it("leaves the chain unchanged when sourcePageId is absent, still propagating the host", () => {
|
|
const { getByTestId } = render(
|
|
<PageEmbedAncestryProvider sourcePageId="a" hostPageId="host">
|
|
<PageEmbedAncestryProvider>
|
|
<Probe testId="leaf" />
|
|
</PageEmbedAncestryProvider>
|
|
</PageEmbedAncestryProvider>,
|
|
);
|
|
const value = read(getByTestId("leaf"));
|
|
expect(value.chain).toEqual(["a"]);
|
|
expect(value.hostPageId).toBe("host");
|
|
});
|
|
|
|
it("keeps the first (top-level) host even if an inner provider passes a different one", () => {
|
|
const { getByTestId } = render(
|
|
<PageEmbedAncestryProvider sourcePageId="a" hostPageId="top-host">
|
|
<PageEmbedAncestryProvider sourcePageId="b" hostPageId="inner-host">
|
|
<Probe testId="leaf" />
|
|
</PageEmbedAncestryProvider>
|
|
</PageEmbedAncestryProvider>,
|
|
);
|
|
const value = read(getByTestId("leaf"));
|
|
expect(value.chain).toEqual(["a", "b"]);
|
|
// Inner host is ignored: the top-level host is set once and propagated.
|
|
expect(value.hostPageId).toBe("top-host");
|
|
});
|
|
|
|
it("defaults to an empty chain and null host with no provider", () => {
|
|
const { getByTestId } = render(<Probe testId="leaf" />);
|
|
const value = read(getByTestId("leaf"));
|
|
expect(value.chain).toEqual([]);
|
|
expect(value.hostPageId).toBeNull();
|
|
});
|
|
});
|