fix(canvas): 提示词优化器 - 隔离多实例浮层定位并修复路由预加载测试

This commit is contained in:
ddCat
2026-08-25 14:33:34 +08:00
parent 5b7f173102
commit 0cbe24a19f
4 changed files with 23 additions and 7 deletions

View File

@@ -0,0 +1,14 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
const source = readFileSync(resolve(import.meta.dir, "../src/components/canvas/canvas-prompt-optimizer-drawer.tsx"), "utf8");
describe("prompt optimizer drawer instance isolation", () => {
test("resolves the popover from the current drawer content instead of the first global match", () => {
expect(source).toContain("const contentRef = useRef<HTMLDivElement | null>(null);");
expect(source).toContain('contentRef.current?.closest<HTMLElement>(".canvas-prompt-optimizer-popover")');
expect(source).toContain('<div ref={contentRef} className={`canvas-prompt-optimizer-panel');
expect(source).not.toContain('document.querySelector<HTMLElement>(".canvas-prompt-optimizer-popover")');
});
});

View File

@@ -19,13 +19,14 @@ describe("workspace route loading", () => {
test("preloads the reported workspace routes before navigation", () => {
const modules = source("../src/lib/workspace-route-modules.ts");
const navigation = source("../src/components/layout/app-top-nav.tsx");
const navigation = source("../src/components/layout/workspace-sidebar-nav.tsx");
for (const route of ["projects", "canvas", "assets", "wallet", "create"]) {
expect(modules).toContain(`${route}: () => import`);
}
expect(navigation).toContain("onPointerEnter={() => preloadWorkspaceRoute(tool.slug)}");
expect(navigation).toContain("onFocus={() => preloadWorkspaceRoute(tool.slug)}");
expect(navigation).toContain("onPointerEnter={() => preloadWorkspaceRoute(linkTo)}");
expect(navigation).toContain("onPointerDown={() => preloadWorkspaceRoute(linkTo)}");
expect(navigation).toContain("onFocus={() => preloadWorkspaceRoute(linkTo)}");
});
test("uses a quiet workspace skeleton for initial hydration", () => {