blob: 94307f56aa711f3be8777c08d5812b88d2dfcc4d [file] [log] [blame]
Matteo Scandolocc0db942016-02-11 17:37:08 -08001(function () {
2 'use strict';
3
4 describe('The Logic Topology Helper Service', () => {
5
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -08006 var Service, Config;
7
8 var x0, x1, x2, x3, x4;
9
10 var svgWidth = 900;
Matteo Scandolocc0db942016-02-11 17:37:08 -080011
12 beforeEach(module('xos.serviceTopology'));
13
14 // inject the rackHelper service
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080015 beforeEach(inject(function (_LogicTopologyHelper_, _serviceTopologyConfig_) {
Matteo Scandolocc0db942016-02-11 17:37:08 -080016 // The injector unwraps the underscores (_) from around the parameter names when matching
17 Service = _LogicTopologyHelper_;
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080018 Config = _serviceTopologyConfig_;
19
20 // result
21 let totalElWidth = Config.elWidths.reduce((el, val) => val + el, 0);
22 let remainingSpace = svgWidth - totalElWidth - (Config.widthMargin * 2);
23 let step = remainingSpace / (Config.elWidths.length - 1);
24 x0 = Config.widthMargin;
25 x1 = x0 + Config.elWidths[0] + step;
26 x2 = x1 + Config.elWidths[1] + step;
27 x3 = x2 + Config.elWidths[2] + step;
28 x4 = x3 + Config.elWidths[3] + step;
Matteo Scandolocc0db942016-02-11 17:37:08 -080029 }));
30
31 var customMatchers = {
32 toBeSimilar: () => {
33
34 const tolerance = 0.1;
35
36 return {
37 compare: (actual, expected) => {
38 return {
39 pass: (Math.abs(actual - expected) < tolerance),
40 message: `Expected ${actual} to be ${expected}`
41 }
42 }
43 }
44 }
45 };
46
47 beforeEach(function() {
48 jasmine.addMatchers(customMatchers);
49 });
50
51 it('should calculate horizontal position for each element', () => {
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080052 let [el0x, el1x, el2x, el3x, el4x] = Service.computeElementPosition(svgWidth);
53 console.log(x1, el1x);
54 expect(el0x).toBeSimilar(svgWidth - (x0 + (Config.elWidths[0] / 2)));
55 expect(el1x).toBeSimilar(svgWidth - (x1 + (Config.elWidths[1] / 2)));
56 expect(el2x).toBeSimilar(svgWidth - (x2 + (Config.elWidths[2] / 2)));
57 expect(el3x).toBeSimilar(svgWidth - (x3 + (Config.elWidths[3] / 2)));
58 expect(el4x).toBeSimilar(svgWidth - (x4 + (Config.elWidths[4] / 2)));
Matteo Scandolocc0db942016-02-11 17:37:08 -080059 });
60 });
61
62})();