-
Notifications
You must be signed in to change notification settings - Fork 4
Port entity graph to server-side BFS endpoint #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
damienriehl
wants to merge
48
commits into
dev
Choose a base branch
from
entity-graph-pr
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 5bab29e
fix(graph): address review findings for entity graph PR
JohnRDOrazio 8c119a4
fix(graph): update stale PLAN.md references and clear graph on empty …
JohnRDOrazio 80af048
fix(tests): update graph tests for server-side BFS refactor
JohnRDOrazio 5342494
test(graph): add missing tests for EntityGraphModal, graph API, and E…
JohnRDOrazio 7116f5f
fix: add type assertion for mock call args in graph API tests
JohnRDOrazio 4e46f9a
test: improve coverage for EntityGraphModal and useGraphData
JohnRDOrazio 4f1ec91
test: add OntologyGraph callback and MiniMap coverage tests
JohnRDOrazio 485d7e6
fix: correct entity graph API URL to match backend route
JohnRDOrazio 3a9b686
fix: use Math.max for total_concept_count in graph merge
JohnRDOrazio 218bcc1
fix: pass class_iri as query param for graph endpoint
JohnRDOrazio 29fcad7
fix: pass auth token to entity graph API calls
JohnRDOrazio 484e1cf
fix: swap source/target handle positions on graph nodes
JohnRDOrazio 9af8ce3
fix: use React Flow built-in markers and add edge style toggle
JohnRDOrazio 0544569
fix: use descendants toggle state in expandNode instead of hardcoding…
JohnRDOrazio d6b5ea2
fix: add accessToken to useEffect dependency array in useGraphData
JohnRDOrazio 5d9fd53
fix: validate node_type at runtime instead of blind cast in useELKLayout
JohnRDOrazio a96d41b
test: strengthen OntologyEdge default style assertions and remove dup…
JohnRDOrazio c9802eb
test: add bezier edge style coverage for OntologyEdge
JohnRDOrazio c5b9855
fix: guard expandNode against stale results after focus/reset changes
JohnRDOrazio 49fccd1
refactor: replace manual fetch lifecycle with React Query in useGraph…
JohnRDOrazio 599372e
fix: resolve lint errors in useGraphData and test wrapper
JohnRDOrazio 9ad334f
fix: reset expansions on graph context change, not on background refetch
JohnRDOrazio c207ad9
feat: show one level of descendants by default in graph view
JohnRDOrazio 2f31314
fix: use useLayoutEffect for epoch reset to prevent stale expansion m…
JohnRDOrazio 28536e7
fix: clear React Flow nodes/edges when graphData is null or empty
JohnRDOrazio a5b913f
refactor: remove duplicate expandedNodes tracking from OntologyGraph
JohnRDOrazio f1ef029
fix: log ELK layout errors instead of silently swallowing them
JohnRDOrazio 60e8899
fix: add click-delay guard to distinguish single click from double click
JohnRDOrazio ecab724
test: add isLayouting spinner and accessToken forwarding tests
JohnRDOrazio 7ecb179
fix: require accessToken before firing entity graph query
JohnRDOrazio abec074
fix: use layout-aware handle positions on graph nodes
JohnRDOrazio 1cc1422
fix: validate edge_type at runtime instead of blind cast in useELKLayout
JohnRDOrazio 313ab1f
perf: lazy-load EntityGraphModal to reduce main bundle size
JohnRDOrazio c8be8e7
test: properly observe isLayouting state during ELK layout computation
JohnRDOrazio 3ece951
feat: center viewport on expanded node after layout completes
JohnRDOrazio d69b492
test: improve patch coverage for OntologyNode, OntologyGraph, and use…
JohnRDOrazio aec230a
refactor: address nitpick review findings
JohnRDOrazio ab430f1
fix: prevent focus escape via Shift+Tab in EntityGraphModal
JohnRDOrazio e6bdfa6
fix: guard layout sync effect against stale results after graph clear
JohnRDOrazio 81decfd
test: add auth header, stale epoch, and focus trap tests
JohnRDOrazio e7bcb35
test: fix stale test state and improve assertion specificity
JohnRDOrazio 1c8824f
feat(graph): add secondary_root type, bezier-only edges, per-type arr…
damienriehl 8a10ce9
fix(graph): use normalized edge type for arrow marker condition
JohnRDOrazio e2a0c70
fix(graph): wire keyboard handlers through useELKLayout (H1)
damienriehl 059ac12
fix(graph): honor graphEdgeStyle store setting in OntologyEdge (H2)
damienriehl 1fadb47
fix(graph): drop redundant OntologyGraphNode/Edge/GraphData types (H3)
damienriehl 02cec20
feat(graph): add edge style toggle (Bezier ↔ Smooth Step) to graph to…
damienriehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
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(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.