33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
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);
|
|
});
|
|
test.each(['phase', 'norm'])('new nodes get correct Id', (nodeType) => {
|
|
act(()=> {
|
|
addNode(nodeType, {x:100, y:100});
|
|
addNode(nodeType, {x:100, y:100});
|
|
})
|
|
const updatedState = useFlowStore.getState();
|
|
expect(updatedState.nodes.length).toBe(2);
|
|
expect(updatedState.nodes[0].id).toBe(`${nodeType}-1`);
|
|
expect(updatedState.nodes[1].id).toBe(`${nodeType}-2`);
|
|
});
|
|
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");
|
|
})
|
|
}); |