Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | |
| 4 | describe('The Logic Topology Helper Service', () => { |
| 5 | |
Matteo Scandolo | 7e67a9a | 2016-02-16 16:33:26 -0800 | [diff] [blame] | 6 | var Service, Config; |
| 7 | |
| 8 | var x0, x1, x2, x3, x4; |
| 9 | |
| 10 | var svgWidth = 900; |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 11 | |
| 12 | beforeEach(module('xos.serviceTopology')); |
| 13 | |
| 14 | // inject the rackHelper service |
Matteo Scandolo | 7e67a9a | 2016-02-16 16:33:26 -0800 | [diff] [blame] | 15 | beforeEach(inject(function (_LogicTopologyHelper_, _serviceTopologyConfig_) { |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 16 | // The injector unwraps the underscores (_) from around the parameter names when matching |
| 17 | Service = _LogicTopologyHelper_; |
Matteo Scandolo | 7e67a9a | 2016-02-16 16:33:26 -0800 | [diff] [blame] | 18 | 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 Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 29 | })); |
| 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 Scandolo | 7e67a9a | 2016-02-16 16:33:26 -0800 | [diff] [blame] | 52 | 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 Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 59 | }); |
| 60 | }); |
| 61 | |
| 62 | })(); |