Simon Hunt

GUI -- Sketching out GlyphService.

- Added areFunctions() to FnService.
- First unit test for GlyphService.
- Added note about debugging unit tests.

Change-Id: I377b6a1cf1845fb57e506e1a935970b49dbf0bbb
......@@ -22,14 +22,38 @@
(function () {
'use strict';
var $log;
var $log,
glyphs = d3.map();
angular.module('onosSvg')
.factory('GlyphService', ['$log', function (_$log_) {
$log = _$log_;
function init() {
// TODO: load the core set of glyphs
}
function register(viewBox, data, overwrite) {
// TODO: register specified glyph definitions
}
function ids() {
return glyphs.keys();
}
function loadDefs(defs) {
// TODO: clear defs element, then load all glyph definitions
}
return {
tbd: function () {}
init: init,
register: register,
ids: ids,
loadDefs: loadDefs
};
}]);
......
......@@ -42,6 +42,23 @@
return isA(a) && a.indexOf(x) > -1;
}
// Returns true if all names in the array are defined as functions
// on the given api object; false otherwise.
function areFunctions(api, fnNames) {
if (!isA(fnNames)) {
return false;
}
var n = fnNames.length,
i, name;
for (i=0; i<n; i++) {
name = fnNames[i];
if (!isF(api[name])) {
return false;
}
}
return true;
}
angular.module('onosUtil')
.factory('FnService', [function () {
return {
......@@ -49,7 +66,8 @@
isA: isA,
isS: isS,
isO: isO,
contains: contains
contains: contains,
areFunctions: areFunctions
};
}]);
......
......@@ -13,3 +13,19 @@ This will launch and capture a browser, install and run the unit tests.
The configuration is currently set to re-run the tests every time a
file change is detected, (i.e. each time a source file is saved).
----------------------------------------------------------------------
Useful Notes
============
Set a 'breakpoint' with the debugger command:
it('should define four functions', function () {
debugger;
expect(fs.isF(gs.init)).toBeTruthy();
// ...
});
Open Developer Tools in the captured Chrome browser, and reload the page.
The debugger will break at the given point, allowing you to inspect context.
......
......@@ -20,11 +20,13 @@
@author Simon Hunt
*/
describe('factory: fw/svg/glyph.js', function() {
var gs;
var $log, fs, gs;
beforeEach(module('onosSvg'));
beforeEach(module('onosUtil', 'onosSvg'));
beforeEach(inject(function (GlyphService) {
beforeEach(inject(function (_$log_, FnService, GlyphService) {
$log = _$log_;
fs = FnService;
gs = GlyphService;
}));
......@@ -32,5 +34,11 @@ describe('factory: fw/svg/glyph.js', function() {
expect(gs).toBeDefined();
});
it('should define four functions', function () {
expect(fs.areFunctions(gs, [
'init', 'register', 'ids', 'loadDefs'
])).toBeTruthy();
});
// TODO: unit tests for glyph functions
});
......
......@@ -158,4 +158,34 @@ describe('factory: fw/util/fn.js', function() {
expect(fs.contains(someArray, 109)).toBeFalsy();
expect(fs.contains(stringArray, 'zonko')).toBeFalsy();
});
// === Tests for areFunctions()
it('areFunctions(): false for non-array', function () {
expect(fs.areFunctions({}, 'not-an-array')).toBeFalsy();
});
it('areFunctions(): true for empty-array', function () {
expect(fs.areFunctions({}, [])).toBeTruthy();
});
it('areFunctions(): true for some api', function () {
expect(fs.areFunctions({
a: function () {},
b: function () {}
}, ['b', 'a'])).toBeTruthy();
});
it('areFunctions(): false for some other api', function () {
expect(fs.areFunctions({
a: function () {},
b: 'not-a-function'
}, ['b', 'a'])).toBeFalsy();
});
it('areFunctions(): extraneous stuff ignored', function () {
expect(fs.areFunctions({
a: function () {},
b: function () {},
c: 1,
d: 'foo'
}, ['a', 'b'])).toBeTruthy();
});
});
......