Files
pepperplus-ui/test/pages/visProgPage/visualProgrammingUI/nodes/StartNode.test.tsx
JobvAlewijk 2261da9915 test: robot, and 2 nodes tests added.
ref: N25B-292
2025-11-27 18:45:11 +01:00

101 lines
2.7 KiB
TypeScript

import { describe, it, beforeEach } from '@jest/globals';
import { screen } from '@testing-library/react';
import { renderWithProviders, resetFlowStore } from '../.././/./../../test-utils/test-utils';
import StartNode, { StartReduce, StartConnects } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/StartNode';
import type { Node } from '@xyflow/react';
import '@testing-library/jest-dom';
describe('StartNode', () => {
beforeEach(() => {
resetFlowStore();
});
describe('Rendering', () => {
it('renders the StartNode correctly', () => {
const mockNode: Node = {
id: 'start-1',
type: 'start', // TypeScript now knows this is a string
position: { x: 0, y: 0 },
data: {
label: 'Start Node',
droppable: false,
hasReduce: true,
},
};
renderWithProviders(
<StartNode
id={mockNode.id}
type={mockNode.type!} // <--- fix here
data={mockNode.data as any}
selected={false}
isConnectable={true}
zIndex={0}
dragging={false}
selectable={true}
deletable={false}
draggable={true}
positionAbsoluteX={0}
positionAbsoluteY={0}
/>
);
expect(screen.getByText('Start')).toBeInTheDocument();
// The handle should exist in the DOM
expect(document.querySelector('[data-handleid="source"]')).toBeInTheDocument();
});
});
describe('StartReduce Function', () => {
it('reduces the StartNode to its minimal structure', () => {
const mockNode: Node = {
id: 'start-1',
type: 'start',
position: { x: 0, y: 0 },
data: {
label: 'Start Node',
droppable: false,
hasReduce: true,
},
};
const result = StartReduce(mockNode, [mockNode]);
expect(result).toEqual({ id: 'start-1' });
});
});
describe('StartConnects Function', () => {
it('handles connections without throwing', () => {
const startNode: Node = {
id: 'start-1',
type: 'start',
position: { x: 0, y: 0 },
data: {
label: 'Start Node',
droppable: false,
hasReduce: true,
},
};
const otherNode: Node = {
id: 'norm-1',
type: 'norm',
position: { x: 100, y: 0 },
data: {
label: 'Norm Node',
droppable: true,
norm: 'test',
hasReduce: true,
},
};
expect(() => StartConnects(startNode, otherNode, true)).not.toThrow();
expect(() => StartConnects(startNode, otherNode, false)).not.toThrow();
});
});
});