Bri Prebilic Cole
Committed by Gerrit Code Review

ONOS-1724 - GUI -- svgUnit tests written. WIP topoToolbar unit tests written. Fi…

…ring key presses programmatically investigated.

Change-Id: Ifff05859ebfebcee513d7fa8c42b52dc62f48f97
...@@ -53,6 +53,10 @@ ...@@ -53,6 +53,10 @@
53 ' is not a function'; 53 ' is not a function';
54 } 54 }
55 55
56 + if (!force) {
57 + bad.push('SvgUtilService: createDragBehavior(): ' +
58 + 'Bad force reference');
59 + }
56 if (!fSel) { 60 if (!fSel) {
57 bad.push(naf('selectCb')); 61 bad.push(naf('selectCb'));
58 } 62 }
...@@ -71,7 +75,6 @@ ...@@ -71,7 +75,6 @@
71 return null; 75 return null;
72 } 76 }
73 77
74 -
75 function dragged(d) { 78 function dragged(d) {
76 var threshold = draggedThreshold(force.alpha()), 79 var threshold = draggedThreshold(force.alpha()),
77 dx = d.oldX - d.px, 80 dx = d.oldX - d.px,
......
...@@ -18,21 +18,20 @@ ...@@ -18,21 +18,20 @@
18 ONOS GUI -- Layer -- Flash Service - Unit Tests 18 ONOS GUI -- Layer -- Flash Service - Unit Tests
19 */ 19 */
20 describe('factory: fw/layer/quickhelp.js', function () { 20 describe('factory: fw/layer/quickhelp.js', function () {
21 - var $log, $timeout, fs, qhs, d3Elem; 21 + var $log, fs, qhs, d3Elem;
22 22
23 beforeEach(module('onosUtil', 'onosSvg', 'onosLayer')); 23 beforeEach(module('onosUtil', 'onosSvg', 'onosLayer'));
24 24
25 - beforeEach(inject(function (_$log_, _$timeout_, FnService, QuickHelpService) { 25 + beforeEach(inject(function (_$log_, FnService, QuickHelpService) {
26 $log = _$log_; 26 $log = _$log_;
27 - //$timeout = _$timeout_;
28 fs = FnService; 27 fs = FnService;
29 qhs = QuickHelpService; 28 qhs = QuickHelpService;
30 - //jasmine.clock().install(); 29 + jasmine.clock().install();
31 d3Elem = d3.select('body').append('div').attr('id', 'myqhdiv'); 30 d3Elem = d3.select('body').append('div').attr('id', 'myqhdiv');
32 })); 31 }));
33 32
34 afterEach(function () { 33 afterEach(function () {
35 - //jasmine.clock().uninstall(); 34 + jasmine.clock().uninstall();
36 d3.select('#myqhdiv').remove(); 35 d3.select('#myqhdiv').remove();
37 }); 36 });
38 37
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
18 ONOS GUI -- SVG -- SVG Util Service - Unit Tests 18 ONOS GUI -- SVG -- SVG Util Service - Unit Tests
19 */ 19 */
20 describe('factory: fw/svg/svgUtil.js', function() { 20 describe('factory: fw/svg/svgUtil.js', function() {
21 - var $log, fs, sus, svg, d3Elem; 21 + var $log, fs, sus, svg, defs, force;
22 +
23 + var noop = function () {};
22 24
23 beforeEach(module('onosUtil', 'onosSvg')); 25 beforeEach(module('onosUtil', 'onosSvg'));
24 26
...@@ -27,7 +29,8 @@ describe('factory: fw/svg/svgUtil.js', function() { ...@@ -27,7 +29,8 @@ describe('factory: fw/svg/svgUtil.js', function() {
27 fs = FnService; 29 fs = FnService;
28 sus = SvgUtilService; 30 sus = SvgUtilService;
29 svg = d3.select('body').append('svg').attr('id', 'mySvg'); 31 svg = d3.select('body').append('svg').attr('id', 'mySvg');
30 - d3Elem = svg.append('defs'); 32 + defs = svg.append('defs');
33 + force = d3.layout.force();
31 })); 34 }));
32 35
33 afterEach(function () { 36 afterEach(function () {
...@@ -46,9 +49,100 @@ describe('factory: fw/svg/svgUtil.js', function() { ...@@ -46,9 +49,100 @@ describe('factory: fw/svg/svgUtil.js', function() {
46 ])).toBeTruthy(); 49 ])).toBeTruthy();
47 }); 50 });
48 51
52 + // === createDragBehavior
53 + // TODO: break up drag into separate functions for testing
54 + // d3 needs better testing support...
55 +
56 + // Note: just checking to see if error message was called
57 + // because jasmine spy isn't catching the right newline char
58 + it('should complain if function given no parameters', function () {
59 + spyOn($log, 'error');
60 + expect(sus.createDragBehavior()).toBeNull();
61 + expect($log.error).toHaveBeenCalled();
62 + });
63 +
64 + it('should complain if function is not given clickEnabled', function () {
65 + spyOn($log, 'error');
66 + expect(sus.createDragBehavior(force, noop, noop, noop)).toBeNull();
67 + expect($log.error).toHaveBeenCalled();
68 + });
69 +
70 + it('should complain if function is not given dragEnabled', function () {
71 + spyOn($log, 'error');
72 + expect(sus.createDragBehavior(force, noop, noop)).toBeNull();
73 + expect($log.error).toHaveBeenCalled();
74 + });
75 +
76 + it('should complain if function is not given atDragEnd', function () {
77 + spyOn($log, 'error');
78 + expect(sus.createDragBehavior(force, noop)).toBeNull();
79 + expect($log.error).toHaveBeenCalled();
80 + });
81 +
82 + it('should complain if function is not given selectCb', function () {
83 + spyOn($log, 'error');
84 + expect(sus.createDragBehavior(force)).toBeNull();
85 + expect($log.error).toHaveBeenCalled();
86 + });
87 +
88 + // === loadGlowDefs
89 + function checkAttrs(glow, r, g, b) {
90 + var filterEffects, feColor, feBlur, feMerge, feMergeNodes;
91 +
92 + // filter attrs
93 + expect(glow.attr('x')).toBe('-50%');
94 + expect(glow.attr('y')).toBe('-50%');
95 + expect(glow.attr('width')).toBe('200%');
96 + expect(glow.attr('height')).toBe('200%');
97 +
98 + filterEffects = d3.selectAll(glow.node().childNodes);
99 + expect(filterEffects.size()).toBe(3);
100 +
101 + // Note: d3 didn't recognize 'feColorMatrix' and others as valid selectors
102 + // this is a work around
103 + feColor = d3.select(filterEffects[0].shift());
104 + feBlur = d3.select(filterEffects[0].shift());
105 + feMerge = d3.select(filterEffects[0].shift());
106 +
107 + // feColorMatrix attrs
108 + expect(feColor.empty()).toBe(false);
109 + expect(feColor.attr('type')).toBe('matrix');
110 + expect(feColor.attr('values')).toBe(
111 + '0 0 0 0 ' + r + ' ' +
112 + '0 0 0 0 ' + g + ' ' +
113 + '0 0 0 0 ' + b + ' ' +
114 + '0 0 0 1 0 '
115 + );
116 +
117 + // feGuassianBlur attrs
118 + expect(feBlur.empty()).toBe(false);
119 + expect(feBlur.attr('stdDeviation')).toBe('3');
120 + expect(feBlur.attr('result')).toBe('coloredBlur');
49 121
50 - // TODO: add unit tests for drag behavior 122 + // feMerge attrs
51 - // TODO: add unit tests for loadGlowDefs 123 + feMergeNodes = d3.selectAll(feMerge.node().childNodes);
124 + expect(feMergeNodes.size()).toBe(2);
125 + expect(d3.select(feMergeNodes[0][0]).attr('in')).toBe('coloredBlur');
126 + expect(d3.select(feMergeNodes[0][1]).attr('in')).toBe('SourceGraphic');
127 + }
128 +
129 + it('should load glow definitions', function () {
130 + var blue, yellow;
131 + sus.loadGlowDefs(defs);
132 +
133 + expect(defs.empty()).toBe(false);
134 + expect((defs.selectAll('filter')).size()).toBe(2);
135 +
136 + // blue-glow specific
137 + blue = defs.select('#blue-glow');
138 + expect(blue.empty()).toBe(false);
139 + checkAttrs(blue, 0.0, 0.0, 0.7);
140 +
141 + // yellow-glow specific
142 + yellow = defs.select('#yellow-glow');
143 + expect(yellow.empty()).toBe(false);
144 + checkAttrs(yellow, 1.0, 1.0, 0.3);
145 + });
52 146
53 // === cat7 147 // === cat7
54 148
......
...@@ -55,8 +55,16 @@ describe('factory: fw/util/keys.js', function() { ...@@ -55,8 +55,16 @@ describe('factory: fw/util/keys.js', function() {
55 ])).toBeTruthy(); 55 ])).toBeTruthy();
56 }); 56 });
57 57
58 - // Code to emulate key presses.... 58 + // This no longer works because 'initKeyboardEvent' has been depreciated.
59 - // NOTE: kinda messy, but it seems to get the job done. 59 + // Now there is a constructor for 'KeyboardEvent' where you can modify
60 + // the new event with a dictionary(?) 'KeyboardEventInit'.
61 + // However, the below code has been so recently depreciated, there are no
62 + // examples online of how to use the new interface, and some browsers
63 + // don't support it still. These tests will have to be put off for a
64 + // while more. (Investigated 4/28/15)
65 + // Also tried was Angular's triggerHandler() function, but it doesn't seem
66 + // that it can take arguments about the event.
67 + // Using jQuery in tests might be a good idea, for triggering test events.
60 function jsKeyDown(element, code) { 68 function jsKeyDown(element, code) {
61 var ev = document.createEvent('KeyboardEvent'); 69 var ev = document.createEvent('KeyboardEvent');
62 70
...@@ -184,8 +192,9 @@ describe('factory: fw/util/keys.js', function() { ...@@ -184,8 +192,9 @@ describe('factory: fw/util/keys.js', function() {
184 expect(ks.keyBindings().viewFunction).toBeFalsy(); 192 expect(ks.keyBindings().viewFunction).toBeFalsy();
185 } 193 }
186 194
187 - // FIXME: jsKeyDown(...) no longer emulates key presses ?! :( 195 + // TODO: jsKeyDown(...) no longer emulates key presses ?! :(
188 // The following four unit tests ignored until we can figure this out. 196 // The following four unit tests ignored until we can figure this out.
197 + // INVESTIGATED: see jsKeyDown for details...
189 198
190 xit('should allow specific key bindings', function () { 199 xit('should allow specific key bindings', function () {
191 bindTestKeys(); 200 bindTestKeys();
......
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 -- Topo View -- Topo Toolbar Service - Unit Tests
19 + */
20 +describe('factory: view/topo/topoToolbar.js', function() {
21 + var $log, fs, tts, prefs, ps,
22 + d3Elem;
23 +
24 + beforeEach(module('ovTopo', 'onosUtil', 'onosLayer', 'ngRoute', 'onosNav',
25 + 'onosWidget'));
26 +
27 + beforeEach(inject(function (_$log_, FnService,
28 + TopoToolbarService, PanelService, PrefsService) {
29 + $log = _$log_;
30 + fs = FnService;
31 + tts = TopoToolbarService;
32 + prefs = PrefsService;
33 + ps = PanelService;
34 + d3Elem = d3.select('body').append('div').attr('id', 'floatpanels');
35 + ps.init();
36 + }));
37 +
38 + it('should define TopoToolbarService', function () {
39 + expect(tts).toBeDefined();
40 + });
41 +
42 + it('should define api functions', function () {
43 + expect(fs.areFunctions(tts, [
44 + 'init', 'createToolbar', 'destroyToolbar',
45 + 'keyListener', 'toggleToolbar'
46 + ])).toBeTruthy();
47 + });
48 +
49 + function verifyFirstRow() {
50 +
51 + }
52 +
53 + function verifySecondRow() {
54 +
55 + }
56 +
57 + function verifyThirdRow() {
58 +
59 + }
60 +
61 + it('should create a toolbar', function () {
62 + //var toolbar = tts.createToolbar('foo');
63 + //expect(toolbar).toBeTruthy();
64 + //expect(d3.select('#toolbar-foo').empty()).toBe(false);
65 + //verifyFirstRow();
66 + //verifySecondRow();
67 + //verifyThirdRow();
68 + });
69 +
70 +});
...\ No newline at end of file ...\ No newline at end of file