test: added test for addNode error

added test for addNode error thrown on unexpected node type

ref: N25B-114
This commit is contained in:
JGerla
2025-10-25 21:09:25 +02:00
parent 416025bf3f
commit 7b12ae1f5e
2 changed files with 4 additions and 11 deletions

View File

@@ -13,11 +13,6 @@ import useFlowStore from "../VisProgStores.tsx";
import styles from "../../VisProg.module.css" import styles from "../../VisProg.module.css"
// Is used to make sure each subsequent node gets a unique id, so the ReactFlow implementation
// can distinguish between different nodes.
let id = 0;
const getId = () => `dndnode_${id++}`;
/** /**
* DraggableNodeProps dictates the type properties of a DraggableNode * DraggableNodeProps dictates the type properties of a DraggableNode
*/ */
@@ -97,12 +92,7 @@ export function addNode(nodeType: string, position: XYPosition) {
}; };
} }
default: { default: {
return { throw new Error(`Node ${nodeType} not found`);
id: getId(),
type: nodeType,
position,
data: {label: `new default node`},
};
} }
} }
} }

View File

@@ -27,4 +27,7 @@ describe('Drag-and-Drop sidebar', () => {
expect(updatedState.nodes[0].id).toBe(`${nodeType}-0`); expect(updatedState.nodes[0].id).toBe(`${nodeType}-0`);
expect(updatedState.nodes[1].id).toBe(`${nodeType}-1`); expect(updatedState.nodes[1].id).toBe(`${nodeType}-1`);
}); });
test('throws error on unexpected node type', () => {
expect(() => addNode('I do not Exist', {x:100, y:100})).toThrow("Node I do not Exist not found");
})
}); });