From d9faeafe320800278beedfc2fe4ac288100fc290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Otgaar?= Date: Wed, 3 Dec 2025 11:28:15 +0100 Subject: [PATCH] test: create test for phase node to account for the previous bug. ref: N25B-371 --- .../nodes/PhaseNode.test.tsx | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/pages/visProgPage/visualProgrammingUI/nodes/PhaseNode.test.tsx b/test/pages/visProgPage/visualProgrammingUI/nodes/PhaseNode.test.tsx index b37c23a..43763d3 100644 --- a/test/pages/visProgPage/visualProgrammingUI/nodes/PhaseNode.test.tsx +++ b/test/pages/visProgPage/visualProgrammingUI/nodes/PhaseNode.test.tsx @@ -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); }); }); \ No newline at end of file