4-10 树域 Rust 家族化

This commit is contained in:
lix-2026
2026-04-24 06:10:18 +08:00
parent 41e958769e
commit 94631f3636
49 changed files with 5751 additions and 557 deletions
@@ -39,12 +39,14 @@ vi.mock("@tanstack/react-query", () => ({
},
}));
const mockUseDocumentSearch = vi.fn(() => ({
data: null,
isLoading: false,
error: null,
}));
vi.mock("@/hooks/use-document-search", () => ({
useDocumentSearch: () => ({
data: null,
isLoading: false,
error: null,
}),
useDocumentSearch: (...args: unknown[]) => mockUseDocumentSearch(...args),
}));
vi.mock("@/components/ui/dialog", () => ({
@@ -100,6 +102,13 @@ describe("MoveEmbedPickerDialog", () => {
});
container.remove();
vi.clearAllMocks();
mockUseDocumentSearch.mockReset();
mockUseDocumentSearch.mockReturnValue({
data: null,
isLoading: false,
error: null,
});
delete window.__MNOTE_RUNTIME_CONFIG__;
});
it("空查询时会使用统一 picker surface 并透传根目录选择", async () => {
@@ -131,4 +140,130 @@ describe("MoveEmbedPickerDialog", () => {
expect(onPick).toHaveBeenCalledWith("move", null);
expect(onOpenChange).toHaveBeenCalledWith(false);
});
it("搜索结果也应继续复用统一 picker surface", async () => {
mockUseDocumentSearch.mockReturnValue({
data: {
results: [
{
id: "doc_target",
title: "目标页面",
matchField: "title",
},
],
},
isLoading: false,
error: null,
});
const onPick = vi.fn(async () => undefined);
const onOpenChange = vi.fn();
await act(async () => {
root.render(
<MoveEmbedPickerDialog
open
onOpenChange={onOpenChange}
workspaceId="ws_test"
defaultMode="move"
allowRoot
excludeIds={[]}
onPick={onPick}
/>,
);
});
const input = container.querySelector("input");
expect(input).not.toBeNull();
await act(async () => {
input?.dispatchEvent(new Event("input", { bubbles: true }));
Object.defineProperty(input as HTMLInputElement, "value", {
configurable: true,
value: "目标",
});
input?.dispatchEvent(new Event("change", { bubbles: true }));
});
const pickerSurface = container.querySelector('[data-testid="tree-picker-surface"]');
const pickerRows = container.querySelectorAll('[data-testid="tree-picker-row"]');
expect(pickerSurface).not.toBeNull();
expect(pickerRows).toHaveLength(1);
await act(async () => {
pickerRows[0]?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
});
expect(onPick).toHaveBeenCalledWith("move", "doc_target");
expect(onOpenChange).toHaveBeenCalledWith(false);
});
it("rust_family 配置下,picker 空态与结果态都应进入统一 host", async () => {
window.__MNOTE_RUNTIME_CONFIG__ = {
treeRendererFamily: "rust_family",
};
const onPick = vi.fn(async () => undefined);
const onOpenChange = vi.fn();
await act(async () => {
root.render(
<MoveEmbedPickerDialog
open
onOpenChange={onOpenChange}
workspaceId="ws_test"
defaultMode="move"
allowRoot
excludeIds={[]}
onPick={onPick}
/>,
);
});
const emptySurface = container.querySelector('[data-testid="tree-picker-surface"]');
expect(emptySurface?.getAttribute("data-tree-host-kind")).toBe("rust_family");
expect(emptySurface?.getAttribute("data-tree-host-implementation")).toBe("mnote_web_iframe_proxy");
expect(
container.querySelector('[data-testid="tree-picker-surface-rust-host"]'),
).not.toBeNull();
expect(
container.querySelector('[data-testid="tree-picker-surface-rust-iframe"]'),
).not.toBeNull();
mockUseDocumentSearch.mockReturnValue({
data: {
results: [
{
id: "doc_target",
title: "目标页面",
matchField: "title",
},
],
},
isLoading: false,
error: null,
});
const input = container.querySelector("input");
expect(input).not.toBeNull();
await act(async () => {
Object.defineProperty(input as HTMLInputElement, "value", {
configurable: true,
value: "目标",
});
input?.dispatchEvent(new Event("input", { bubbles: true }));
input?.dispatchEvent(new Event("change", { bubbles: true }));
});
const resultSurface = container.querySelector('[data-testid="tree-picker-surface"]');
expect(resultSurface?.getAttribute("data-tree-host-kind")).toBe("rust_family");
expect(resultSurface?.getAttribute("data-tree-host-implementation")).toBe("mnote_web_iframe_proxy");
expect(
container.querySelector('[data-testid="tree-picker-surface-rust-host"]'),
).not.toBeNull();
expect(
container.querySelector('[data-testid="tree-picker-surface-rust-iframe"]'),
).not.toBeNull();
});
});