Simon Hunt

GUI -- augmented Key Service unit tests to include masked key test, and gesture notes test.

Change-Id: I4797cbb5baec6f05835b3fbc77952e47c059c5d1
......@@ -23,7 +23,7 @@
'use strict';
// references to injected services
var f;
var $log, f;
// internal state
var keyHandler = {
......@@ -156,13 +156,12 @@
viewKeys = d3.map(keyArg).keys();
viewKeys.forEach(function (key) {
if (keyHandler.maskedKeys[key]) {
masked.push(' Key "' + key + '" is reserved');
masked.push('setKeyBindings(): Key "' + key + '" is reserved');
}
});
if (masked.length) {
// TODO: use alert service
window.alert('WARNING...\n\nsetKeys():\n' + masked.join('\n'));
$log.warn(masked.join('\n'));
}
keyHandler.viewKeys = keyArg;
}
......@@ -182,8 +181,8 @@
};
}
// TODO: inject alert service
onos.factory('KeyService', ['FnService', function (fs) {
onos.factory('KeyService', ['$log', 'FnService', function ($l, fs) {
$log = $l;
f = fs;
return {
installOn: function (elem) {
......
......@@ -20,10 +20,29 @@
@author Simon Hunt
*/
describe('factory: fw/lib/keys.js', function() {
var ks, fs, d3Elem, elem, last;
var ks, fs, d3Elem, elem, last,
mockLog;
beforeEach(module('onosApp'));
// create mock log to verify warning was logged
beforeEach(module(function($provide) {
mockLog = {
warn: function (msg) {
mockLog._last.warn = msg;
},
_last: {},
_check: function (which) {
// destructive read
var m = mockLog._last[which];
mockLog._last[which] = null;
return m;
}
};
// tell angular to provide our mock, when '$log' service is requested
$provide.value('$log', mockLog);
}));
beforeEach(inject(function (KeyService, FnService) {
ks = KeyService;
fs = FnService;
......@@ -195,4 +214,45 @@ describe('factory: fw/lib/keys.js', function() {
verifyTestKeys();
});
it('should warn about masked keys', function () {
var k = {'space': cb, 'T': cb},
count = 0;
function cb() { count++; }
ks.keyBindings(k);
expect(mockLog._check('warn'))
.toEqual('setKeyBindings(): Key "T" is reserved');
// the 'T' key should NOT invoke our callback
expect(count).toEqual(0);
jsKeyDown(elem, 84); // 'T'
expect(count).toEqual(0);
// but the 'space' key SHOULD invoke our callback
jsKeyDown(elem, 32); // 'space'
expect(count).toEqual(1);
});
// === Gesture notes related tests
it('should start with no notes', function () {
expect(ks.gestureNotes()).toEqual([]);
});
it('should allow us to add nodes', function () {
var notes = [
['one', 'something about one'],
['two', 'description of two']
];
ks.gestureNotes(notes);
expect(ks.gestureNotes()).toEqual(notes);
});
it('should ignore non-arrays', function () {
ks.gestureNotes({foo:4});
expect(ks.gestureNotes()).toEqual([]);
});
// Consider adding test to ensure array contains 2-tuples of strings
});
......