Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
62af299
refactor(graph): replace client-side graph builder with server-side BFS
damienriehl Apr 7, 2026
5bab29e
fix(graph): address review findings for entity graph PR
JohnRDOrazio Apr 10, 2026
8c119a4
fix(graph): update stale PLAN.md references and clear graph on empty …
JohnRDOrazio Apr 10, 2026
80af048
fix(tests): update graph tests for server-side BFS refactor
JohnRDOrazio Apr 10, 2026
5342494
test(graph): add missing tests for EntityGraphModal, graph API, and E…
JohnRDOrazio Apr 10, 2026
7116f5f
fix: add type assertion for mock call args in graph API tests
JohnRDOrazio Apr 11, 2026
4e46f9a
test: improve coverage for EntityGraphModal and useGraphData
JohnRDOrazio Apr 11, 2026
4f1ec91
test: add OntologyGraph callback and MiniMap coverage tests
JohnRDOrazio Apr 11, 2026
485d7e6
fix: correct entity graph API URL to match backend route
JohnRDOrazio Apr 11, 2026
3a9b686
fix: use Math.max for total_concept_count in graph merge
JohnRDOrazio Apr 11, 2026
218bcc1
fix: pass class_iri as query param for graph endpoint
JohnRDOrazio Apr 11, 2026
29fcad7
fix: pass auth token to entity graph API calls
JohnRDOrazio Apr 11, 2026
484e1cf
fix: swap source/target handle positions on graph nodes
JohnRDOrazio Apr 11, 2026
9af8ce3
fix: use React Flow built-in markers and add edge style toggle
JohnRDOrazio Apr 11, 2026
0544569
fix: use descendants toggle state in expandNode instead of hardcoding…
JohnRDOrazio Apr 11, 2026
d6b5ea2
fix: add accessToken to useEffect dependency array in useGraphData
JohnRDOrazio Apr 11, 2026
5d9fd53
fix: validate node_type at runtime instead of blind cast in useELKLayout
JohnRDOrazio Apr 11, 2026
a96d41b
test: strengthen OntologyEdge default style assertions and remove dup…
JohnRDOrazio Apr 11, 2026
c9802eb
test: add bezier edge style coverage for OntologyEdge
JohnRDOrazio Apr 11, 2026
c5b9855
fix: guard expandNode against stale results after focus/reset changes
JohnRDOrazio Apr 11, 2026
49fccd1
refactor: replace manual fetch lifecycle with React Query in useGraph…
JohnRDOrazio Apr 11, 2026
599372e
fix: resolve lint errors in useGraphData and test wrapper
JohnRDOrazio Apr 11, 2026
9ad334f
fix: reset expansions on graph context change, not on background refetch
JohnRDOrazio Apr 11, 2026
c207ad9
feat: show one level of descendants by default in graph view
JohnRDOrazio Apr 11, 2026
2f31314
fix: use useLayoutEffect for epoch reset to prevent stale expansion m…
JohnRDOrazio Apr 11, 2026
28536e7
fix: clear React Flow nodes/edges when graphData is null or empty
JohnRDOrazio Apr 11, 2026
a5b913f
refactor: remove duplicate expandedNodes tracking from OntologyGraph
JohnRDOrazio Apr 11, 2026
f1ef029
fix: log ELK layout errors instead of silently swallowing them
JohnRDOrazio Apr 11, 2026
60e8899
fix: add click-delay guard to distinguish single click from double click
JohnRDOrazio Apr 11, 2026
ecab724
test: add isLayouting spinner and accessToken forwarding tests
JohnRDOrazio Apr 11, 2026
7ecb179
fix: require accessToken before firing entity graph query
JohnRDOrazio Apr 12, 2026
abec074
fix: use layout-aware handle positions on graph nodes
JohnRDOrazio Apr 12, 2026
1cc1422
fix: validate edge_type at runtime instead of blind cast in useELKLayout
JohnRDOrazio Apr 12, 2026
313ab1f
perf: lazy-load EntityGraphModal to reduce main bundle size
JohnRDOrazio Apr 12, 2026
c8be8e7
test: properly observe isLayouting state during ELK layout computation
JohnRDOrazio Apr 12, 2026
3ece951
feat: center viewport on expanded node after layout completes
JohnRDOrazio Apr 12, 2026
d69b492
test: improve patch coverage for OntologyNode, OntologyGraph, and use…
JohnRDOrazio Apr 12, 2026
aec230a
refactor: address nitpick review findings
JohnRDOrazio Apr 12, 2026
ab430f1
fix: prevent focus escape via Shift+Tab in EntityGraphModal
JohnRDOrazio Apr 12, 2026
e6bdfa6
fix: guard layout sync effect against stale results after graph clear
JohnRDOrazio Apr 12, 2026
81decfd
test: add auth header, stale epoch, and focus trap tests
JohnRDOrazio Apr 12, 2026
e7bcb35
test: fix stale test state and improve assertion specificity
JohnRDOrazio Apr 12, 2026
1c8824f
feat(graph): add secondary_root type, bezier-only edges, per-type arr…
damienriehl Apr 12, 2026
8a10ce9
fix(graph): use normalized edge type for arrow marker condition
JohnRDOrazio Apr 12, 2026
e2a0c70
fix(graph): wire keyboard handlers through useELKLayout (H1)
damienriehl Apr 25, 2026
059ac12
fix(graph): honor graphEdgeStyle store setting in OntologyEdge (H2)
damienriehl Apr 25, 2026
1fadb47
fix(graph): drop redundant OntologyGraphNode/Edge/GraphData types (H3)
damienriehl Apr 25, 2026
02cec20
feat(graph): add edge style toggle (Bezier ↔ Smooth Step) to graph to…
damienriehl May 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions __tests__/components/graph/EntityGraphModal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";

