test: added test

added test for addNode

ref: N25B-114
This commit is contained in:
JGerla
2025-10-25 20:53:09 +02:00
parent e1d6b08a1c
commit 9bfc39afa1
4 changed files with 30 additions and 3 deletions

View File

@@ -0,0 +1,3 @@
jest.mock('@neodrag/react', () => ({
useDraggable: jest.fn(),
}));

View File

@@ -69,7 +69,9 @@ function DraggableNode({className, children, nodeType, onDrop}: DraggableNodePro
); );
} }
function addNode(nodeType: string, position: XYPosition) {
// eslint-disable-next-line react-refresh/only-export-components
export function addNode(nodeType: string, position: XYPosition) {
const {setNodes} = useFlowStore.getState(); const {setNodes} = useFlowStore.getState();
const nds = useFlowStore.getState().nodes; const nds = useFlowStore.getState().nodes;
const newNode = () => { const newNode = () => {

View File

@@ -0,0 +1,20 @@
import { mockReactFlow } from '../../../../setupFlowTests.ts';
import {act} from "@testing-library/react";
import useFlowStore from "../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx";
import {addNode} from "../../../../../src/pages/VisProgPage/visualProgrammingUI/components/DragDropSidebar.tsx";
beforeAll(() => {
mockReactFlow();
});
describe('Drag-and-Drop sidebar', () => {
test.each(['phase', 'phase'])('new nodes get added correctly', (nodeType: string) => {
act(()=> {
addNode(nodeType, {x:100, y:100});
})
const updatedState = useFlowStore.getState();
expect(updatedState.nodes.length).toBe(1);
expect(updatedState.nodes[0].type).toBe(nodeType);
});
});

View File

@@ -58,11 +58,13 @@ export const mockReactFlow = () => {
(globalThis.SVGElement as never).prototype.getBBox = () => ({ (globalThis.SVGElement as never).prototype.getBBox = () => ({
x: 0, x: 0,
y: 0, y: 0,
width: 0, width: 200,
height: 0, height: 200,
}); });
}; };
beforeAll(() => { beforeAll(() => {
useFlowStore.setState({ useFlowStore.setState({
nodes: [], nodes: [],