mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
JS test framework for node layout
This commit is contained in:
50
client/app/scripts/charts/__tests__/node-layout-test.js
Normal file
50
client/app/scripts/charts/__tests__/node-layout-test.js
Normal file
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -78,6 +78,7 @@
|
||||
"react",
|
||||
"immutable",
|
||||
"d3",
|
||||
"dagre",
|
||||
"keymirror",
|
||||
"object-assign",
|
||||
"lodash",
|
||||
|
||||
Reference in New Issue
Block a user