diff --git a/client/app/scripts/charts/__tests__/node-layout-test.js b/client/app/scripts/charts/__tests__/node-layout-test.js new file mode 100644 index 000000000..a6d8d3cf2 --- /dev/null +++ b/client/app/scripts/charts/__tests__/node-layout-test.js @@ -0,0 +1,50 @@ +jest.dontMock('../nodes-layout'); +jest.dontMock('../../constants/naming'); // edge naming: 'source-target' + +describe('NodesLayout', () => { + const NodesLayout = require('../nodes-layout'); + + function scale(val) { + return val * 3; + } + const topologyId = 'tid'; + const width = 80; + const height = 80; + const margins = { + left: 0, + top: 0 + }; + + const nodeSets = { + initial4: { + nodes: { + n1: {id: 'n1'}, + n2: {id: 'n2'}, + n3: {id: 'n3'}, + n4: {id: 'n4'} + }, + edges: { + 'n1-n3': {id: 'n1-n3', source: {id: 'n1'}, target: {id: 'n3'}}, + 'n1-n4': {id: 'n1-n4', source: {id: 'n1'}, target: {id: 'n4'}}, + 'n2-n4': {id: 'n2-n4', source: {id: 'n2'}, target: {id: 'n4'}} + } + } + }; + + it('lays out initial nodeset', () => { + const nodes = nodeSets.initial4.nodes; + const edges = nodeSets.initial4.edges; + NodesLayout.doLayout(nodes, edges, width, height, scale, margins, topologyId); + expect(nodes.n1.x).toBeLessThan(nodes.n2.x); + expect(nodes.n1.y).toEqual(nodes.n2.y); + + expect(nodes.n1.x).toEqual(nodes.n3.x); + expect(nodes.n1.y).toBeLessThan(nodes.n3.y); + + expect(nodes.n3.x).toBeLessThan(nodes.n4.x); + expect(nodes.n3.y).toEqual(nodes.n4.y); + + console.log(nodes, nodeSets.initial4.nodes); + }); + +}); diff --git a/client/package.json b/client/package.json index 0fd48ea14..6d4fcbdeb 100644 --- a/client/package.json +++ b/client/package.json @@ -78,6 +78,7 @@ "react", "immutable", "d3", + "dagre", "keymirror", "object-assign", "lodash",