From c8484d28e5a357fdfaf3a2b42e193973a8b83527 Mon Sep 17 00:00:00 2001 From: JGerla Date: Sat, 25 Oct 2025 16:03:57 +0200 Subject: [PATCH] test: added tests for onReconnectEnd ref: N25B-114 --- .../VisProgStores.test.tsx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx b/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx index 3fe5b5c..b6eb9d3 100644 --- a/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx +++ b/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx @@ -81,6 +81,49 @@ describe('FlowStore Functionality', () => { }); }); describe('ReactFlow onReconnectEnd', () => { + // prepares the state to have an edge in the edge array + beforeEach(() => { + useFlowStore.setState({edges: [ + { + id: 'xy-edge__A-B', + source: 'A', + target: 'B' + } + ]} + ); + }); + + test('successfully removes edge if no successful reconnect occurred', () => { + const {onReconnectEnd} = useFlowStore.getState(); + useFlowStore.setState({edgeReconnectSuccessful: false}); + + act(() => { + onReconnectEnd(null, {id: 'xy-edge__A-B'}); + }); + + const updatedState = useFlowStore.getState(); + expect(updatedState.edgeReconnectSuccessful).toBe(true); + expect(updatedState.edges).toHaveLength(0); + }); + + test('does not remove reconnecting edge if successful reconnect occurred', () => { + const {onReconnectEnd} = useFlowStore.getState(); + + act(() => { + onReconnectEnd(null, {id: 'xy-edge__A-B'}); + }); + + const updatedState = useFlowStore.getState(); + expect(updatedState.edgeReconnectSuccessful).toBe(true); + expect(updatedState.edges).toHaveLength(1); + expect(updatedState.edges).toMatchObject([ + { + id: 'xy-edge__A-B', + source: 'A', + target: 'B' + }] + ); + }); }); describe('ReactFlow setNodes', () => { test('sets nodes to the provided list of nodes', () => {