From 2fced6ce705c6c840aacec68f4b298109558c9d3 Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Fri, 4 Oct 2024 15:33:24 +0200 Subject: [PATCH 1/6] check main called with merge for main chain and numberNodeEdge for circle --- src/composables/__tests__/LayoutMain.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/composables/__tests__/LayoutMain.test.ts b/src/composables/__tests__/LayoutMain.test.ts index 743fcda..e3adfab 100644 --- a/src/composables/__tests__/LayoutMain.test.ts +++ b/src/composables/__tests__/LayoutMain.test.ts @@ -134,14 +134,17 @@ describe('LayoutMain', () => { // EXPECT expect(putDuplicatedSideCompoundAsideMock).toHaveBeenCalledTimes(1); + expect(putDuplicatedSideCompoundAsideMock).toHaveBeenCalledWith(expect.anything(), true, true); expect(vizLayoutMock).toHaveBeenCalledTimes(3); expect(duplicateReversibleReactionsMock).toHaveBeenCalledTimes(1); expect(addDirectedCycleToSubgraphNetworkMock).toHaveBeenCalledTimes(1); expect(getStartNodesMock).toHaveBeenCalledTimes(2); expect(chooseReversibleReactionMock).toHaveBeenCalledTimes(1); expect(addMainChainFromSourcesMock).toHaveBeenCalledTimes(1); + expect(addMainChainFromSourcesMock).toHaveBeenCalledWith(expect.anything(), expect.anything(),expect.anything(),parameters.merge,expect.anything()); expect(addMiniBranchToMainChainMock).toHaveBeenCalledTimes(1); expect(coordinateAllCyclesMock).toHaveBeenCalledTimes(1); + expect(coordinateAllCyclesMock).toHaveBeenCalledWith(expect.anything(),expect.anything(),parameters.numberNodeOnEdge); expect(drawAllCyclesGroupMock).toHaveBeenCalledTimes(1); expect(reinsertionSideCompoundsMock).toHaveBeenCalledTimes(1); expect(shiftAllToGetTopLeftCoordMock).toHaveBeenCalledTimes(1); -- GitLab From 7649a8104cb901d84c195faebd7fb8d8036cba8c Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Fri, 4 Oct 2024 15:39:41 +0200 Subject: [PATCH 2/6] doc function vizlayout + check if numberNodeOnEdge called in main --- src/composables/LayoutSugiyama.ts | 21 ++++++++++++-------- src/composables/__tests__/LayoutMain.test.ts | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/composables/LayoutSugiyama.ts b/src/composables/LayoutSugiyama.ts index f5cee69..1777a96 100644 --- a/src/composables/LayoutSugiyama.ts +++ b/src/composables/LayoutSugiyama.ts @@ -22,14 +22,19 @@ import { instance } from "@viz-js/viz"; */ - -/** - * Take a network object and change the (x,y) position of the node with viz lib - * @param {Network} Network object - * @param mainChains clusters for viz (type version for quick search) - * @param graphAttributes for viz dot layout (see https://graphviz.org/docs/layouts/dot/) - * @param assignRank indicates if rank and order need to be infered after layout is applied - * @param [callbackFunction=() => {}] function to do after the layout is done +/** + * Apply viz layout on network in subgraphnetwork : change nodes coordinates + * @param subgraphNetwork + * @param assignRank assign rank at the end ? + * @param cycle consider cycle as metanodes ? + * @param addNodes addNodes in DOT for viz ? + * @param groupOrCluster use group for clusterizing nodes, or cluster ? + * @param orderChange change order of links with ordering for cycle metanodes? + * @param printDot print the DOT in console ? + * @param dpi dot per inch + * @param factorLenghtEdge number of nodes that could be placed on a edge : for choosing length of edge + * @param callbackFunction function to call once finished + * @returns Promise of modified subgraphnetwork */ export async function vizLayout(subgraphNetwork:SubgraphNetwork,assignRank:boolean=false, cycle:boolean=true,addNodes:boolean=true, groupOrCluster:"group"|"cluster"="cluster",orderChange:boolean=false,printDot:boolean=false,dpi:number=72,factorLenghtEdge:number=3,callbackFunction = () => {}): Promise<SubgraphNetwork> { diff --git a/src/composables/__tests__/LayoutMain.test.ts b/src/composables/__tests__/LayoutMain.test.ts index e3adfab..417c461 100644 --- a/src/composables/__tests__/LayoutMain.test.ts +++ b/src/composables/__tests__/LayoutMain.test.ts @@ -136,6 +136,7 @@ describe('LayoutMain', () => { expect(putDuplicatedSideCompoundAsideMock).toHaveBeenCalledTimes(1); expect(putDuplicatedSideCompoundAsideMock).toHaveBeenCalledWith(expect.anything(), true, true); expect(vizLayoutMock).toHaveBeenCalledTimes(3); + expect(vizLayoutMock).toHaveBeenLastCalledWith(expect.anything(),expect.anything(),expect.anything(),expect.anything(),expect.anything(),expect.anything(),expect.anything(),expect.anything(),parameters.numberNodeOnEdge); expect(duplicateReversibleReactionsMock).toHaveBeenCalledTimes(1); expect(addDirectedCycleToSubgraphNetworkMock).toHaveBeenCalledTimes(1); expect(getStartNodesMock).toHaveBeenCalledTimes(2); -- GitLab From 62faa88dd1defccdddc12e1d76af04f4972b357c Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Fri, 4 Oct 2024 16:26:54 +0200 Subject: [PATCH 3/6] =?UTF-8?q?avanc=C3=A9e=20modif=20test=20cycle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/LayoutDrawCycle.test.ts | 138 +++++++++++++++++- 1 file changed, 130 insertions(+), 8 deletions(-) diff --git a/src/composables/__tests__/LayoutDrawCycle.test.ts b/src/composables/__tests__/LayoutDrawCycle.test.ts index 1c4bc3b..7411d7e 100644 --- a/src/composables/__tests__/LayoutDrawCycle.test.ts +++ b/src/composables/__tests__/LayoutDrawCycle.test.ts @@ -2,7 +2,7 @@ import { SubgraphNetwork } from '../../types/SubgraphNetwork'; import { NetworkLayout, NodeLayout } from '../../types/NetworkLayout'; import { Subgraph, TypeSubgraph } from '../../types/Subgraph'; -import { CoordinateNull } from '../../types/CoordinatesSize'; +import { Coordinate, CoordinateNull } from '../../types/CoordinatesSize'; // Composable imports @@ -14,8 +14,105 @@ import * as CalculateSize from '../CalculateSize'; // General imports import * as d3 from 'd3'; +import { error } from 'console'; + +// Function for tests + +/** Check if a list of nodes [a,b,c,d], with center o respect the constraint : + * d(a,b) = d(b,c) = d(c,d) + * d(a,o) = d(b,o) = d(c,o) =d(d,o) = radius + * */ +function isDrawAsCircle(subgraphNetwork: SubgraphNetwork,cycleGroupName: string,cycleName: string):boolean{ + const distancesNodes=getDistancesBetweenNodes(subgraphNetwork,cycleGroupName,cycleName); + const distanceCentroid=getDistancesFromNodesToCentroid(subgraphNetwork,cycleGroupName,cycleName); + if (distancesNodes === null) return false + if (distanceCentroid === null) return false + if(!subgraphNetwork[TypeSubgraph.CYCLE] || !subgraphNetwork[TypeSubgraph.CYCLE][cycleName] || subgraphNetwork[TypeSubgraph.CYCLE][cycleName].radiusCycle===undefined) return false; + const radius=subgraphNetwork[TypeSubgraph.CYCLE][cycleName].radiusCycle; + distanceCentroid?.push(radius); + + return areAllElementsEqual(distancesNodes) && areAllElementsEqual(distanceCentroid); +} + + +function euclideanDistance(p1: Coordinate, p2: Coordinate): number { + const dx = p1.x - p2.x; + const dy = p1.y - p2.y; + return Math.sqrt(dx * dx + dy * dy); +} + +function getDistancesBetweenNodes(subgraphNetwork: SubgraphNetwork,cycleGroupName: string,cycleName: string): number[] | null { + if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP] || !subgraphNetwork[TypeSubgraph.CYCLEGROUP][cycleGroupName]) return null; + const cycleGroup = subgraphNetwork[TypeSubgraph.CYCLEGROUP][cycleGroupName]; + if (!cycleGroup.precalculatedNodesPosition) return null; + const positions=cycleGroup.precalculatedNodesPosition; + + if (! subgraphNetwork[TypeSubgraph.CYCLE] || !subgraphNetwork[TypeSubgraph.CYCLE][cycleName]) return null; + const cycle = subgraphNetwork[TypeSubgraph.CYCLE][cycleName]; + + const nodesInCycle = cycle.nodes; + + const distances: number[] = []; + + for (let i = 0; i < nodesInCycle.length - 1; i++) { + const nodeA = positions[nodesInCycle[i]]; + const nodeB = positions[nodesInCycle[i + 1]]; + + if (nodeA && nodeB) { + const distance = euclideanDistance(nodeA as Coordinate, nodeB as Coordinate); + distances.push(parseFloat(distance.toFixed(2))); + } else { + console.error(`Node '${nodesInCycle[i]}' or '${nodesInCycle[i + 1]}' not found in precalculated positions`); + return null; + } + } + + return distances; +} + +function getDistancesFromNodesToCentroid(subgraphNetwork: SubgraphNetwork,cycleGroupName: string,cycleName: string): number[] | null { + if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP] || !subgraphNetwork[TypeSubgraph.CYCLEGROUP][cycleGroupName]) return null; + const cycleGroup = subgraphNetwork[TypeSubgraph.CYCLEGROUP][cycleGroupName]; + if (!cycleGroup.precalculatedNodesPosition) return null; + const positions=cycleGroup.precalculatedNodesPosition; + + + if (! subgraphNetwork[TypeSubgraph.CYCLE] || !subgraphNetwork[TypeSubgraph.CYCLE][cycleName]) return null; + const cycle = subgraphNetwork[TypeSubgraph.CYCLE][cycleName]; + + const nodesInCycle = cycle.nodes; + const centroidCycle = cycle.centroidCycle; + if (!centroidCycle) return null; + + const distances: number[] = []; + + for (let i = 0; i < nodesInCycle.length; i++) { + const node = cycleGroup.precalculatedNodesPosition[nodesInCycle[i]]; + + if (node) { + const distance = euclideanDistance(node as Coordinate, centroidCycle); + distances.push(parseFloat(distance.toFixed(2))); + } else { + console.error(`Node '${nodesInCycle[i]}' not found in precalculated positions`); + return null; + } + } + return distances; +} + +function areAllElementsEqual(arr: number[]): boolean { + if (arr.length === 0) { + throw new Error("array empty"); // Pb in distance function maybe (shouldn't have nothing) + } + const firstElement = arr[0]; + return arr.every(element => element === firstElement); +} + + +// Tests + jest.mock('d3', () => { return { forceSimulation:jest.fn(), @@ -273,11 +370,13 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle=isDrawAsCircle(result,"cycle_group_0","cycle"); // EXPECT expect(updateNodeMetadataSubgraphMock).toHaveBeenCalledTimes(3); expect(rectangleSizeMock).toHaveBeenCalledTimes(1); expect(result).toEqual(subgraphNetworkExpected); + expect(drawAsCircle).toEqual(true); }); @@ -468,11 +567,14 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); // EXPECT expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); - + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(false); }); @@ -565,10 +667,14 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); // EXPECT expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(false); }); @@ -621,11 +727,14 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); // EXPECT expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); - + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(true); }); @@ -634,11 +743,11 @@ describe('LayoutDrawCycle',()=>{ // MOCK isIntersectionGraphMock.mockReturnValue(true); - getListNodeLinksForCycleGroupAsArrayMock.mockReturnValue({ + getListNodeLinksForCycleGroupAsArrayMock.mockReturnValueOnce({ nodes: [ - { id: 'node0', fx: 0, fy: -6 }, - { id: 'node1', fx: 5.2, fy: 3 }, - { id: 'node2', fx: -5.2, fy: 3 }, + { id: 'node0', fx: 0, fy: -5.2 }, + { id: 'node1', fx: 4.5, fy: 2.6 }, + { id: 'node2', fx: -4.5, fy: 2.6 }, { id: 'node3' } ], links: [] @@ -689,12 +798,15 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); // EXPECT expect(getListNodeLinksForCycleGroupAsArrayMock).toHaveBeenCalledTimes(1); expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).toHaveBeenCalledTimes(1); - + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(false); }); @@ -919,10 +1031,16 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); + const drawAsCircle3=isDrawAsCircle(result,"cycle_group_0","cycle3"); // EXPECT expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); + expect(drawAsCircle1).toEqual(false); + expect(drawAsCircle2).toEqual(true); + expect(drawAsCircle3).toEqual(true); }); @@ -1008,11 +1126,15 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_1","cycle2"); // EXPECT expect(getNodesPlacedInGroupCycleAsObjectMock).toHaveBeenCalledTimes(2); expect(result).toEqual(subgraphNetworkExpected); + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(true); }); -- GitLab From 131538d8c1aa583ecd36a2725dc772ce1b6ccdd9 Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Mon, 7 Oct 2024 08:32:28 +0200 Subject: [PATCH 4/6] debug check circle + check line --- .../__tests__/LayoutDrawCycle.test.ts | 64 +++++++++++++++++-- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/src/composables/__tests__/LayoutDrawCycle.test.ts b/src/composables/__tests__/LayoutDrawCycle.test.ts index 7411d7e..699fdac 100644 --- a/src/composables/__tests__/LayoutDrawCycle.test.ts +++ b/src/composables/__tests__/LayoutDrawCycle.test.ts @@ -15,6 +15,7 @@ import * as CalculateSize from '../CalculateSize'; // General imports import * as d3 from 'd3'; import { error } from 'console'; +import exp from 'constants'; @@ -23,6 +24,7 @@ import { error } from 'console'; /** Check if a list of nodes [a,b,c,d], with center o respect the constraint : * d(a,b) = d(b,c) = d(c,d) * d(a,o) = d(b,o) = d(c,o) =d(d,o) = radius + * (or close by epsilon instead of equal) * */ function isDrawAsCircle(subgraphNetwork: SubgraphNetwork,cycleGroupName: string,cycleName: string):boolean{ const distancesNodes=getDistancesBetweenNodes(subgraphNetwork,cycleGroupName,cycleName); @@ -33,7 +35,7 @@ function isDrawAsCircle(subgraphNetwork: SubgraphNetwork,cycleGroupName: string, const radius=subgraphNetwork[TypeSubgraph.CYCLE][cycleName].radiusCycle; distanceCentroid?.push(radius); - return areAllElementsEqual(distancesNodes) && areAllElementsEqual(distanceCentroid); + return areAllElementsClose(distancesNodes) && areAllElementsClose(distanceCentroid); } @@ -102,14 +104,60 @@ function getDistancesFromNodesToCentroid(subgraphNetwork: SubgraphNetwork,cycleG return distances; } -function areAllElementsEqual(arr: number[]): boolean { +function areAllElementsClose(arr: number[], epsilon: number = 0.05): boolean { if (arr.length === 0) { - throw new Error("array empty"); // Pb in distance function maybe (shouldn't have nothing) + throw new Error("Array is empty"); // Error if the array is empty } + const firstElement = arr[0]; - return arr.every(element => element === firstElement); + + // Check if all elements are within the tolerance of the first element + return arr.every(element => Math.abs(element - firstElement) <= epsilon); } +function isDrawAsLine(subgraphNetwork: SubgraphNetwork,cycleGroupName: string,nodeIds: string[],epsilon:number=0.05): boolean { + if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP] || !subgraphNetwork[TypeSubgraph.CYCLEGROUP][cycleGroupName]) {return false;} + + const cycleGroup = subgraphNetwork[TypeSubgraph.CYCLEGROUP][cycleGroupName]; + if (!cycleGroup.precalculatedNodesPosition) {return false;} + const positions = cycleGroup.precalculatedNodesPosition; + + // Calculate the initial slope between the first two nodes + if (nodeIds.length <= 2) {return true;} // Only two nodes or less, so it is a line + const firstNode = positions[nodeIds[0]]; + const secondNode = positions[nodeIds[1]]; + if (!firstNode || !secondNode || firstNode.x===null || firstNode.y===null || secondNode.x===null || secondNode.y===null) { + console.error("Coordinates for one or more nodes are missing."); + return false; + } + const initialSlope = calculateSlope(firstNode as Coordinate, secondNode as Coordinate); + const isVertical = (initialSlope === Infinity); + + // Check the slope between all consecutive node pairs + for (let i = 1; i < nodeIds.length - 1; i++) { + const nodeA = positions[nodeIds[i]]; + const nodeB = positions[nodeIds[i + 1]]; + + if (!nodeA || !nodeB || nodeA.x===null || nodeA.y===null || nodeB.x===null || nodeB.y===null) { + console.error(`Node '${nodeIds[i]}' or '${nodeIds[i + 1]}' not found in precalculated positions`); + return false; + } + const currentSlope = calculateSlope(nodeA as Coordinate, nodeB as Coordinate); + if (initialSlope === null || currentSlope === null) {return false;} + if (isVertical && Math.abs(currentSlope) !== Infinity) { + return false; // If initial was vertical but current is not + } + else if ( Math.abs(currentSlope - initialSlope) > epsilon) {return false;} + } + return true; +} + +function calculateSlope(pointA: Coordinate, pointB: Coordinate): number | null { + const dx = pointB.x - pointA.x; + const dy = pointB.y - pointA.y; + if (dx === 0) {return Infinity;} // Vertical line + return dy / dx; +} // Tests @@ -263,7 +311,7 @@ describe('LayoutDrawCycle',()=>{ }); - it('should throw error because cycle have no node',async ()=>{ + it('should throw error because cycle have no node',async ()=>{ // DATA @@ -569,12 +617,14 @@ describe('LayoutDrawCycle',()=>{ const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); + const drawAsLine=isDrawAsLine(result,"cycle_group_0",["node0","node2","node4"]); // EXPECT expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(false); + expect(drawAsLine).toEqual(true); }); @@ -669,12 +719,14 @@ describe('LayoutDrawCycle',()=>{ const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); + const drawAsLine=isDrawAsLine(result,"cycle_group_0",["node6","node0","node1","node5"]); // EXPECT expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(false); + expect(drawAsLine).toEqual(true); }); @@ -1034,6 +1086,7 @@ describe('LayoutDrawCycle',()=>{ const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); const drawAsCircle3=isDrawAsCircle(result,"cycle_group_0","cycle3"); + const drawAsLine=isDrawAsLine(result,"cycle_group_0",["node6","node9","node8"]); // EXPECT expect(result).toEqual(subgraphNetworkExpected); @@ -1041,6 +1094,7 @@ describe('LayoutDrawCycle',()=>{ expect(drawAsCircle1).toEqual(false); expect(drawAsCircle2).toEqual(true); expect(drawAsCircle3).toEqual(true); + expect(drawAsLine).toEqual(true); }); -- GitLab From 5062977e64095724f05a855671e28028106285d0 Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Mon, 7 Oct 2024 08:58:06 +0200 Subject: [PATCH 5/6] adding some check for drawing groupcycle test --- .../__tests__/LayoutDrawCycle.test.ts | 61 +++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/composables/__tests__/LayoutDrawCycle.test.ts b/src/composables/__tests__/LayoutDrawCycle.test.ts index 699fdac..28c3b37 100644 --- a/src/composables/__tests__/LayoutDrawCycle.test.ts +++ b/src/composables/__tests__/LayoutDrawCycle.test.ts @@ -369,19 +369,26 @@ describe('LayoutDrawCycle',()=>{ // MOCK getNodesPlacedInGroupCycleAsObjectMock = jest.spyOn(CalculateRelationCycle, 'getNodesPlacedInGroupCycleAsObject'); getNodesPlacedInGroupCycleAsObjectMock.mockImplementation( () => { - if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP]) return; + if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP] || !subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"]) return; const position=subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"].precalculatedNodesPosition; - if (position && position.node0.x === 0 && position.node0.y === -5.2 && - position.node1.x === 4.5 && position.node1.y === 2.6 && - position.node2.x === -4.5 && position.node2.y === 2.6) { - return {node0:{x:0,y:-5.2},node1:{x:4.5,y:2.6},node2:{x:-4.5,y:2.6}}; - } + if (!position) return; + return {node0:{x:0,y:-5},node1:{x:4,y:2},node2:{x:-4,y:2}}; } ); rectangleSizeMock = jest.spyOn(CalculateSize, 'rectangleSize'); - rectangleSizeMock.mockReturnValue({width:10.4,height:9,center:{x:0,y:-1.5}}); - + rectangleSizeMock.mockReturnValue({width:10,height:10,center:{x:0,y:-1}}); + + // FUNCTION FOR TEST + const checkSize=function(subgraphNetwork:SubgraphNetwork):boolean{ + if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP] || !subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"]) return false; + if (!subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"].originalPosition) return false; + if (subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"].height!==10) return false; + if (subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"].width!==10) return false; + if (subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"].originalPosition.x!==0) return false; + if (subgraphNetwork[TypeSubgraph.CYCLEGROUP]["cycle_group_0"].originalPosition.y!==-1) return false; + return true; + } // DATA const subgraph:Subgraph={ @@ -414,7 +421,7 @@ describe('LayoutDrawCycle',()=>{ "links":[]}, "networkStyle":{}, "cycles":{"cycle":{"name":"cycle","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node2"],"radiusCycle":5.2,"centroidCycle":{"x":0,"y":0}}}, - "cyclesGroup":{"cycle_group_0":{"name":"cycle_group_0","nodes":["cycle"],"type":TypeSubgraph.CYCLEGROUP,"precalculatedNodesPosition":{"node0":{"x":0,"y":-5.2},"node1":{"x":4.5,"y":2.6},"node2":{"x":-4.5,"y":2.6}},"width":10.4,"height":9,"originalPosition":{"x":0,"y":-1.5}}}} + "cyclesGroup":{"cycle_group_0":{"name":"cycle_group_0","nodes":["cycle"],"type":TypeSubgraph.CYCLEGROUP,"precalculatedNodesPosition":{"node0":{"x":0,"y":-5.2},"node1":{"x":4.5,"y":2.6},"node2":{"x":-4.5,"y":2.6}},"width":10,"height":10,"originalPosition":{"x":0,"y":-1}}}} // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); @@ -423,8 +430,10 @@ describe('LayoutDrawCycle',()=>{ // EXPECT expect(updateNodeMetadataSubgraphMock).toHaveBeenCalledTimes(3); expect(rectangleSizeMock).toHaveBeenCalledTimes(1); + expect (rectangleSizeMock).toHaveBeenCalledWith([{"x":0,"y":-5},{"x":4,"y":2},{"x":-4,"y":2}]); expect(result).toEqual(subgraphNetworkExpected); expect(drawAsCircle).toEqual(true); + expect(checkSize(result)).toEqual(true); }); @@ -797,9 +806,9 @@ describe('LayoutDrawCycle',()=>{ getListNodeLinksForCycleGroupAsArrayMock.mockReturnValueOnce({ nodes: [ - { id: 'node0', fx: 0, fy: -5.2 }, - { id: 'node1', fx: 4.5, fy: 2.6 }, - { id: 'node2', fx: -4.5, fy: 2.6 }, + { id: 'node0', fx: 0, fy: -5 }, + { id: 'node1', fx: 4, fy: 2 }, + { id: 'node2', fx: -4, fy: 2 }, { id: 'node3' } ], links: [] @@ -852,10 +861,19 @@ describe('LayoutDrawCycle',()=>{ const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); + let posNode3:CoordinateNull={x:null,y:null}; + if(result.cyclesGroup && result[TypeSubgraph.CYCLEGROUP]["cycle_group_0"] + && result.cyclesGroup["cycle_group_0"].precalculatedNodesPosition + && result.cyclesGroup["cycle_group_0"].precalculatedNodesPosition.node3){ + posNode3=result.cyclesGroup["cycle_group_0"].precalculatedNodesPosition.node3; + } // EXPECT expect(getListNodeLinksForCycleGroupAsArrayMock).toHaveBeenCalledTimes(1); expect(result).toEqual(subgraphNetworkExpected); + expect(posNode3).toBeDefined(); + expect(posNode3.x).toEqual(34); + expect(posNode3.y).toEqual(34); expect(forcesimulationMock).toHaveBeenCalledTimes(1); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(false); @@ -870,8 +888,8 @@ describe('LayoutDrawCycle',()=>{ getListNodeLinksForCycleGroupAsArrayMock.mockReturnValue({ nodes: [ { id: 'node0', fx: 0, fy: -6 }, - { id: 'node1', fx: 5.2, fy: 3 }, - { id: 'node2', fx: -5.2, fy: 3 }, + { id: 'node1', fx: 5, fy: 3 }, + { id: 'node2', fx: -5, fy: 3 }, { id: 'node3' } ], links: [] @@ -909,6 +927,8 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); let posNode3:CoordinateNull={x:null,y:null}; if(result.cyclesGroup && result[TypeSubgraph.CYCLEGROUP]["cycle_group_0"] @@ -918,11 +938,13 @@ describe('LayoutDrawCycle',()=>{ } // EXPECT + expect(getListNodeLinksForCycleGroupAsArrayMock).toHaveBeenCalledTimes(1); expect(posNode3).toBeDefined(); expect(posNode3.x).toEqual(34); expect(posNode3.y).toEqual(34); expect(forcesimulationMock).toHaveBeenCalledTimes(1); - + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(false); }); @@ -934,8 +956,8 @@ describe('LayoutDrawCycle',()=>{ getListNodeLinksForCycleGroupAsArrayMock.mockReturnValue({ nodes: [ { id: 'node0', fx: 0, fy: -6 }, - { id: 'node1', fx: 5.2, fy: 3 }, - { id: 'node2', fx: -5.2, fy: 3 }, + { id: 'node1', fx: 5, fy: 3 }, + { id: 'node2', fx: -5, fy: 3 }, { id: 'node3' } ], links: [] @@ -973,6 +995,8 @@ describe('LayoutDrawCycle',()=>{ // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); + const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); + const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); let posNode3:CoordinateNull={x:null,y:null}; if(result.cyclesGroup && result[TypeSubgraph.CYCLEGROUP]["cycle_group_0"] @@ -982,10 +1006,13 @@ describe('LayoutDrawCycle',()=>{ } // EXPECT + expect(getListNodeLinksForCycleGroupAsArrayMock).toHaveBeenCalledTimes(1); expect(posNode3).toBeDefined(); expect(posNode3.x).toEqual(34); expect(posNode3.y).toEqual(34); expect(forcesimulationMock).toHaveBeenCalledTimes(1); + expect(drawAsCircle1).toEqual(true); + expect(drawAsCircle2).toEqual(false); }); -- GitLab From 5388238e6d745a189d4fd3bb663b1d85379e0002 Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Mon, 7 Oct 2024 09:01:33 +0200 Subject: [PATCH 6/6] test cycle indep of coordinates --- .../__tests__/LayoutDrawCycle.test.ts | 200 ------------------ 1 file changed, 200 deletions(-) diff --git a/src/composables/__tests__/LayoutDrawCycle.test.ts b/src/composables/__tests__/LayoutDrawCycle.test.ts index 28c3b37..dfb4cd6 100644 --- a/src/composables/__tests__/LayoutDrawCycle.test.ts +++ b/src/composables/__tests__/LayoutDrawCycle.test.ts @@ -414,15 +414,6 @@ describe('LayoutDrawCycle',()=>{ [TypeSubgraph.CYCLE]:{"cycle":subgraph} }; - const subgraphNetworkExpected:SubgraphNetwork={"network":{"id":"network", - "nodes":{"node0":{"id":"node0","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node1":{"id":"node1","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node2":{"id":"node2","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}}, - "links":[]}, - "networkStyle":{}, - "cycles":{"cycle":{"name":"cycle","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node2"],"radiusCycle":5.2,"centroidCycle":{"x":0,"y":0}}}, - "cyclesGroup":{"cycle_group_0":{"name":"cycle_group_0","nodes":["cycle"],"type":TypeSubgraph.CYCLEGROUP,"precalculatedNodesPosition":{"node0":{"x":0,"y":-5.2},"node1":{"x":4.5,"y":2.6},"node2":{"x":-4.5,"y":2.6}},"width":10,"height":10,"originalPosition":{"x":0,"y":-1}}}} - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle=isDrawAsCircle(result,"cycle_group_0","cycle"); @@ -431,7 +422,6 @@ describe('LayoutDrawCycle',()=>{ expect(updateNodeMetadataSubgraphMock).toHaveBeenCalledTimes(3); expect(rectangleSizeMock).toHaveBeenCalledTimes(1); expect (rectangleSizeMock).toHaveBeenCalledWith([{"x":0,"y":-5},{"x":4,"y":2},{"x":-4,"y":2}]); - expect(result).toEqual(subgraphNetworkExpected); expect(drawAsCircle).toEqual(true); expect(checkSize(result)).toEqual(true); @@ -443,7 +433,6 @@ describe('LayoutDrawCycle',()=>{ parentNodeNotInCycleMock.mockReturnValue([ [],["node3"],["node4"] ]) - // DATA const subgraph:Subgraph={ @@ -611,17 +600,6 @@ describe('LayoutDrawCycle',()=>{ [TypeSubgraph.CYCLE]:{"cycle":subgraph, "cycle2":subgraph2} }; - const subgraphNetworkExpected:SubgraphNetwork={"network":{"id":"network", - "nodes":{"node0":{"id":"node0","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node1":{"id":"node1","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node2":{"id":"node2","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node3":{"id":"node3","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node4":{"id":"node4","x":10,"y":10,"metadataLayout":{"isFixed":true}}},"links":[]}, - "networkStyle":{}, - "cycles":{"cycle":{"name":"cycle","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node2","node3"],"radiusCycle":6.36,"centroidCycle":{"x":0,"y":0}}, - "cycle2":{"name":"cycle2","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node2","node4"]}}, - "cyclesGroup":{"cycle_group_0":{"name":"cycle_group_0","nodes":["cycle","cycle2"],"type":TypeSubgraph.CYCLEGROUP,"precalculatedNodesPosition":{"node0":{"x":0,"y":-6.36},"node1":{"x":6.36,"y":0},"node2":{"x":0,"y":6.36},"node3":{"x":-6.36,"y":0},"node4":{"x":0,"y":0}},"width":0,"height":0,"originalPosition":{"x":0,"y":0}}}} - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); @@ -629,7 +607,6 @@ describe('LayoutDrawCycle',()=>{ const drawAsLine=isDrawAsLine(result,"cycle_group_0",["node0","node2","node4"]); // EXPECT - expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(false); @@ -671,58 +648,6 @@ describe('LayoutDrawCycle',()=>{ networkStyle:{}, [TypeSubgraph.CYCLE]:{"cycle":subgraph, "cycle2":subgraph2} }; - - const subgraphNetworkExpected:SubgraphNetwork={ - "network": { - "id": "network", - "nodes": { - "node0": { "id": "node0", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node1": { "id": "node1", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node2": { "id": "node2", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node3": { "id": "node3", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node4": { "id": "node4", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node5": { "id": "node5", "x": 0, "y": 0, "metadataLayout": { "isFixed": true } }, - "node6": { "id": "node6", "x": 0, "y": 0, "metadataLayout": { "isFixed": true } } - }, - "links": [] - }, - "networkStyle": {}, - "cycles": { - "cycle": { - "name": "cycle", - "type": TypeSubgraph.CYCLE, - "nodes": ["node0", "node1", "node2", "node3", "node4"], - "radiusCycle": 7.66, - "centroidCycle": { "x": 0, "y": 0 } - }, - "cycle2": { - "name": "cycle2", - "type": TypeSubgraph.CYCLE, - "nodes": ["node6", "node0", "node1", "node5"] - } - }, - "cyclesGroup": { - "cycle_group_0": { - "name": "cycle_group_0", - "nodes": ["cycle", "cycle2"], - "type": TypeSubgraph.CYCLEGROUP, - "precalculatedNodesPosition": { - "node0": { "x": 0, "y": -7.66 }, - "node1": { "x": 7.29, "y": -2.37 }, - "node2": { "x": 4.5, "y": 6.2 }, - "node3": { "x": -4.5, "y": 6.2 }, - "node4": { "x": -7.29, "y": -2.37 }, - "node5": { "x": 4.86, "y": -4.13 }, - "node6": { "x": 2.43, "y": -5.9 } - }, - "width": 0, - "height": 0, - "originalPosition": { "x": 0, "y": 0 } - } - } - } - - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); @@ -731,14 +656,12 @@ describe('LayoutDrawCycle',()=>{ const drawAsLine=isDrawAsLine(result,"cycle_group_0",["node6","node0","node1","node5"]); // EXPECT - expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(false); expect(drawAsLine).toEqual(true); }); - it('should calculate coordinates for 2 cycles related : as tangent (but no force)', async()=>{ @@ -773,18 +696,6 @@ describe('LayoutDrawCycle',()=>{ networkStyle:{}, [TypeSubgraph.CYCLE]:{"cycle":subgraph, "cycle2":subgraph2} }; - - const subgraphNetworkExpected:SubgraphNetwork={"network":{"id":"network", - "nodes":{"node0":{"id":"node0","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node1":{"id":"node1","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node2":{"id":"node2","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node3":{"id":"node3","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle2"}}, - "node4":{"id":"node4","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle2"}}}, - "links":[]},"networkStyle":{}, - "cycles":{"cycle":{"name":"cycle","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node2"],"radiusCycle":5.2,"centroidCycle":{"x":0,"y":0}}, - "cycle2":{"name":"cycle2","type":TypeSubgraph.CYCLE,"nodes":["node0","node3","node4"],"radiusCycle":5.2,"centroidCycle":{"x":0,"y":-10.4}}}, - "cyclesGroup":{"cycle_group_0":{"name":"cycle_group_0","nodes":["cycle","cycle2"],"type":TypeSubgraph.CYCLEGROUP,"precalculatedNodesPosition":{"node0":{"x":0,"y":-5.2},"node1":{"x":4.5,"y":2.6},"node2":{"x":-4.5,"y":2.6},"node3":{"x":-4.5,"y":-13},"node4":{"x":4.5,"y":-13}},"width":0,"height":0,"originalPosition":{"x":0,"y":0}}}} - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); @@ -792,7 +703,6 @@ describe('LayoutDrawCycle',()=>{ const drawAsCircle2=isDrawAsCircle(result,"cycle_group_0","cycle2"); // EXPECT - expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(true); @@ -844,19 +754,6 @@ describe('LayoutDrawCycle',()=>{ [TypeSubgraph.CYCLE]:{"cycle":subgraph, "cycle2":subgraph2} }; - const subgraphNetworkExpected:SubgraphNetwork={"network":{"id":"network", - "nodes":{"node0":{"id":"node0","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node1":{"id":"node1","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node2":{"id":"node2","x":0,"y":0,"metadataLayout":{"isFixed":true,"fixedInCircle":"cycle"}}, - "node3":{"id":"node3","x":0,"y":0,"metadataLayout":{"isFixed":true}}}, - "links":[]}, - "networkStyle":{}, - "cycles":{"cycle":{"name":"cycle","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node2"],"radiusCycle":5.2,"centroidCycle":{"x":0,"y":0}}, - "cycle2":{"name":"cycle2","type":TypeSubgraph.CYCLE,"nodes":["node0","node1","node3"]}}, - "cyclesGroup":{"cycle_group_0":{"name":"cycle_group_0","nodes":["cycle","cycle2"],"type":TypeSubgraph.CYCLEGROUP, - "precalculatedNodesPosition":{"node0":{"x":0,"y":-5.2},"node1":{"x":4.5,"y":2.6},"node2":{"x":-4.5,"y":2.6},"node3":{"x":34,"y":34}}, - "width":0,"height":0,"originalPosition":{"x":0,"y":0}}}} - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); @@ -870,7 +767,6 @@ describe('LayoutDrawCycle',()=>{ // EXPECT expect(getListNodeLinksForCycleGroupAsArrayMock).toHaveBeenCalledTimes(1); - expect(result).toEqual(subgraphNetworkExpected); expect(posNode3).toBeDefined(); expect(posNode3.x).toEqual(34); expect(posNode3.y).toEqual(34); @@ -1060,53 +956,6 @@ describe('LayoutDrawCycle',()=>{ networkStyle:{}, [TypeSubgraph.CYCLE]:{"cycle":subgraph, "cycle2":subgraph2, "cycle3":subgraph3} }; - - const subgraphNetworkExpected:SubgraphNetwork={ - "network": { - "id": "network", - "nodes": { - "node0": { "id": "node0", "x": 0, "y": 0 }, - "node1": { "id": "node1", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node2": { "id": "node2", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node3": { "id": "node3", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node4": { "id": "node4", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node5": { "id": "node5", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node6": { "id": "node6", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle3" } }, - "node7": { "id": "node7", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle3" } }, - "node8": { "id": "node8", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle3" } }, - "node9": { "id": "node9", "x": 0, "y": 0, "metadataLayout": { "isFixed": true } } - }, - "links": [] - }, - "networkStyle": {}, - "cycles": { - "cycle": { "name": "cycle", "type": TypeSubgraph.CYCLE, "nodes": ["node6", "node7", "node8", "node9"] }, - "cycle2": { "name": "cycle2", "type": TypeSubgraph.CYCLE, "nodes": ["node1", "node2", "node3", "node4", "node5"], "radiusCycle": 7.66, "centroidCycle": { "x": 0, "y": 0 } }, - "cycle3": { "name": "cycle3", "type": TypeSubgraph.CYCLE, "nodes": ["node6", "node7", "node8", "node2"], "radiusCycle": 6.36, "centroidCycle": { "x": 13.33, "y": -4.33 } } - }, - "cyclesGroup": { - "cycle_group_0": { - "name": "cycle_group_0", - "nodes": ["cycle2", "cycle3", "cycle"], - "type": TypeSubgraph.CYCLEGROUP, - "precalculatedNodesPosition": { - "node1": { "x": 0, "y": -7.66 }, - "node2": { "x": 7.29, "y": -2.37 }, - "node3": { "x": 4.5, "y": 6.2 }, - "node4": { "x": -4.5, "y": 6.2 }, - "node5": { "x": -7.29, "y": -2.37 }, - "node6": { "x": 11.37, "y": -10.38 }, - "node7": { "x": 19.38, "y": -6.29 }, - "node8": { "x": 15.29, "y": 1.72 }, - "node9": { "x": 13.33, "y": -4.33 } - }, - "width": 0, - "height": 0, - "originalPosition": { "x": 0, "y": 0 } - } - } - } - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); @@ -1116,14 +965,12 @@ describe('LayoutDrawCycle',()=>{ const drawAsLine=isDrawAsLine(result,"cycle_group_0",["node6","node9","node8"]); // EXPECT - expect(result).toEqual(subgraphNetworkExpected); expect(forcesimulationMock).not.toHaveBeenCalled(); expect(drawAsCircle1).toEqual(false); expect(drawAsCircle2).toEqual(true); expect(drawAsCircle3).toEqual(true); expect(drawAsLine).toEqual(true); - }); @@ -1161,50 +1008,6 @@ describe('LayoutDrawCycle',()=>{ [TypeSubgraph.CYCLE]:{"cycle":subgraph, "cycle2":subgraph2} }; - const subgraphNetworkExpected:SubgraphNetwork={ - "network": { - "id": "network", - "nodes": { - "node0": { "id": "node0", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node1": { "id": "node1", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node2": { "id": "node2", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle" } }, - "node3": { "id": "node3", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node4": { "id": "node4", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } }, - "node5": { "id": "node5", "x": 0, "y": 0, "metadataLayout": { "isFixed": true, "fixedInCircle": "cycle2" } } - }, - "links": [] - }, - "networkStyle": {}, - "cycles": { - "cycle": { "name": "cycle", "type": TypeSubgraph.CYCLE, "nodes": ["node0", "node1", "node2"], "radiusCycle": 5.2, "centroidCycle": { "x": 0, "y": 0 } }, - "cycle2": { "name": "cycle2", "type": TypeSubgraph.CYCLE, "nodes": ["node3", "node4", "node5"], "radiusCycle": 5.2, "centroidCycle": { "x": 0, "y": 0 } } - }, - "cyclesGroup": { - "cycle_group_0": { - "name": "cycle_group_0", - "nodes": ["cycle"], - "type": TypeSubgraph.CYCLEGROUP, - "precalculatedNodesPosition": { - "node0": { "x": 0, "y": -5.2 }, - "node1": { "x": 4.5, "y": 2.6 }, - "node2": { "x": -4.5, "y": 2.6 } - }, - "width": 0,"height": 0,"originalPosition": { "x": 0, "y": 0 } - }, - "cycle_group_1": { - "name": "cycle_group_1", - "nodes": ["cycle2"], - "type": TypeSubgraph.CYCLEGROUP, - "precalculatedNodesPosition": { - "node3": { "x": 0, "y": -5.2 }, - "node4": { "x": 4.5, "y": 2.6 }, - "node5": { "x": -4.5, "y": 2.6 } - }, - "width": 0,"height": 0,"originalPosition": { "x": 0, "y": 0 } - } - } - }; - // TEST const result=await LayoutDrawCycle.coordinateAllCycles(subgraphNetwork); const drawAsCircle1=isDrawAsCircle(result,"cycle_group_0","cycle"); @@ -1213,7 +1016,6 @@ describe('LayoutDrawCycle',()=>{ // EXPECT expect(getNodesPlacedInGroupCycleAsObjectMock).toHaveBeenCalledTimes(2); - expect(result).toEqual(subgraphNetworkExpected); expect(drawAsCircle1).toEqual(true); expect(drawAsCircle2).toEqual(true); @@ -1422,8 +1224,6 @@ describe('LayoutDrawCycle',()=>{ }); - - }); }); \ No newline at end of file -- GitLab