Simon Hunt

GUI -- refactored key service test to spy on $log service, instead of implementing our own mock.

Change-Id: I166972eed147ccf3d50d65454103922939b87e06
...@@ -20,30 +20,13 @@ ...@@ -20,30 +20,13 @@
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, $log,
24 - mockLog; 24 + d3Elem, elem, last;
25 25
26 beforeEach(module('onosApp')); 26 beforeEach(module('onosApp'));
27 27
28 - // create mock log to verify warning was logged 28 + beforeEach(inject(function (KeyService, FnService, _$log_) {
29 - beforeEach(module(function($provide) { 29 + $log = _$log_;
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 -
46 - beforeEach(inject(function (KeyService, FnService) {
47 ks = KeyService; 30 ks = KeyService;
48 fs = FnService; 31 fs = FnService;
49 d3Elem = d3.select('body').append('p').attr('id', 'ptest'); 32 d3Elem = d3.select('body').append('p').attr('id', 'ptest');
...@@ -217,12 +200,14 @@ describe('factory: fw/lib/keys.js', function() { ...@@ -217,12 +200,14 @@ describe('factory: fw/lib/keys.js', function() {
217 it('should warn about masked keys', function () { 200 it('should warn about masked keys', function () {
218 var k = {'space': cb, 'T': cb}, 201 var k = {'space': cb, 'T': cb},
219 count = 0; 202 count = 0;
203 +
220 function cb() { count++; } 204 function cb() { count++; }
221 205
206 + spyOn($log, 'warn');
207 +
222 ks.keyBindings(k); 208 ks.keyBindings(k);
223 209
224 - expect(mockLog._check('warn')) 210 + expect($log.warn).toHaveBeenCalledWith('setKeyBindings(): Key "T" is reserved');
225 - .toEqual('setKeyBindings(): Key "T" is reserved');
226 211
227 // the 'T' key should NOT invoke our callback 212 // the 'T' key should NOT invoke our callback
228 expect(count).toEqual(0); 213 expect(count).toEqual(0);
......