Refactored test to allow dinamically calculated space between points
diff --git a/views/ngXosViews/diagnostic/spec/logicTopologyHelper.test.js b/views/ngXosViews/diagnostic/spec/logicTopologyHelper.test.js
index d9a987d..94307f5 100644
--- a/views/ngXosViews/diagnostic/spec/logicTopologyHelper.test.js
+++ b/views/ngXosViews/diagnostic/spec/logicTopologyHelper.test.js
@@ -3,14 +3,29 @@
describe('The Logic Topology Helper Service', () => {
- var Service;
+ var Service, Config;
+
+ var x0, x1, x2, x3, x4;
+
+ var svgWidth = 900;
beforeEach(module('xos.serviceTopology'));
// inject the rackHelper service
- beforeEach(inject(function (_LogicTopologyHelper_) {
+ beforeEach(inject(function (_LogicTopologyHelper_, _serviceTopologyConfig_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
Service = _LogicTopologyHelper_;
+ Config = _serviceTopologyConfig_;
+
+ // result
+ let totalElWidth = Config.elWidths.reduce((el, val) => val + el, 0);
+ let remainingSpace = svgWidth - totalElWidth - (Config.widthMargin * 2);
+ let step = remainingSpace / (Config.elWidths.length - 1);
+ x0 = Config.widthMargin;
+ x1 = x0 + Config.elWidths[0] + step;
+ x2 = x1 + Config.elWidths[1] + step;
+ x3 = x2 + Config.elWidths[2] + step;
+ x4 = x3 + Config.elWidths[3] + step;
}));
var customMatchers = {
@@ -34,14 +49,13 @@
});
it('should calculate horizontal position for each element', () => {
- let [el0x, el1x, el2x, el3x, el4x, el5x] = Service.computeElementPosition(900);
-
- expect(el0x).toBeSimilar(870);
- expect(el1x).toBeSimilar(736.6);
- expect(el2x).toBeSimilar(560.7);
- expect(el3x).toBeSimilar(384.8);
- expect(el4x).toBeSimilar(251.4);
- expect(el5x).toBeSimilar(95);
+ let [el0x, el1x, el2x, el3x, el4x] = Service.computeElementPosition(svgWidth);
+ console.log(x1, el1x);
+ expect(el0x).toBeSimilar(svgWidth - (x0 + (Config.elWidths[0] / 2)));
+ expect(el1x).toBeSimilar(svgWidth - (x1 + (Config.elWidths[1] / 2)));
+ expect(el2x).toBeSimilar(svgWidth - (x2 + (Config.elWidths[2] / 2)));
+ expect(el3x).toBeSimilar(svgWidth - (x3 + (Config.elWidths[3] / 2)));
+ expect(el4x).toBeSimilar(svgWidth - (x4 + (Config.elWidths[4] / 2)));
});
});
diff --git a/views/ngXosViews/diagnostic/src/js/config.js b/views/ngXosViews/diagnostic/src/js/config.js
index fec991a..6b029d7 100644
--- a/views/ngXosViews/diagnostic/src/js/config.js
+++ b/views/ngXosViews/diagnostic/src/js/config.js
@@ -6,7 +6,7 @@
widthMargin: 20,
heightMargin: 30,
duration: 750,
- elWidths: [20, 104, 105, 104, 20, 150], //this is not true
+ elWidths: [20, 104, 105, 104, 20], //this is not true
circle: {
radius: 10,
r: 10,
diff --git a/views/ngXosViews/diagnostic/src/js/logicTopology.js b/views/ngXosViews/diagnostic/src/js/logicTopology.js
index ed1fcbb..c126053 100644
--- a/views/ngXosViews/diagnostic/src/js/logicTopology.js
+++ b/views/ngXosViews/diagnostic/src/js/logicTopology.js
@@ -28,7 +28,7 @@
$scope.$watch(() => this.subscribers, (subscribers) => {
if(subscribers){
- LogicTopologyHelper.addSubscribers(angular.copy(subscribers));
+ // LogicTopologyHelper.addSubscribers(angular.copy(subscribers));
Node.queryWithInstances().$promise
.then((computeNodes) => {
diff --git a/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js b/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
index 8ba9c71..f87e397 100644
--- a/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
+++ b/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
@@ -22,7 +22,10 @@
{
name: 'LAN',
type: 'network',
- children: [] //subscribers goes here
+ children: [{
+ name: 'Subscriber',
+ type: 'subscriber'
+ }] //subscribers goes here
}
]
}
@@ -63,7 +66,7 @@
+ (step * i) // space between elements
+ (el / 2) // this el width
+ previousElWidth; // previous elements width
-
+ console.log(`${i} elPos: ${previousElWidth}`);
xPos.push(svgWidth - elPos);
})
diff --git a/views/ngXosViews/diagnostic/src/js/nodeDrawer.js b/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
index 1a45f03..2548812 100644
--- a/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
+++ b/views/ngXosViews/diagnostic/src/js/nodeDrawer.js
@@ -161,10 +161,7 @@
instanceContainer
.attr({
transform: `translate(${width / 2}, ${ height / 2})`,
- class: d => {
- console.log(d.name, d.selected);
- return `instance ${d.selected ? 'active' : ''}`
- },
+ class: d => `instance ${d.selected ? 'active' : ''}`,
})
.transition()
.duration(serviceTopologyConfig.duration)
diff --git a/views/ngXosViews/diagnostic/src/js/rest_services.js b/views/ngXosViews/diagnostic/src/js/rest_services.js
index 93a9b90..396439c 100644
--- a/views/ngXosViews/diagnostic/src/js/rest_services.js
+++ b/views/ngXosViews/diagnostic/src/js/rest_services.js
@@ -70,6 +70,9 @@
$q.all(requests)
.then((list) => {
+
+ // adding devices
+
res.data.map((subscriber, i) => {
subscriber.devices = list[i];
subscriber.type = 'subscriber';