Merge branch 'dev' into feat/basic-belief-nodes

This commit is contained in:
Björn Otgaar
2025-12-15 14:47:01 +01:00
15 changed files with 639 additions and 109 deletions

View File

@@ -1,8 +1,12 @@
import { describe, it, beforeEach } from '@jest/globals';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithProviders } from '../.././/./../../test-utils/test-utils';
import NormNode, { NormReduce, NormConnects, type NormNodeData } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/NormNode'
import { renderWithProviders } from '../../../../test-utils/test-utils.tsx';
import NormNode, {
NormReduce,
type NormNodeData,
NormConnectionSource, NormConnectionTarget
} from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/NormNode';
import useFlowStore from '../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores';
import type { Node } from '@xyflow/react';
import '@testing-library/jest-dom'
@@ -518,7 +522,7 @@ describe('NormNode', () => {
};
expect(() => {
NormConnects(normNode, phaseNode, true);
NormConnectionSource(normNode, phaseNode.id);
}).not.toThrow();
});
@@ -548,7 +552,7 @@ describe('NormNode', () => {
};
expect(() => {
NormConnects(normNode, phaseNode, false);
NormConnectionTarget(normNode, phaseNode.id);
}).not.toThrow();
});
@@ -566,7 +570,8 @@ describe('NormNode', () => {
};
expect(() => {
NormConnects(normNode, normNode, true);
NormConnectionTarget(normNode, normNode.id);
NormConnectionSource(normNode, normNode.id);
}).not.toThrow();
});
});

View File

@@ -2,8 +2,11 @@ import { describe, it } from '@jest/globals';
import '@testing-library/jest-dom';
import { screen } from '@testing-library/react';
import type { Node } from '@xyflow/react';
import { renderWithProviders } from '../.././/./../../test-utils/test-utils';
import StartNode, { StartReduce, StartConnects } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/StartNode';
import { renderWithProviders } from '../../../../test-utils/test-utils.tsx';
import StartNode, {
StartConnectionSource, StartConnectionTarget,
StartReduce
} from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/StartNode';
describe('StartNode', () => {
@@ -91,8 +94,8 @@ describe('StartNode', () => {
},
};
expect(() => StartConnects(startNode, otherNode, true)).not.toThrow();
expect(() => StartConnects(startNode, otherNode, false)).not.toThrow();
expect(() => StartConnectionSource(startNode, otherNode.id)).not.toThrow();
expect(() => StartConnectionTarget(startNode, otherNode.id)).not.toThrow();
});
});
});

View File

@@ -1,8 +1,13 @@
import { describe, it, beforeEach } from '@jest/globals';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithProviders } from '../.././/./../../test-utils/test-utils';
import TriggerNode, { TriggerReduce, TriggerConnects, TriggerNodeCanConnect, type TriggerNodeData } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode';
import { renderWithProviders } from '../../../../test-utils/test-utils.tsx';
import TriggerNode, {
TriggerReduce,
TriggerNodeCanConnect,
type TriggerNodeData,
TriggerConnectionSource, TriggerConnectionTarget
} from '../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/TriggerNode';
import useFlowStore from '../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores';
import type { Node } from '@xyflow/react';
import '@testing-library/jest-dom';
@@ -233,8 +238,8 @@ describe('TriggerNode', () => {
};
expect(() => {
TriggerConnects(node1, node2, true);
TriggerConnects(node1, node2, false);
TriggerConnectionSource(node1, node2.id);
TriggerConnectionTarget(node1, node2.id);
}).not.toThrow();
});

View File

@@ -1,8 +1,8 @@
import { describe, beforeEach } from '@jest/globals';
import { screen } from '@testing-library/react';
import { renderWithProviders } from '../.././/./../../test-utils/test-utils';
import { renderWithProviders } from '../../../../test-utils/test-utils.tsx';
import type { XYPosition } from '@xyflow/react';
import { NodeTypes, NodeDefaults, NodeConnects, NodeReduces, NodesInPhase } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/NodeRegistry';
import { NodeTypes, NodeDefaults, NodeConnections, NodeReduces, NodesInPhase } from '../../../../../src/pages/VisProgPage/visualProgrammingUI/NodeRegistry';
import '@testing-library/jest-dom'
import { createElement } from 'react';
import useFlowStore from '../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores';
@@ -89,8 +89,8 @@ describe('NormNode', () => {
useFlowStore.setState({ nodes: [sourceNode, targetNode] });
// Spy on the connect functions
const sourceConnectSpy = jest.spyOn(NodeConnects, nodeType as keyof typeof NodeConnects);
const targetConnectSpy = jest.spyOn(NodeConnects, 'end');
const sourceConnectSpy = jest.spyOn(NodeConnections.Sources, nodeType as keyof typeof NodeConnections.Sources);
const targetConnectSpy = jest.spyOn(NodeConnections.Targets, 'end');
// Simulate connection
useFlowStore.getState().onConnect({
@@ -101,8 +101,8 @@ describe('NormNode', () => {
});
// Verify the connect functions were called
expect(sourceConnectSpy).toHaveBeenCalledWith(sourceNode, targetNode, true);
expect(targetConnectSpy).toHaveBeenCalledWith(targetNode, sourceNode, false);
expect(sourceConnectSpy).toHaveBeenCalledWith(sourceNode, targetNode.id);
expect(targetConnectSpy).toHaveBeenCalledWith(targetNode, sourceNode.id);
sourceConnectSpy.mockRestore();
targetConnectSpy.mockRestore();
@@ -132,7 +132,7 @@ describe('NormNode', () => {
expect(phaseReduceSpy).toHaveBeenCalledWith(phaseNode, [phaseNode, testNode]);
// Check if this node type is in NodesInPhase and returns false
const nodesInPhaseFunc = NodesInPhase[nodeType as keyof typeof NodesInPhase];
if (nodesInPhaseFunc && nodesInPhaseFunc() === false && nodeType !== 'phase') {
if (nodesInPhaseFunc && !nodesInPhaseFunc() && nodeType !== 'phase') {
// Node is NOT in phase, so it should NOT be called
expect(nodeReduceSpy).not.toHaveBeenCalled();
} else {