blob: 6fb1a6010a5ca3c5951f37c52b8bbe9655ff1842 [file] [log] [blame]
Simon Hunt737c89f2015-01-28 12:23:19 -08001/*
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 */
20describe('factory: fw/svg/svgUtil.js', function() {
Simon Hunt7c8ab8d2015-02-03 15:05:15 -080021 var $log, fs, sus, svg, d3Elem;
Simon Hunt737c89f2015-01-28 12:23:19 -080022
23 beforeEach(module('onosUtil', 'onosSvg'));
24
25 beforeEach(inject(function (_$log_, FnService, SvgUtilService) {
26 $log = _$log_;
27 fs = FnService;
28 sus = SvgUtilService;
Simon Hunt7c8ab8d2015-02-03 15:05:15 -080029 svg = d3.select('body').append('svg').attr('id', 'mySvg');
30 d3Elem = svg.append('defs');
Simon Hunt737c89f2015-01-28 12:23:19 -080031 }));
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 Hunt7c8ab8d2015-02-03 15:05:15 -080043 'createDragBehavior', 'loadGlow', 'cat7', 'translate', 'stripPx',
Simon Hunt18bf9822015-02-12 17:35:45 -080044 'safeId', 'visible'
Simon Hunt737c89f2015-01-28 12:23:19 -080045 ])).toBeTruthy();
46 });
47
Simon Hunt4b668592015-01-29 17:33:53 -080048
49 // TODO: add unit tests for drag behavior
50 // TODO: add unit tests for loadGlow
Simon Hunt4b668592015-01-29 17:33:53 -080051
Simon Hunt48e61672015-01-30 14:48:25 -080052 // === cat7
53
54 it('should define two methods on the api', function () {
55 var cat7 = sus.cat7();
56 expect(fs.areFunctions(cat7, [
57 'testCard', 'getColor'
58 ])).toBeTruthy();
59 });
60
61 it('should provide a certain shade of blue', function () {
62 expect(sus.cat7().getColor('foo', false, 'light')).toEqual('#3E5780');
63 });
64
65 it('should not matter what the ID really is for shade of blue', function () {
66 expect(sus.cat7().getColor('bar', false, 'light')).toEqual('#3E5780');
67 });
68
69 it('should provide different shade of blue for muted', function () {
70 expect(sus.cat7().getColor('foo', true, 'light')).toEqual('#A8B8CC');
71 });
72
73
74 it('should provide an alternate (dark) shade of blue', function () {
Simon Hunt27e153a2015-02-02 18:45:44 -080075 expect(sus.cat7().getColor('foo', false, 'dark')).toEqual('#304860');
Simon Hunt48e61672015-01-30 14:48:25 -080076 });
77
78 it('should provide an alternate (dark) shade of blue for muted', function () {
Simon Hunt5724fb42015-02-05 16:59:40 -080079 expect(sus.cat7().getColor('foo', true, 'dark')).toEqual('#304860');
Simon Hunt48e61672015-01-30 14:48:25 -080080 });
81
82 it('should iterate across the colors', function () {
83 expect(sus.cat7().getColor('foo', false, 'light')).toEqual('#3E5780');
84 expect(sus.cat7().getColor('bar', false, 'light')).toEqual('#78533B');
85 expect(sus.cat7().getColor('baz', false, 'light')).toEqual('#CB4D28');
86 expect(sus.cat7().getColor('goo', false, 'light')).toEqual('#018D61');
87 expect(sus.cat7().getColor('zoo', false, 'light')).toEqual('#8A2979');
88 expect(sus.cat7().getColor('pip', false, 'light')).toEqual('#006D73');
89 expect(sus.cat7().getColor('sdh', false, 'light')).toEqual('#56AF00');
90 // and cycle back to the first color for item #8
91 expect(sus.cat7().getColor('bri', false, 'light')).toEqual('#3E5780');
92 // and return the same color for the same ID
93 expect(sus.cat7().getColor('zoo', false, 'light')).toEqual('#8A2979');
94 });
Simon Hunt4b668592015-01-29 17:33:53 -080095
96 // === translate()
Simon Huntc9b73162015-01-29 14:02:15 -080097
98 it('should translate from two args', function () {
99 expect(sus.translate(1,2)).toEqual('translate(1,2)');
100 });
101
102 it('should translate from an array', function () {
103 expect(sus.translate([3,4])).toEqual('translate(3,4)');
104 });
105
Simon Hunt4b668592015-01-29 17:33:53 -0800106
107 // === stripPx()
108
109 it('should not affect a number', function () {
110 expect(sus.stripPx('4')).toEqual('4');
111 });
112
113 it('should remove trailing px', function () {
114 expect(sus.stripPx('4px')).toEqual('4');
115 });
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800116
Simon Hunt18bf9822015-02-12 17:35:45 -0800117 // === visible()
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800118
119 it('should hide and show an element', function () {
120 var r = svg.append('rect');
121
Simon Hunt18bf9822015-02-12 17:35:45 -0800122 sus.visible(r, false);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800123 expect(r.style('visibility')).toEqual('hidden');
Simon Hunt18bf9822015-02-12 17:35:45 -0800124 expect(sus.visible(r)).toBe(false);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800125
Simon Hunt18bf9822015-02-12 17:35:45 -0800126 sus.visible(r, true);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800127 expect(r.style('visibility')).toEqual('visible');
Simon Hunt18bf9822015-02-12 17:35:45 -0800128 expect(sus.visible(r)).toBe(true);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800129 });
Simon Hunt737c89f2015-01-28 12:23:19 -0800130});