test: create test for phase node to account for the previous bug.

ref: N25B-371
This commit is contained in:
Björn Otgaar
2025-12-03 11:28:15 +01:00
parent 518045ed1c
commit d9faeafe32

View File

@@ -1,22 +1,39 @@
import { resetFlowStore } from "../../../../test-utils/test-utils";
import useFlowStore from '../../../../../src/pages/VisProgPage/visualProgrammingUI/VisProgStores';
import addNode from "../../../../../src/pages/VisProgPage/visualProgrammingUI/utils/AddNode";
import type { PhaseNodeData } from "../../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/PhaseNode";
describe('PhaseNode', () => {
beforeEach(() => resetFlowStore());
it('each created phase gets its own children array (store-level)', () => {
it('each created phase gets its own children array, not the same reference ', () => {
// Create nodes
addNode("phase", {x:10,y:10})
addNode("phase", {x:20,y:20})
addNode("norm", {x:30,y:30})
addNode("norm", {x:40,y:40})
addNode("goal", {x:50,y:50})
// Find nodes
const nodes = useFlowStore.getState().nodes;
const p1 = nodes.find((x) => x.id === 'phase-1')!;
const p2 = nodes.find((x) => x.id === 'phase-2')!;
// not the same reference
// expect same value, not same reference
expect(p1.data.children).not.toBe(p2.data.children);
// but same initial value
expect(p1.data.children).toEqual(p2.data.children);
// Add nodes to children
let p1_data = p1.data as PhaseNodeData;
let p2_data = p2.data as PhaseNodeData;
p1_data.children.push("norm-1");
p2_data.children.push("norm-2");
p2_data.children.push("goal-1");
// check that after adding, its not the same reference, and its not the same children
expect(p1.data.children).not.toBe(p2.data.children);
expect(p1.data.children).not.toEqual(p2.data.children);
// expect them to have the correct length.
expect(p1_data.children.length == 1);
expect(p2_data.children.length == 2);
});
});