test: added test for onConnect event
ref: N25B-114
This commit is contained in:
30
test/pages/visProgPage/VisProg.test.tsx
Normal file
30
test/pages/visProgPage/VisProg.test.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { act } from '@testing-library/react';
|
||||||
|
import useFlowStore from '../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx';
|
||||||
|
import { mockReactFlow } from '../../setupFlowTests.ts';
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
mockReactFlow();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('FlowCanvas onConnect', () => {
|
||||||
|
|
||||||
|
test('adds an edge when onConnect is triggered', () => {
|
||||||
|
const { onConnect} = useFlowStore.getState();
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
onConnect({
|
||||||
|
source: 'A',
|
||||||
|
target: 'B',
|
||||||
|
sourceHandle: null,
|
||||||
|
targetHandle: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedEdges = useFlowStore.getState().edges;
|
||||||
|
expect(updatedEdges).toHaveLength(1);
|
||||||
|
expect(updatedEdges[0]).toMatchObject({
|
||||||
|
source: 'A',
|
||||||
|
target: 'B',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -63,8 +63,7 @@ export const mockReactFlow = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(() => {
|
beforeEach(() => { useFlowStore.setState({ nodes: [], edges: [] }); })
|
||||||
cleanup();
|
|
||||||
useFlowStore.setState({ nodes: [], edges: [] });
|
afterEach(() => { cleanup(); });
|
||||||
});
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user