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

Change-Id: I377b6a1cf1845fb57e506e1a935970b49dbf0bbb
diff --git a/web/gui/src/main/webapp/app/fw/svg/glyph.js b/web/gui/src/main/webapp/app/fw/svg/glyph.js
index ab540a1..1775a11 100644
--- a/web/gui/src/main/webapp/app/fw/svg/glyph.js
+++ b/web/gui/src/main/webapp/app/fw/svg/glyph.js
@@ -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
             };
         }]);
 
diff --git a/web/gui/src/main/webapp/app/fw/util/fn.js b/web/gui/src/main/webapp/app/fw/util/fn.js
index 062da3a..5858e5a 100644
--- a/web/gui/src/main/webapp/app/fw/util/fn.js
+++ b/web/gui/src/main/webapp/app/fw/util/fn.js
@@ -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
             };
     }]);
 
diff --git a/web/gui/src/main/webapp/tests/README.txt b/web/gui/src/main/webapp/tests/README.txt
index 68837f4..213b484 100644
--- a/web/gui/src/main/webapp/tests/README.txt
+++ b/web/gui/src/main/webapp/tests/README.txt
@@ -13,3 +13,19 @@
 
 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.
diff --git a/web/gui/src/main/webapp/tests/app/fw/svg/glyph-spec.js b/web/gui/src/main/webapp/tests/app/fw/svg/glyph-spec.js
index 568a05b..524a160 100644
--- a/web/gui/src/main/webapp/tests/app/fw/svg/glyph-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/svg/glyph-spec.js
@@ -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 @@
         expect(gs).toBeDefined();
     });
 
+    it('should define four functions', function () {
+        expect(fs.areFunctions(gs, [
+            'init', 'register', 'ids', 'loadDefs'
+        ])).toBeTruthy();
+    });
+
     // TODO: unit tests for glyph functions
 });
diff --git a/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js b/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js
index 4b99942..d5c6fb2 100644
--- a/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js
@@ -158,4 +158,34 @@
         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();
+    });
+
+
 });