Matteo Scandolo | 594dfbc | 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 | 4aae3aa | 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 | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 11 | |
Matteo Scandolo | 0b8b7ab | 2016-03-07 16:41:25 -0800 | [diff] [blame] | 12 | beforeEach(module('xos.diagnostic')); |
Matteo Scandolo | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 13 | |
| 14 | // inject the rackHelper service |
Matteo Scandolo | 4aae3aa | 2016-02-16 16:33:26 -0800 | [diff] [blame] | 15 | beforeEach(inject(function (_LogicTopologyHelper_, _serviceTopologyConfig_) { |
Matteo Scandolo | 594dfbc | 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 | 4aae3aa | 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 | 594dfbc | 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 | 4aae3aa | 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 | 594dfbc | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 59 | }); |
| 60 | }); |
| 61 | |
| 62 | })(); |