blob: 7ea10719091eacbecedd3bf2fd7eec8d6465f77f [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolocc0db942016-02-11 17:37:08 -080019(function () {
20 'use strict';
21
22 describe('The Logic Topology Helper Service', () => {
23
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080024 var Service, Config;
25
26 var x0, x1, x2, x3, x4;
27
28 var svgWidth = 900;
Matteo Scandolocc0db942016-02-11 17:37:08 -080029
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080030 beforeEach(module('xos.diagnostic'));
Matteo Scandolocc0db942016-02-11 17:37:08 -080031
32 // inject the rackHelper service
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080033 beforeEach(inject(function (_LogicTopologyHelper_, _serviceTopologyConfig_) {
Matteo Scandolocc0db942016-02-11 17:37:08 -080034 // The injector unwraps the underscores (_) from around the parameter names when matching
35 Service = _LogicTopologyHelper_;
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080036 Config = _serviceTopologyConfig_;
37
38 // result
39 let totalElWidth = Config.elWidths.reduce((el, val) => val + el, 0);
40 let remainingSpace = svgWidth - totalElWidth - (Config.widthMargin * 2);
41 let step = remainingSpace / (Config.elWidths.length - 1);
42 x0 = Config.widthMargin;
43 x1 = x0 + Config.elWidths[0] + step;
44 x2 = x1 + Config.elWidths[1] + step;
45 x3 = x2 + Config.elWidths[2] + step;
46 x4 = x3 + Config.elWidths[3] + step;
Matteo Scandolocc0db942016-02-11 17:37:08 -080047 }));
48
49 var customMatchers = {
50 toBeSimilar: () => {
51
52 const tolerance = 0.1;
53
54 return {
55 compare: (actual, expected) => {
56 return {
57 pass: (Math.abs(actual - expected) < tolerance),
58 message: `Expected ${actual} to be ${expected}`
59 }
60 }
61 }
62 }
63 };
64
65 beforeEach(function() {
66 jasmine.addMatchers(customMatchers);
67 });
68
69 it('should calculate horizontal position for each element', () => {
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080070 let [el0x, el1x, el2x, el3x, el4x] = Service.computeElementPosition(svgWidth);
Matteo Scandolo7e67a9a2016-02-16 16:33:26 -080071 expect(el0x).toBeSimilar(svgWidth - (x0 + (Config.elWidths[0] / 2)));
72 expect(el1x).toBeSimilar(svgWidth - (x1 + (Config.elWidths[1] / 2)));
73 expect(el2x).toBeSimilar(svgWidth - (x2 + (Config.elWidths[2] / 2)));
74 expect(el3x).toBeSimilar(svgWidth - (x3 + (Config.elWidths[3] / 2)));
75 expect(el4x).toBeSimilar(svgWidth - (x4 + (Config.elWidths[4] / 2)));
Matteo Scandolocc0db942016-02-11 17:37:08 -080076 });
77 });
78
79})();