GUI -- Sketching out GlyphService.
- Added areFunctions() to FnService. - First unit test for GlyphService. - Added note about debugging unit tests. Change-Id: I377b6a1cf1845fb57e506e1a935970b49dbf0bbb
Showing
5 changed files
with
102 additions
and
6 deletions
... | @@ -22,14 +22,38 @@ | ... | @@ -22,14 +22,38 @@ |
22 | (function () { | 22 | (function () { |
23 | 'use strict'; | 23 | 'use strict'; |
24 | 24 | ||
25 | - var $log; | 25 | + var $log, |
26 | + glyphs = d3.map(); | ||
26 | 27 | ||
27 | angular.module('onosSvg') | 28 | angular.module('onosSvg') |
28 | .factory('GlyphService', ['$log', function (_$log_) { | 29 | .factory('GlyphService', ['$log', function (_$log_) { |
29 | $log = _$log_; | 30 | $log = _$log_; |
30 | 31 | ||
32 | + | ||
33 | + function init() { | ||
34 | + // TODO: load the core set of glyphs | ||
35 | + | ||
36 | + } | ||
37 | + | ||
38 | + function register(viewBox, data, overwrite) { | ||
39 | + // TODO: register specified glyph definitions | ||
40 | + | ||
41 | + } | ||
42 | + | ||
43 | + function ids() { | ||
44 | + return glyphs.keys(); | ||
45 | + } | ||
46 | + | ||
47 | + function loadDefs(defs) { | ||
48 | + // TODO: clear defs element, then load all glyph definitions | ||
49 | + | ||
50 | + } | ||
51 | + | ||
31 | return { | 52 | return { |
32 | - tbd: function () {} | 53 | + init: init, |
54 | + register: register, | ||
55 | + ids: ids, | ||
56 | + loadDefs: loadDefs | ||
33 | }; | 57 | }; |
34 | }]); | 58 | }]); |
35 | 59 | ... | ... |
... | @@ -42,6 +42,23 @@ | ... | @@ -42,6 +42,23 @@ |
42 | return isA(a) && a.indexOf(x) > -1; | 42 | return isA(a) && a.indexOf(x) > -1; |
43 | } | 43 | } |
44 | 44 | ||
45 | + // Returns true if all names in the array are defined as functions | ||
46 | + // on the given api object; false otherwise. | ||
47 | + function areFunctions(api, fnNames) { | ||
48 | + if (!isA(fnNames)) { | ||
49 | + return false; | ||
50 | + } | ||
51 | + var n = fnNames.length, | ||
52 | + i, name; | ||
53 | + for (i=0; i<n; i++) { | ||
54 | + name = fnNames[i]; | ||
55 | + if (!isF(api[name])) { | ||
56 | + return false; | ||
57 | + } | ||
58 | + } | ||
59 | + return true; | ||
60 | + } | ||
61 | + | ||
45 | angular.module('onosUtil') | 62 | angular.module('onosUtil') |
46 | .factory('FnService', [function () { | 63 | .factory('FnService', [function () { |
47 | return { | 64 | return { |
... | @@ -49,7 +66,8 @@ | ... | @@ -49,7 +66,8 @@ |
49 | isA: isA, | 66 | isA: isA, |
50 | isS: isS, | 67 | isS: isS, |
51 | isO: isO, | 68 | isO: isO, |
52 | - contains: contains | 69 | + contains: contains, |
70 | + areFunctions: areFunctions | ||
53 | }; | 71 | }; |
54 | }]); | 72 | }]); |
55 | 73 | ... | ... |
... | @@ -13,3 +13,19 @@ This will launch and capture a browser, install and run the unit tests. | ... | @@ -13,3 +13,19 @@ This will launch and capture a browser, install and run the unit tests. |
13 | 13 | ||
14 | The configuration is currently set to re-run the tests every time a | 14 | The configuration is currently set to re-run the tests every time a |
15 | file change is detected, (i.e. each time a source file is saved). | 15 | file change is detected, (i.e. each time a source file is saved). |
16 | + | ||
17 | +---------------------------------------------------------------------- | ||
18 | +Useful Notes | ||
19 | +============ | ||
20 | + | ||
21 | +Set a 'breakpoint' with the debugger command: | ||
22 | + | ||
23 | + it('should define four functions', function () { | ||
24 | + debugger; | ||
25 | + | ||
26 | + expect(fs.isF(gs.init)).toBeTruthy(); | ||
27 | + // ... | ||
28 | + }); | ||
29 | + | ||
30 | +Open Developer Tools in the captured Chrome browser, and reload the page. | ||
31 | +The debugger will break at the given point, allowing you to inspect context. | ... | ... |
... | @@ -20,11 +20,13 @@ | ... | @@ -20,11 +20,13 @@ |
20 | @author Simon Hunt | 20 | @author Simon Hunt |
21 | */ | 21 | */ |
22 | describe('factory: fw/svg/glyph.js', function() { | 22 | describe('factory: fw/svg/glyph.js', function() { |
23 | - var gs; | 23 | + var $log, fs, gs; |
24 | 24 | ||
25 | - beforeEach(module('onosSvg')); | 25 | + beforeEach(module('onosUtil', 'onosSvg')); |
26 | 26 | ||
27 | - beforeEach(inject(function (GlyphService) { | 27 | + beforeEach(inject(function (_$log_, FnService, GlyphService) { |
28 | + $log = _$log_; | ||
29 | + fs = FnService; | ||
28 | gs = GlyphService; | 30 | gs = GlyphService; |
29 | })); | 31 | })); |
30 | 32 | ||
... | @@ -32,5 +34,11 @@ describe('factory: fw/svg/glyph.js', function() { | ... | @@ -32,5 +34,11 @@ describe('factory: fw/svg/glyph.js', function() { |
32 | expect(gs).toBeDefined(); | 34 | expect(gs).toBeDefined(); |
33 | }); | 35 | }); |
34 | 36 | ||
37 | + it('should define four functions', function () { | ||
38 | + expect(fs.areFunctions(gs, [ | ||
39 | + 'init', 'register', 'ids', 'loadDefs' | ||
40 | + ])).toBeTruthy(); | ||
41 | + }); | ||
42 | + | ||
35 | // TODO: unit tests for glyph functions | 43 | // TODO: unit tests for glyph functions |
36 | }); | 44 | }); | ... | ... |
... | @@ -158,4 +158,34 @@ describe('factory: fw/util/fn.js', function() { | ... | @@ -158,4 +158,34 @@ describe('factory: fw/util/fn.js', function() { |
158 | expect(fs.contains(someArray, 109)).toBeFalsy(); | 158 | expect(fs.contains(someArray, 109)).toBeFalsy(); |
159 | expect(fs.contains(stringArray, 'zonko')).toBeFalsy(); | 159 | expect(fs.contains(stringArray, 'zonko')).toBeFalsy(); |
160 | }); | 160 | }); |
161 | + | ||
162 | + // === Tests for areFunctions() | ||
163 | + it('areFunctions(): false for non-array', function () { | ||
164 | + expect(fs.areFunctions({}, 'not-an-array')).toBeFalsy(); | ||
165 | + }); | ||
166 | + it('areFunctions(): true for empty-array', function () { | ||
167 | + expect(fs.areFunctions({}, [])).toBeTruthy(); | ||
168 | + }); | ||
169 | + it('areFunctions(): true for some api', function () { | ||
170 | + expect(fs.areFunctions({ | ||
171 | + a: function () {}, | ||
172 | + b: function () {} | ||
173 | + }, ['b', 'a'])).toBeTruthy(); | ||
174 | + }); | ||
175 | + it('areFunctions(): false for some other api', function () { | ||
176 | + expect(fs.areFunctions({ | ||
177 | + a: function () {}, | ||
178 | + b: 'not-a-function' | ||
179 | + }, ['b', 'a'])).toBeFalsy(); | ||
180 | + }); | ||
181 | + it('areFunctions(): extraneous stuff ignored', function () { | ||
182 | + expect(fs.areFunctions({ | ||
183 | + a: function () {}, | ||
184 | + b: function () {}, | ||
185 | + c: 1, | ||
186 | + d: 'foo' | ||
187 | + }, ['a', 'b'])).toBeTruthy(); | ||
188 | + }); | ||
189 | + | ||
190 | + | ||
161 | }); | 191 | }); | ... | ... |
-
Please register or login to post a comment