// ── Mocks ──────────────────────────────────────────────────────────

let capturedOnNavigateToClass: ((iri: string) => void) | undefined;
vi.mock("@/components/graph/OntologyGraph", () => ({
OntologyGraph: ({ focusIri, projectId, onNavigateToClass }: { focusIri: string; projectId: string; onNavigateToClass?: (iri: string) => void }) => {
capturedOnNavigateToClass = onNavigateToClass;
return (
<div data-testid="ontology-graph" data-focus-iri={focusIri} data-project-id={projectId}>
<button data-testid="graph-action">Action</button>
</div>
);
},
}));

import { EntityGraphModal } from "@/components/graph/EntityGraphModal";

// ── Fixtures ───────────────────────────────────────────────────────

const defaultProps = {
focusIri: "urn:test:Class1",
label: "Class1",
projectId: "proj-1",
branch: "main",
onNavigateToClass: vi.fn(),
onClose: vi.fn(),
};

// ── Tests ──────────────────────────────────────────────────────────

describe("EntityGraphModal", () => {
beforeEach(() => {
vi.clearAllMocks();
capturedOnNavigateToClass = undefined;
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

afterEach(() => {
vi.restoreAllMocks();
});

// --- Dialog semantics ---

it("renders with role=dialog and aria-modal", () => {
render(<EntityGraphModal {...defaultProps} />);
const dialog = screen.getByRole("dialog");
expect(dialog).toBeDefined();
expect(dialog.getAttribute("aria-modal")).toBe("true");
});

it("has aria-labelledby pointing to the title", () => {
render(<EntityGraphModal {...defaultProps} />);
const dialog = screen.getByRole("dialog");
const labelId = dialog.getAttribute("aria-labelledby");
expect(labelId).toBe("entity-graph-title");
const title = document.getElementById(labelId!);
expect(title).not.toBeNull();
});

// --- Title rendering ---

it("renders the label in the title", () => {
render(<EntityGraphModal {...defaultProps} />);
expect(screen.getByText("Class1")).toBeDefined();
expect(screen.getByText("Entity Graph")).toBeDefined();
});

// --- Close button ---

it("renders a close button with aria-label", () => {
render(<EntityGraphModal {...defaultProps} />);
const closeBtn = screen.getByLabelText("Close graph modal");
expect(closeBtn).toBeDefined();
});

it("calls onClose when close button is clicked", () => {
render(<EntityGraphModal {...defaultProps} />);
fireEvent.click(screen.getByLabelText("Close graph modal"));
expect(defaultProps.onClose).toHaveBeenCalledTimes(1);
});

// --- Escape key ---

it("calls onClose when Escape is pressed", () => {
render(<EntityGraphModal {...defaultProps} />);
fireEvent.keyDown(document, { key: "Escape" });
expect(defaultProps.onClose).toHaveBeenCalledTimes(1);
});

it("does not call onClose for non-Escape keys", () => {
render(<EntityGraphModal {...defaultProps} />);
fireEvent.keyDown(document, { key: "Enter" });
expect(defaultProps.onClose).not.toHaveBeenCalled();
});

// --- Focus management ---

it("focuses the first focusable element on mount", () => {
render(<EntityGraphModal {...defaultProps} />);
// The close button is the first focusable element in the dialog
const closeBtn = screen.getByLabelText("Close graph modal");
expect(document.activeElement).toBe(closeBtn);
});

it("restores focus on unmount", () => {
const button = document.createElement("button");
button.textContent = "Trigger";
document.body.appendChild(button);
button.focus();
expect(document.activeElement).toBe(button);

const { unmount } = render(<EntityGraphModal {...defaultProps} />);
// Focus moved to dialog
expect(document.activeElement).not.toBe(button);

unmount();
expect(document.activeElement).toBe(button);

document.body.removeChild(button);
});

// --- Focus trapping ---

it("traps focus: shift-tab from first focusable wraps to last", () => {
render(<EntityGraphModal {...defaultProps} />);
const dialog = screen.getByRole("dialog");
const focusables = dialog.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
);

expect(focusables.length).toBeGreaterThan(1);
focusables[0].focus();
fireEvent.keyDown(document, { key: "Tab", shiftKey: true });
expect(document.activeElement).toBe(focusables[focusables.length - 1]);
});

it("traps focus: tab from last focusable wraps to first", () => {
render(<EntityGraphModal {...defaultProps} />);
const dialog = screen.getByRole("dialog");
const focusables = dialog.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
);

expect(focusables.length).toBeGreaterThan(1);
focusables[focusables.length - 1].focus();
fireEvent.keyDown(document, { key: "Tab", shiftKey: false });
expect(document.activeElement).toBe(focusables[0]);
});

it("does not trap focus when Tab is pressed but focus is in the middle", () => {
render(<EntityGraphModal {...defaultProps} />);
const dialog = screen.getByRole("dialog");
const focusables = dialog.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
);

expect(focusables.length).toBeGreaterThan(1);
// Focus a non-first, non-last element — should not prevent default
// If only 2 elements, focus the first (Tab forward from first is not trapped)
const mid = focusables.length > 2 ? Math.floor(focusables.length / 2) : 0;
focusables[mid].focus();
const event = new KeyboardEvent("keydown", { key: "Tab", bubbles: true });
const preventSpy = vi.spyOn(event, "preventDefault");
document.dispatchEvent(event);
expect(preventSpy).not.toHaveBeenCalled();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

// --- Esc keyboard hint ---

it("renders Esc keyboard hint", () => {
render(<EntityGraphModal {...defaultProps} />);
expect(screen.getByText("Esc")).toBeDefined();
});

// --- Navigate callback ---

it("calls onNavigateToClass and onClose when graph triggers navigation", () => {
render(<EntityGraphModal {...defaultProps} />);
expect(capturedOnNavigateToClass).toBeDefined();
capturedOnNavigateToClass!("urn:target:Class");
expect(defaultProps.onNavigateToClass).toHaveBeenCalledWith("urn:target:Class");
expect(defaultProps.onClose).toHaveBeenCalledTimes(1);
});

// --- OntologyGraph rendered ---

it("renders the OntologyGraph component", () => {
render(<EntityGraphModal {...defaultProps} />);
expect(screen.getByTestId("ontology-graph")).toBeDefined();
});
});
51 changes: 49 additions & 2 deletions __tests__/components/graph/OntologyEdge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it, vi, beforeEach } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { Position } from "@xyflow/react";

