/** * FZ-9012. Every arrowhead ends at the target port's outer edge, outside its * ring AND outside the node body. * * React Flow ends a path at the handle box's outer edge (`getHandlePosition`, * `center: false`), and `GraphEdge` draws the head back from that point * (`edgeArrowhead`). Edges paint UNDER nodes, so a head that lands inside the * frame is painted over by the node's own surface. That is what happened while * the port rows sat inside the frame's padding: the disc centred `padding` px * in from the edge, and the head fell on the node body. * * happy-dom does no layout, so the port centre is summed from the emitted * declarations: the frame's left border and padding, plus the port anchor's * `left` offset. `handleGeometry.portGeometry` gives the handle box around it. */ import { panelPaddingPx, Preset, Surface, useResolvedKnobs } from "@multiplatform.one/theme"; import { renderWithProviders } from "@multiplatform.one/test-utils"; import { cleanup } from "@testing-library/react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { declarationFor } from "../../tests/styles"; import { edgeArrowheadLength, edgeStrokeWidth } from "../edges/edgeStyle"; import type { GraphNodePort } from "./nodeMeasure"; import { paintedPortSizePx, portGeometry } from "./handleGeometry"; vi.mock("../react-flow/xy", async (importOriginal) => { const actual = await importOriginal(); return { ...actual, useUpdateNodeInternals: () => vi.fn() }; }); const { GraphNode } = await import("./GraphNode"); afterEach(cleanup); const inPort: GraphNodePort[] = [{ id: "in", side: "left", direction: "in", label: "rows" }]; function renderNode() { const captured = { border: 0, padding: "" }; function Probe() { const { knobProps } = useResolvedKnobs({ component: "GraphNode" }); captured.border = Number(knobProps.surface.borderWidth ?? 0); captured.padding = knobProps.panelPadding.padding; return null; } const { container } = renderWithProviders( } /> , ); const frame = container.querySelector("[data-graph-node]") as HTMLElement; const anchor = container.querySelector('[data-graph-node-port-anchor="left"]'); const px = (declaration: string | undefined): number => { if (!declaration) return 0; const token = declaration.match(/^var\(--(?:[ct]-)?space-(\d+(?:-\d+)?)\)$/); if (token) { expect(token[1], "the frame pads by the panelPadding role").toBe(captured.padding); return panelPaddingPx(); } return Number.parseFloat(declaration); }; return { border: captured.border, framePad: px(declarationFor(frame, "padding-left")), anchorLeft: anchor ? px(declarationFor(anchor, "left")) : 0, }; } describe("FZ-9012: the arrowhead lands outside the port ring and the node body", () => { it("centres a port on the frame's padding edge (design ยง7.1 H6)", () => { const { framePad, anchorLeft } = renderNode(); expect(framePad, "the frame pads its content").toBeGreaterThan(0); expect(framePad + anchorLeft).toBe(0); }); it("keeps the whole head off the node body, at every port size and edge stroke", () => { const { border, framePad, anchorLeft } = renderNode(); const centreX = border + framePad + anchorLeft; for (const painted of Object.values(paintedPortSizePx)) { const { box } = portGeometry({ painted, hit: painted, side: "left", nodeWidth: 160, nodeHeight: 80, offset: 40, }); // The path's end, and so the head's tip, for a left target: the handle // box's left edge, which is the outside of the painted ring. const tip = centreX + box.x; for (const stop of ["none", "small", "medium", "large"] as const) { for (const weight of ["value", "control"] as const) { const tail = tip - edgeArrowheadLength(edgeStrokeWidth(stop, weight)); const label = `painted ${painted}, ${stop} ${weight}`; expect(tip, `${label}: the tip lands on the node body`).toBeLessThan(0); expect(tail, `${label}: the head runs into the ring`).toBeLessThan(tip); } } } }); });