Calculating test result based on config values
diff --git a/views/ngXosViews/diagnostic/spec/rackHelper.test.js b/views/ngXosViews/diagnostic/spec/rackHelper.test.js
index 932b17f..9f11686 100644
--- a/views/ngXosViews/diagnostic/spec/rackHelper.test.js
+++ b/views/ngXosViews/diagnostic/spec/rackHelper.test.js
@@ -42,75 +42,145 @@
describe('The Rack Helper Service', () => {
- var Service;
+ var Service, Config;
+
+ // results
+ var cp1, cp2, cp3, rack, instancePos, nodePos;
beforeEach(module('xos.serviceTopology'));
// inject the rackHelper service
- beforeEach(inject(function (_RackHelper_) {
+ beforeEach(inject(function (_RackHelper_, _serviceTopologyConfig_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
Service = _RackHelper_;
+ Config = _serviceTopologyConfig_;
+
+ cp1 = {
+ width: (Config.instance.width * 2) + (Config.instance.margin * 3),
+ height: (Config.instance.height * 2) + (Config.instance.margin * 5) + Config.computeNode.labelHeight
+ };
+
+ cp2 = {
+ width: (Config.instance.width * 2) + (Config.instance.margin * 3),
+ height: Config.instance.height + (Config.instance.margin * 4) + Config.computeNode.labelHeight
+ };
+
+ cp3 = {
+ width: (Config.instance.width * 2) + (Config.instance.margin * 3),
+ height: Config.instance.height + (Config.instance.margin * 4) + Config.computeNode.labelHeight
+ };
+
+ rack = {
+ width: cp1.width + (Config.computeNode.margin * 2),
+ height: cp1.height + cp2.height + cp3.height + (Config.computeNode.margin * 4)
+ }
+
+ instancePos = [
+ {
+ x: Config.instance.margin,
+ y: Config.instance.margin + Service.getComputeNodeLabelSize()
+ },
+ {
+ x: Config.instance.margin + (Config.instance.width * 1) + (Config.instance.margin * 1),
+ y: Config.instance.margin + Service.getComputeNodeLabelSize()
+ },
+ {
+ x: Config.instance.margin,
+ y: Config.instance.margin + Service.getComputeNodeLabelSize() + + (Config.instance.height * 1) + (Config.instance.margin * 1)
+ },
+ {
+ x: Config.instance.margin + (Config.instance.width * 1) + (Config.instance.margin * 1),
+ y: Config.instance.margin + Service.getComputeNodeLabelSize() + + (Config.instance.height * 1) + (Config.instance.margin * 1)
+ }
+ ];
+
+ nodePos = [
+ {
+ x: Config.computeNode.margin,
+ y: Config.computeNode.margin
+ },
+ {
+ x: Config.computeNode.margin,
+ y: (Config.computeNode.margin * 2) + cp1.height
+ },
+ {
+ x: Config.computeNode.margin,
+ y: (Config.computeNode.margin * 3) + cp1.height + cp2.height
+ }
+ ]
}));
describe('Given a list of instances', () => {
- it('should calculate the Compute Node Size', () => {
+ it('should calculate the first Compute Node Size', () => {
const [width, height] = Service.getComputeNodeSize(computeNodes[0].instances);
- expect(width).toBe(95);
- expect(height).toBe(67);
+ expect(width).toBe(cp1.width);
+ expect(height).toBe(cp1.height);
+ });
+
+ it('should calculate the second Compute Node Size', () => {
+ const [width, height] = Service.getComputeNodeSize(computeNodes[1].instances);
+ expect(width).toBe(cp2.width);
+ expect(height).toBe(cp2.height);
+ });
+
+ it('should calculate the third Compute Node Size', () => {
+ const [width, height] = Service.getComputeNodeSize(computeNodes[1].instances);
+ expect(width).toBe(cp3.width);
+ expect(height).toBe(cp3.height);
});
});
describe('Given a list of Compute Nodes', () => {
it('should return rack size', () => {
const [width, height] = Service.getRackSize(computeNodes);
- expect(width).toBe(105);
- expect(height).toBe(179);
+ expect(width).toBe(rack.width);
+ expect(height).toBe(rack.height);
});
});
describe('Given an instance index', () => {
it('should return the position for first instance', () => {
const [x, y] = Service.getInstancePosition(0);
- expect(x).toBe(5);
- expect(y).toBe(25);
- });
+ expect(x).toBe(instancePos[0].x);
+ expect(y).toBe(instancePos[0].y);
+ })
it('should return the position for second instance', () => {
const [x, y] = Service.getInstancePosition(1);
- expect(x).toBe(50);
- expect(y).toBe(25);
+ expect(x).toBe(instancePos[1].x);
+ expect(y).toBe(instancePos[1].y);
});
it('should return the position for third instance', () => {
const [x, y] = Service.getInstancePosition(2);
- expect(x).toBe(5);
- expect(y).toBe(46);
+ expect(x).toBe(instancePos[2].x);
+ expect(y).toBe(instancePos[2].y);
});
it('should return the position for 4th instance', () => {
const [x, y] = Service.getInstancePosition(3);
- expect(x).toBe(50);
- expect(y).toBe(46);
+ expect(x).toBe(instancePos[3].x);
+ expect(y).toBe(instancePos[3].y);
});
});
describe('Given an ComputeNode index', () => {
it('should return the position for 1st node', () => {
const [x, y] = Service.getComputeNodePosition(computeNodes, 0);
- expect(x).toBe(5);
- expect(y).toBe(5);
- });
+ expect(x).toBe(nodePos[0].x);
+ expect(y).toBe(nodePos[0].y);
+ })
it('should return the position for 2st node', () => {
const [x, y] = Service.getComputeNodePosition(computeNodes, 1);
- expect(x).toBe(5);
- expect(y).toBe(77);
+ expect(x).toBe(nodePos[1].x);
+ expect(y).toBe(nodePos[1].y);
});
it('should return the position for 2st node', () => {
const [x, y] = Service.getComputeNodePosition(computeNodes, 2);
- expect(x).toBe(5);
- expect(y).toBe(128);
+ expect(x).toBe(nodePos[2].x);
+ expect(y).toBe(nodePos[2].y);
});
});
});
diff --git a/views/ngXosViews/diagnostic/src/js/config.js b/views/ngXosViews/diagnostic/src/js/config.js
index a693317..a8ab7dc 100644
--- a/views/ngXosViews/diagnostic/src/js/config.js
+++ b/views/ngXosViews/diagnostic/src/js/config.js
@@ -33,11 +33,11 @@
y: -10
},
instance: {
- width: 40,
- height: 16,
+ width: 80,
+ height: 36,
margin: 5,
- x: -20,
- y: -8
+ x: -40,
+ y: -18
}
})
diff --git a/views/ngXosViews/diagnostic/src/js/nodeDrawer.js b/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
index dba2325..7e52abb 100644
--- a/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
+++ b/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
@@ -120,7 +120,7 @@
y: 13, //FIXME
x: 5 //FIXME
})
- .text(d => d.humanReadableName.split('.')[0]);
+ .text(d => d.name);
};
this.addPhisical = (nodes) => {
diff --git a/views/ngXosViews/diagnostic/src/js/rackHelper.js b/views/ngXosViews/diagnostic/src/js/rackHelper.js
index 345bd80..15dcc0c 100644
--- a/views/ngXosViews/diagnostic/src/js/rackHelper.js
+++ b/views/ngXosViews/diagnostic/src/js/rackHelper.js
@@ -67,8 +67,6 @@
this.getComputeNodePosition = (nodes, position) => {
- console.log(position);
-
const x = serviceTopologyConfig.computeNode.margin;
let previousElEight = lodash.reduce(nodes.slice(0, position), (val, node) => {