import { OntologyEdge } from "@/components/graph/OntologyEdge";

vi.mock("@xyflow/react", () => ({
Expand All @@ -16,9 +17,18 @@ vi.mock("@xyflow/react", () => ({
<div data-testid="edge-label-renderer">{children}</div>
),
getBezierPath: (): [string, number, number] => ["M0,0 C10,10 20,20 30,30", 15, 15],
getSmoothStepPath: (): [string, number, number] => ["M0,0 L10,10 L30,30", 15, 15],
Position: { Top: "top", Bottom: "bottom", Left: "left", Right: "right" },
}));

// Mock the editor mode store — OntologyEdge subscribes for graphEdgeStyle.
// Without this, Zustand's persist middleware initializes against window.matchMedia
// (system theme detection), which jsdom doesn't ship.
vi.mock("@/lib/stores/editorModeStore", () => ({
useEditorModeStore: (selector: (s: { graphEdgeStyle: string }) => unknown) =>
selector({ graphEdgeStyle: "smoothstep" }),
}));

describe("OntologyEdge", () => {
const baseProps = {
id: "edge-1",
Expand Down Expand Up @@ -49,9 +59,32 @@ describe("OntologyEdge", () => {
);
const edge = screen.getByTestId("base-edge-edge-1");
expect(edge).toBeDefined();
// Default edge type is subClassOf: solid stroke in slate color, strokeWidth 1.5
expect(edge.style.stroke).toBe("rgb(148, 163, 184)"); // #94a3b8
expect(edge.style.strokeWidth).toBe("1.5");
expect(edge.style.strokeDasharray).toBeFalsy();
});

it("uses config-based markerEnd for subClassOf edges", () => {
render(
<svg>
<OntologyEdge {...baseProps} data={{ edgeType: "subClassOf" }} />
</svg>
);
const edge = screen.getByTestId("base-edge-edge-1");
expect(edge.getAttribute("data-marker-end")).toBe("url(#arrow-slate)");
});

it("does not apply markerEnd for non-subClassOf edges", () => {
render(
<svg>
<OntologyEdge {...baseProps} data={{ edgeType: "seeAlso" }} />
</svg>
);
const edge = screen.getByTestId("base-edge-edge-1");
expect(edge.getAttribute("data-marker-end")).toBe("");
});

it("renders with equivalentClass edge type", () => {
render(
<svg>
Expand Down Expand Up @@ -86,7 +119,7 @@ describe("OntologyEdge", () => {
</svg>
);
const edge = screen.getByTestId("base-edge-edge-1");
expect(edge.style.strokeDasharray).toBe("2 4");
expect(edge.style.strokeDasharray).toBe("6 3");
});

it("does not show label by default (not hovered)", () => {
Expand Down Expand Up @@ -146,7 +179,10 @@ describe("OntologyEdge", () => {
</svg>
);
const edge = screen.getByTestId("base-edge-edge-1");
expect(edge.getAttribute("data-marker-end")).toBe("url(#arrow-slate)");
// Without data, edge defaults to subClassOf style
expect(edge.style.stroke).toBe("rgb(148, 163, 184)");
expect(edge.style.strokeWidth).toBe("1.5");
expect(edge.style.strokeDasharray).toBeFalsy();
});

it("renders invisible hover detection path with strokeWidth 16", () => {
Expand All @@ -162,4 +198,15 @@ describe("OntologyEdge", () => {
);
expect(hoverPath?.getAttribute("stroke-width")).toBe("16");
});

it("renders smoothstep path when graphEdgeStyle is 'smoothstep' (per store mock)", () => {
render(
<svg>
<OntologyEdge {...baseProps} />
</svg>
);
const edge = screen.getByTestId("base-edge-edge-1");
// Default mock returns "smoothstep" — getSmoothStepPath is invoked.
expect(edge.getAttribute("d")).toBe("M0,0 L10,10 L30,30");
});
});
Loading
Loading