39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
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', () => {
|
|
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')!;
|
|
|
|
// expect same value, not same reference
|
|
expect(p1.data.children).not.toBe(p2.data.children);
|
|
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);
|
|
});
|
|
}); |