GUI -- augmented Key Service unit tests to include masked key test, and gesture notes test.
Change-Id: I4797cbb5baec6f05835b3fbc77952e47c059c5d1
Showing
2 changed files
with
66 additions
and
7 deletions
... | @@ -23,7 +23,7 @@ | ... | @@ -23,7 +23,7 @@ |
23 | 'use strict'; | 23 | 'use strict'; |
24 | 24 | ||
25 | // references to injected services | 25 | // references to injected services |
26 | - var f; | 26 | + var $log, f; |
27 | 27 | ||
28 | // internal state | 28 | // internal state |
29 | var keyHandler = { | 29 | var keyHandler = { |
... | @@ -156,13 +156,12 @@ | ... | @@ -156,13 +156,12 @@ |
156 | viewKeys = d3.map(keyArg).keys(); | 156 | viewKeys = d3.map(keyArg).keys(); |
157 | viewKeys.forEach(function (key) { | 157 | viewKeys.forEach(function (key) { |
158 | if (keyHandler.maskedKeys[key]) { | 158 | if (keyHandler.maskedKeys[key]) { |
159 | - masked.push(' Key "' + key + '" is reserved'); | 159 | + masked.push('setKeyBindings(): Key "' + key + '" is reserved'); |
160 | } | 160 | } |
161 | }); | 161 | }); |
162 | 162 | ||
163 | if (masked.length) { | 163 | if (masked.length) { |
164 | - // TODO: use alert service | 164 | + $log.warn(masked.join('\n')); |
165 | - window.alert('WARNING...\n\nsetKeys():\n' + masked.join('\n')); | ||
166 | } | 165 | } |
167 | keyHandler.viewKeys = keyArg; | 166 | keyHandler.viewKeys = keyArg; |
168 | } | 167 | } |
... | @@ -182,8 +181,8 @@ | ... | @@ -182,8 +181,8 @@ |
182 | }; | 181 | }; |
183 | } | 182 | } |
184 | 183 | ||
185 | - // TODO: inject alert service | 184 | + onos.factory('KeyService', ['$log', 'FnService', function ($l, fs) { |
186 | - onos.factory('KeyService', ['FnService', function (fs) { | 185 | + $log = $l; |
187 | f = fs; | 186 | f = fs; |
188 | return { | 187 | return { |
189 | installOn: function (elem) { | 188 | installOn: function (elem) { | ... | ... |
... | @@ -20,10 +20,29 @@ | ... | @@ -20,10 +20,29 @@ |
20 | @author Simon Hunt | 20 | @author Simon Hunt |
21 | */ | 21 | */ |
22 | describe('factory: fw/lib/keys.js', function() { | 22 | describe('factory: fw/lib/keys.js', function() { |
23 | - var ks, fs, d3Elem, elem, last; | 23 | + var ks, fs, d3Elem, elem, last, |
24 | + mockLog; | ||
24 | 25 | ||
25 | beforeEach(module('onosApp')); | 26 | beforeEach(module('onosApp')); |
26 | 27 | ||
28 | + // create mock log to verify warning was logged | ||
29 | + beforeEach(module(function($provide) { | ||
30 | + mockLog = { | ||
31 | + warn: function (msg) { | ||
32 | + mockLog._last.warn = msg; | ||
33 | + }, | ||
34 | + _last: {}, | ||
35 | + _check: function (which) { | ||
36 | + // destructive read | ||
37 | + var m = mockLog._last[which]; | ||
38 | + mockLog._last[which] = null; | ||
39 | + return m; | ||
40 | + } | ||
41 | + }; | ||
42 | + // tell angular to provide our mock, when '$log' service is requested | ||
43 | + $provide.value('$log', mockLog); | ||
44 | + })); | ||
45 | + | ||
27 | beforeEach(inject(function (KeyService, FnService) { | 46 | beforeEach(inject(function (KeyService, FnService) { |
28 | ks = KeyService; | 47 | ks = KeyService; |
29 | fs = FnService; | 48 | fs = FnService; |
... | @@ -195,4 +214,45 @@ describe('factory: fw/lib/keys.js', function() { | ... | @@ -195,4 +214,45 @@ describe('factory: fw/lib/keys.js', function() { |
195 | verifyTestKeys(); | 214 | verifyTestKeys(); |
196 | }); | 215 | }); |
197 | 216 | ||
217 | + it('should warn about masked keys', function () { | ||
218 | + var k = {'space': cb, 'T': cb}, | ||
219 | + count = 0; | ||
220 | + function cb() { count++; } | ||
221 | + | ||
222 | + ks.keyBindings(k); | ||
223 | + | ||
224 | + expect(mockLog._check('warn')) | ||
225 | + .toEqual('setKeyBindings(): Key "T" is reserved'); | ||
226 | + | ||
227 | + // the 'T' key should NOT invoke our callback | ||
228 | + expect(count).toEqual(0); | ||
229 | + jsKeyDown(elem, 84); // 'T' | ||
230 | + expect(count).toEqual(0); | ||
231 | + | ||
232 | + // but the 'space' key SHOULD invoke our callback | ||
233 | + jsKeyDown(elem, 32); // 'space' | ||
234 | + expect(count).toEqual(1); | ||
235 | + }); | ||
236 | + | ||
237 | + // === Gesture notes related tests | ||
238 | + it('should start with no notes', function () { | ||
239 | + expect(ks.gestureNotes()).toEqual([]); | ||
240 | + }); | ||
241 | + | ||
242 | + it('should allow us to add nodes', function () { | ||
243 | + var notes = [ | ||
244 | + ['one', 'something about one'], | ||
245 | + ['two', 'description of two'] | ||
246 | + ]; | ||
247 | + ks.gestureNotes(notes); | ||
248 | + | ||
249 | + expect(ks.gestureNotes()).toEqual(notes); | ||
250 | + }); | ||
251 | + | ||
252 | + it('should ignore non-arrays', function () { | ||
253 | + ks.gestureNotes({foo:4}); | ||
254 | + expect(ks.gestureNotes()).toEqual([]); | ||
255 | + }); | ||
256 | + | ||
257 | + // Consider adding test to ensure array contains 2-tuples of strings | ||
198 | }); | 258 | }); | ... | ... |
-
Please register or login to post a comment