Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- SVG -- SVG Util Service - Unit Tests |
| 19 | */ |
| 20 | describe('factory: fw/svg/svgUtil.js', function() { |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 21 | var $log, fs, sus, svg, d3Elem; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 22 | |
| 23 | beforeEach(module('onosUtil', 'onosSvg')); |
| 24 | |
| 25 | beforeEach(inject(function (_$log_, FnService, SvgUtilService) { |
| 26 | $log = _$log_; |
| 27 | fs = FnService; |
| 28 | sus = SvgUtilService; |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 29 | svg = d3.select('body').append('svg').attr('id', 'mySvg'); |
| 30 | d3Elem = svg.append('defs'); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 31 | })); |
| 32 | |
| 33 | afterEach(function () { |
| 34 | d3.select('svg').remove(); |
| 35 | }); |
| 36 | |
| 37 | it('should define SvgUtilService', function () { |
| 38 | expect(sus).toBeDefined(); |
| 39 | }); |
| 40 | |
| 41 | it('should define api functions', function () { |
| 42 | expect(fs.areFunctions(sus, [ |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame^] | 43 | 'createDragBehavior', 'loadGlowDefs', 'cat7', |
| 44 | 'translate', |
| 45 | 'stripPx', 'safeId', 'visible' |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 46 | ])).toBeTruthy(); |
| 47 | }); |
| 48 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 49 | |
| 50 | // TODO: add unit tests for drag behavior |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame^] | 51 | // TODO: add unit tests for loadGlowDefs |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 52 | |
Simon Hunt | 48e6167 | 2015-01-30 14:48:25 -0800 | [diff] [blame] | 53 | // === cat7 |
| 54 | |
| 55 | it('should define two methods on the api', function () { |
| 56 | var cat7 = sus.cat7(); |
| 57 | expect(fs.areFunctions(cat7, [ |
| 58 | 'testCard', 'getColor' |
| 59 | ])).toBeTruthy(); |
| 60 | }); |
| 61 | |
| 62 | it('should provide a certain shade of blue', function () { |
| 63 | expect(sus.cat7().getColor('foo', false, 'light')).toEqual('#3E5780'); |
| 64 | }); |
| 65 | |
| 66 | it('should not matter what the ID really is for shade of blue', function () { |
| 67 | expect(sus.cat7().getColor('bar', false, 'light')).toEqual('#3E5780'); |
| 68 | }); |
| 69 | |
| 70 | it('should provide different shade of blue for muted', function () { |
| 71 | expect(sus.cat7().getColor('foo', true, 'light')).toEqual('#A8B8CC'); |
| 72 | }); |
| 73 | |
| 74 | |
| 75 | it('should provide an alternate (dark) shade of blue', function () { |
Simon Hunt | 27e153a | 2015-02-02 18:45:44 -0800 | [diff] [blame] | 76 | expect(sus.cat7().getColor('foo', false, 'dark')).toEqual('#304860'); |
Simon Hunt | 48e6167 | 2015-01-30 14:48:25 -0800 | [diff] [blame] | 77 | }); |
| 78 | |
| 79 | it('should provide an alternate (dark) shade of blue for muted', function () { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 80 | expect(sus.cat7().getColor('foo', true, 'dark')).toEqual('#304860'); |
Simon Hunt | 48e6167 | 2015-01-30 14:48:25 -0800 | [diff] [blame] | 81 | }); |
| 82 | |
| 83 | it('should iterate across the colors', function () { |
| 84 | expect(sus.cat7().getColor('foo', false, 'light')).toEqual('#3E5780'); |
| 85 | expect(sus.cat7().getColor('bar', false, 'light')).toEqual('#78533B'); |
| 86 | expect(sus.cat7().getColor('baz', false, 'light')).toEqual('#CB4D28'); |
| 87 | expect(sus.cat7().getColor('goo', false, 'light')).toEqual('#018D61'); |
| 88 | expect(sus.cat7().getColor('zoo', false, 'light')).toEqual('#8A2979'); |
| 89 | expect(sus.cat7().getColor('pip', false, 'light')).toEqual('#006D73'); |
| 90 | expect(sus.cat7().getColor('sdh', false, 'light')).toEqual('#56AF00'); |
| 91 | // and cycle back to the first color for item #8 |
| 92 | expect(sus.cat7().getColor('bri', false, 'light')).toEqual('#3E5780'); |
| 93 | // and return the same color for the same ID |
| 94 | expect(sus.cat7().getColor('zoo', false, 'light')).toEqual('#8A2979'); |
| 95 | }); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 96 | |
| 97 | // === translate() |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 98 | |
| 99 | it('should translate from two args', function () { |
| 100 | expect(sus.translate(1,2)).toEqual('translate(1,2)'); |
| 101 | }); |
| 102 | |
| 103 | it('should translate from an array', function () { |
| 104 | expect(sus.translate([3,4])).toEqual('translate(3,4)'); |
| 105 | }); |
| 106 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 107 | |
| 108 | // === stripPx() |
| 109 | |
| 110 | it('should not affect a number', function () { |
| 111 | expect(sus.stripPx('4')).toEqual('4'); |
| 112 | }); |
| 113 | |
| 114 | it('should remove trailing px', function () { |
| 115 | expect(sus.stripPx('4px')).toEqual('4'); |
| 116 | }); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 117 | |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 118 | // === visible() |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 119 | |
| 120 | it('should hide and show an element', function () { |
| 121 | var r = svg.append('rect'); |
| 122 | |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 123 | sus.visible(r, false); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 124 | expect(r.style('visibility')).toEqual('hidden'); |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 125 | expect(sus.visible(r)).toBe(false); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 126 | |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 127 | sus.visible(r, true); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 128 | expect(r.style('visibility')).toEqual('visible'); |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 129 | expect(sus.visible(r)).toBe(true); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 130 | }); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 131 | }); |