Skip to content

Commit

Permalink
feat: add test for hover highlighting of users and related edges in h…
Browse files Browse the repository at this point in the history
…ighlightNodesAndEdges function
  • Loading branch information
MH4GF committed Dec 19, 2024
1 parent 352d79d commit bf892f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,27 @@ describe(highlightNodesAndEdges, () => {
),
])
})
it('When the users is hovered, the users and related edges are highlighted', () => {
const { edges: updatedEdges } = highlightNodesAndEdges(nodes, edges, {
hoverTableName: 'users',
})

expect(updatedEdges).toEqual([
anEdge('users', 'posts', 'users-id', 'posts-user_id', {
animated: true,
data: { isHighlighted: true },
}),
anEdge('users', 'comment_users', 'users-id', 'comment_users-user_id', {
animated: true,
data: { isHighlighted: true },
}),
anEdge(
'comments',
'comment_users',
'comments-id',
'comment_users-comment_id',
),
])
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const isHoveredNode = (
return node.data.table.name === hoverTableName
}

const isActivelyRelatedEdge = (
activeTableName: string | undefined,
const isRelatedEdgeToTarget = (
targetTableName: string | undefined,
edge: Edge,
): boolean => {
return edge.source === activeTableName || edge.target === activeTableName
return edge.source === targetTableName || edge.target === targetTableName
}

const getHighlightedHandlesForRelatedNode = (
Expand Down Expand Up @@ -158,7 +158,7 @@ export const highlightNodesAndEdges = (
})

const updatedEdges = edges.map((edge) => {
if (isActivelyRelatedEdge(activeTableName, edge)) {
if (isRelatedEdgeToTarget(activeTableName ?? hoverTableName, edge)) {
return highlightEdge(edge)
}

Expand Down

0 comments on commit bf892f4

Please sign in to comment.