Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e68239a
refactor(graph): replace client-side graph builder with server-side BFS
damienriehl Apr 7, 2026
a14a07a
fix(graph): address review findings for entity graph PR
JohnRDOrazio Apr 10, 2026
877f5c8
fix(graph): update stale PLAN.md references and clear graph on empty …
JohnRDOrazio Apr 10, 2026
13d00b4
fix(tests): update graph tests for server-side BFS refactor
JohnRDOrazio Apr 10, 2026
6d4b282
test(graph): add missing tests for EntityGraphModal, graph API, and E…
JohnRDOrazio Apr 10, 2026
458f752
fix: add type assertion for mock call args in graph API tests
JohnRDOrazio Apr 11, 2026
b37e4ef
test: improve coverage for EntityGraphModal and useGraphData
JohnRDOrazio Apr 11, 2026
ac0504d
test: add OntologyGraph callback and MiniMap coverage tests
JohnRDOrazio Apr 11, 2026
b1c5cdb
fix: correct entity graph API URL to match backend route
JohnRDOrazio Apr 11, 2026
3d41ae0
fix: use Math.max for total_concept_count in graph merge
JohnRDOrazio Apr 11, 2026
e482b82
fix: pass class_iri as query param for graph endpoint
JohnRDOrazio Apr 11, 2026
4912ef3
fix: pass auth token to entity graph API calls
JohnRDOrazio Apr 11, 2026
842218f
fix: swap source/target handle positions on graph nodes
JohnRDOrazio Apr 11, 2026
b42496e
fix: use React Flow built-in markers and add edge style toggle
JohnRDOrazio Apr 11, 2026
281bac2
fix: use descendants toggle state in expandNode instead of hardcoding…
JohnRDOrazio Apr 11, 2026
a29d02f
fix: add accessToken to useEffect dependency array in useGraphData
JohnRDOrazio Apr 11, 2026
c933749
fix: validate node_type at runtime instead of blind cast in useELKLayout
JohnRDOrazio Apr 11, 2026
49e8be5
test: strengthen OntologyEdge default style assertions and remove dup…
JohnRDOrazio Apr 11, 2026
b3da3ca
test: add bezier edge style coverage for OntologyEdge
JohnRDOrazio Apr 11, 2026
41e7038
fix: guard expandNode against stale results after focus/reset changes
JohnRDOrazio Apr 11, 2026
34fcb47
refactor: replace manual fetch lifecycle with React Query in useGraph…
JohnRDOrazio Apr 11, 2026
f898c67
fix: resolve lint errors in useGraphData and test wrapper
JohnRDOrazio Apr 11, 2026
a2779d0
fix: reset expansions on graph context change, not on background refetch
JohnRDOrazio Apr 11, 2026
fc5b230
feat: show one level of descendants by default in graph view
JohnRDOrazio Apr 11, 2026
b42f8d7
fix: use useLayoutEffect for epoch reset to prevent stale expansion m…
JohnRDOrazio Apr 11, 2026
95450da
fix: clear React Flow nodes/edges when graphData is null or empty
JohnRDOrazio Apr 11, 2026
126ad04
refactor: remove duplicate expandedNodes tracking from OntologyGraph
JohnRDOrazio Apr 11, 2026
ce70eb4
fix: log ELK layout errors instead of silently swallowing them
JohnRDOrazio Apr 11, 2026
411905e
fix: add click-delay guard to distinguish single click from double click
JohnRDOrazio Apr 11, 2026
ea69f10
test: add isLayouting spinner and accessToken forwarding tests
JohnRDOrazio Apr 11, 2026
41a01a6
fix: require accessToken before firing entity graph query
JohnRDOrazio Apr 12, 2026
e4ebf7a
fix: use layout-aware handle positions on graph nodes
JohnRDOrazio Apr 12, 2026
3ca5295
fix: validate edge_type at runtime instead of blind cast in useELKLayout
JohnRDOrazio Apr 12, 2026
7002a16
perf: lazy-load EntityGraphModal to reduce main bundle size
JohnRDOrazio Apr 12, 2026
f97baff
test: properly observe isLayouting state during ELK layout computation
JohnRDOrazio Apr 12, 2026
e3448e4
feat: center viewport on expanded node after layout completes
JohnRDOrazio Apr 12, 2026
1c1f915
test: improve patch coverage for OntologyNode, OntologyGraph, and use…
JohnRDOrazio Apr 12, 2026
9f102eb
refactor: address nitpick review findings
JohnRDOrazio Apr 12, 2026
bd890ed
fix: prevent focus escape via Shift+Tab in EntityGraphModal
JohnRDOrazio Apr 12, 2026
f4871e8
fix: guard layout sync effect against stale results after graph clear
JohnRDOrazio Apr 12, 2026
316e4ad
test: add auth header, stale epoch, and focus trap tests
JohnRDOrazio Apr 12, 2026
74dee59
test: fix stale test state and improve assertion specificity
JohnRDOrazio Apr 12, 2026
6fd5d83
feat(graph): add secondary_root type, bezier-only edges, per-type arr…
damienriehl Apr 12, 2026
aa08934
fix(graph): use normalized edge type for arrow marker condition
JohnRDOrazio Apr 12, 2026
ad95639
fix(graph): wire keyboard handlers through useELKLayout (H1)
damienriehl Apr 25, 2026
df83589
fix(graph): honor graphEdgeStyle store setting in OntologyEdge (H2)
damienriehl Apr 25, 2026
724ea45
fix(graph): drop redundant OntologyGraphNode/Edge/GraphData types (H3)
damienriehl Apr 25, 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;
});

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();
});

// --- 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