test: added tests for deleteNode function

ref: N25B-114
This commit is contained in:
JGerla
2025-10-25 17:13:42 +02:00
parent 8c698d1f8e
commit 8038674167

View File

@@ -125,6 +125,42 @@ describe('FlowStore Functionality', () => {
); );
}); });
}); });
describe('ReactFlow deleteNode', () => {
// test deleting A and B, so we make sure the connecting edge gets deleted regardless of
test.each([['A','B'],['B','A']])('deletes a node and its connected edges', (nodeId, undeletedNodeId) => {
const {deleteNode} = useFlowStore.getState();
useFlowStore.setState({
nodes: [
{
id: 'A',
type: 'default',
position: {x: 0, y: 0},
data: {label: 'A'}
},
{
id: 'B',
type: 'default',
position: {x: 0, y: 300},
data: {label: 'A'}
}],
edges: [
{
id: 'xy-edge__A-B',
source: 'A',
target: 'B'
}]
});
act(()=> {
deleteNode(nodeId);
});
const updatedState = useFlowStore.getState();
expect(updatedState.edges).toHaveLength(0);
expect(updatedState.nodes).toHaveLength(1);
expect(updatedState.nodes[0].id).toBe(undeletedNodeId);
});
});
describe('ReactFlow setNodes', () => { describe('ReactFlow setNodes', () => {
test('sets nodes to the provided list of nodes', () => { test('sets nodes to the provided list of nodes', () => {
const {setNodes} = useFlowStore.getState(); const {setNodes} = useFlowStore.getState();