import { expect, test } from "bun:test"; import { readFileSync } from "node:fs"; const component = readFileSync(new URL("../src/components/canvas/canvas-workspace-overlays.tsx", import.meta.url), "utf8"); const css = readFileSync(new URL("../src/styles/globals.css", import.meta.url), "utf8"); test("connection menu omits the header and provides descriptions for every option", () => { expect(component).not.toContain("引用当前节点"); expect(component).not.toContain(">创建下一步"); expect(component).not.toContain("ChevronRight"); expect(component).not.toContain("absolute inset-x-8 top-0 h-px"); const options = component.match(//g) || []; expect(options).toHaveLength(9); for (const option of options) expect(option).toMatch(/description="[^"]+"/); expect(component).toContain('title="批量创作表"'); expect(component).toContain("onCreate(CanvasNodeType.BatchTable)"); }); test("add-node submenu uses a four-column medium-size grid", () => { const menu = readFileSync(new URL("../src/components/canvas/canvas-create-menu.tsx", import.meta.url), "utf8"); const context = readFileSync(new URL("../src/components/canvas/canvas-context-menu.tsx", import.meta.url), "utf8"); const styles = readFileSync(new URL("../src/styles/globals.css", import.meta.url), "utf8"); expect(menu).toContain('variant === "node" ? "grid-cols-4"'); expect(menu).toContain("size-6 shrink-0"); expect(context).toContain('w-[360px]'); expect(styles).toContain("--canvas-create-node-height: var(--space-16)"); }); test("only the active option expands; stationary pointer retargeting cannot switch rows", () => { const descriptionRule = css.match(/\.canvas-connection-create-description \{([^}]+)\}/)?.[1] || ""; expect(descriptionRule).toContain("grid-template-rows: 0fr"); expect(descriptionRule).not.toContain("min-height"); const option = component.slice(component.indexOf("function ConnectionCreateOption("), component.indexOf("function clamp(")); expect(option).not.toContain("motion.button"); expect(css).toContain('.canvas-connection-create-option[data-expanded="true"]'); expect(component).toContain("previous?.x === event.clientX && previous.y === event.clientY"); expect(component).not.toContain("SpotlightSurface"); expect(css).toContain('.canvas-connection-create-option[data-motion="reduced"]'); expect(component).toContain('aria-disabled={Boolean(disabledReason)}'); expect(component).toContain("if (!disabledReason) onClick()"); expect(component).toContain('event.key === "Escape"'); });