Skip to content

Commit

Permalink
test: add tests for highlighting users and comments with related node…
Browse files Browse the repository at this point in the history
…s and edges in highlightNodesAndEdges function
  • Loading branch information
MH4GF committed Dec 19, 2024
1 parent f3e454a commit 00a18a7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ describe(highlightNodesAndEdges, () => {
}),
])
})
it('When the users is active, and the comments is hovered, then the users and comments and related tables are highlighted', () => {
const { nodes: updatedNodes } = highlightNodesAndEdges(nodes, edges, {
activeTableName: 'users',
hoverTableName: 'comments',
})

expect(updatedNodes).toEqual([
aTableNode('users', {
data: aTableData('users', { isActiveHighlighted: true }),
}),
aTableNode('posts', {
data: aTableData('posts', {
isHighlighted: true,
highlightedHandles: ['posts-user_id'],
}),
}),
aTableNode('comments', {
data: aTableData('comments', { isHighlighted: true }),
}),
aTableNode('comment_users', {
data: aTableData('comment_users', {
isHighlighted: true,
highlightedHandles: ['comment_users-user_id'],
}),
}),
])
})
})

describe('edges', () => {
Expand Down Expand Up @@ -204,5 +231,32 @@ describe(highlightNodesAndEdges, () => {
),
])
})
it('When the users is active, and the comments is hovered, then the users and comments and related edges are highlighted', () => {
const { edges: updatedEdges } = highlightNodesAndEdges(nodes, edges, {
activeTableName: 'users',
hoverTableName: 'comments',
})

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',
{
animated: true,
data: { isHighlighted: true },
},
),
])
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ export const highlightNodesAndEdges = (
})

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

Expand Down

0 comments on commit 00a18a7

Please sign in to comment.