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>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { excludeHost, buildPickerQuery } from "./page-embed-picker.utils";
|
|
import type { IPage } from "@/features/page/types/page.types";
|
|
|
|
function page(id: string): IPage {
|
|
return { id, title: id, slugId: `slug-${id}` } as IPage;
|
|
}
|
|
|
|
describe("excludeHost", () => {
|
|
it("drops the host page from the results (self-embed guard)", () => {
|
|
const result = excludeHost([page("a"), page("host"), page("b")], "host");
|
|
expect(result.map((p) => p.id)).toEqual(["a", "b"]);
|
|
});
|
|
|
|
it("returns all pages when hostPageId is undefined", () => {
|
|
const result = excludeHost([page("a"), page("b")], undefined);
|
|
expect(result.map((p) => p.id)).toEqual(["a", "b"]);
|
|
});
|
|
|
|
it("drops null/blank entries", () => {
|
|
const result = excludeHost(
|
|
[page("a"), null as unknown as IPage, page("b")],
|
|
"host",
|
|
);
|
|
expect(result.map((p) => p.id)).toEqual(["a", "b"]);
|
|
});
|
|
});
|
|
|
|
describe("buildPickerQuery", () => {
|
|
it("passes onlyTemplates:true with the query and page inclusion", () => {
|
|
expect(buildPickerQuery("foo")).toEqual({
|
|
query: "foo",
|
|
includePages: true,
|
|
onlyTemplates: true,
|
|
limit: 20,
|
|
});
|
|
});
|
|
|
|
it("preserves an empty query", () => {
|
|
expect(buildPickerQuery("").query).toBe("");
|
|
expect(buildPickerQuery("").onlyTemplates).toBe(true);
|
|
});
|
|
});
|