Matteo Scandolo
Committed by Gerrit Code Review

[WEB-GUI Tests] Fixing UI unit tests

Change-Id: I6eb28a706e148da17f8b2d7d5f8e44821851462a
......@@ -37,7 +37,4 @@ 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.
----------------------------------------------------------------------
FIXME
=====
Most of the skipped test were failing because of: `ReferenceError: userPrefs is not defined`
......
......@@ -45,9 +45,9 @@ describe('factory: fw/layer/flash.js', function () {
expect(flash).toBeDefined();
});
xit('should define api functions', function () {
it('should define api functions', function () {
expect(fs.areFunctions(flash, [
'initFlash', 'flash', 'enable'
'initFlash', 'flash', 'enable', 'tempDiv'
])).toBe(true);
});
......
......@@ -27,6 +27,8 @@ describe('factory: fw/layer/panel.js', function () {
$timeout = _$timeout_;
fs = FnService;
ps = PanelService;
spyOn(fs, 'debugOn').and.returnValue(true);
d3Elem = d3.select('body').append('div').attr('id', 'floatpanels');
ps.init();
}));
......@@ -44,7 +46,7 @@ describe('factory: fw/layer/panel.js', function () {
expect(ps).toBeDefined();
});
xit('should define api functions', function () {
it('should define api functions', function () {
expect(fs.areFunctions(ps, [
'init', 'createPanel', 'destroyPanel'
])).toBeTruthy();
......@@ -62,7 +64,7 @@ describe('factory: fw/layer/panel.js', function () {
expect(floatPanelSelection().size()).toBe(0);
});
xit('should create a default panel', function () {
it('should create a default panel', function () {
spyOn($log, 'warn');
spyOn($log, 'debug');
var p = ps.createPanel('foo');
......@@ -107,13 +109,13 @@ describe('factory: fw/layer/panel.js', function () {
expect(floatPanelSelection().size()).toBe(1);
});
xit('should note when there is no panel to destroy', function () {
it('should note when there is no panel to destroy', function () {
spyOn($log, 'debug');
ps.destroyPanel('bar');
expect($log.debug).toHaveBeenCalledWith('no panel to destroy:', 'bar');
});
xit('should destroy the panel', function () {
it('should destroy the panel', function () {
spyOn($log, 'debug');
var p = ps.createPanel('foo');
expect(floatPanelSelection().size()).toBe(1);
......@@ -123,7 +125,7 @@ describe('factory: fw/layer/panel.js', function () {
expect(floatPanelSelection().size()).toBe(0);
});
xit('should allow alternate settings to be given', function () {
it('should allow alternate settings to be given', function () {
spyOn($log, 'debug');
var p = ps.createPanel('foo', { width: 250, edge: 'left' });
expect($log.debug).toHaveBeenCalledWith('creating panel:', 'foo', {
......
......@@ -18,9 +18,7 @@
ONOS GUI -- Layer -- Veil Service - Unit Tests
*/
// FIXME ReferenceError: userPrefs is not defined
xdescribe('factory: fw/layer/veil.js', function () {
describe('factory: fw/layer/veil.js', function () {
var $log, $route, vs, fs, ks, gs;
beforeEach(module('onosLayer', 'onosNav', 'onosSvg', 'ngRoute', 'onosRemote'));
......
......@@ -18,9 +18,7 @@
ONOS GUI -- Masthead Controller - Unit Tests
*/
// FIXME ReferenceError: userPrefs is not defined
xdescribe('Controller: MastCtrl', function () {
describe('Controller: MastCtrl', function () {
// instantiate the masthead module
beforeEach(module('onosMast', 'onosUtil', 'onosLayer', 'onosWidget', 'onosSvg', 'onosRemote'));
......@@ -29,7 +27,8 @@ xdescribe('Controller: MastCtrl', function () {
// we need an instance of the controller
beforeEach(inject(function(_$log_, $controller, MastService, FnService) {
$log = _$log_;
ctrl = $controller('MastCtrl');
var $scope = {}
ctrl = $controller('MastCtrl', {$scope: $scope});
ms = MastService;
fs = FnService;
}));
......
......@@ -17,7 +17,7 @@
/*
ONOS GUI -- Remote -- REST Service - Unit Tests
*/
xdescribe('factory: fw/remote/rest.js', function() {
describe('factory: fw/remote/rest.js', function() {
var $log, $httpBackend, fs, rs, promise;
beforeEach(module('onosUtil', 'onosRemote'));
......@@ -27,7 +27,10 @@ xdescribe('factory: fw/remote/rest.js', function() {
return {
protocol: function () { return 'http'; },
host: function () { return 'foo'; },
port: function () { return '80'; }
port: function () { return '80'; },
search: function() {
return {debug: 'true'};
}
};
})
}));
......@@ -45,7 +48,8 @@ xdescribe('factory: fw/remote/rest.js', function() {
it('should define api functions', function () {
expect(fs.areFunctions(rs, [
'get'
'get',
'post'
])).toBeTruthy();
});
......
......@@ -18,9 +18,7 @@
ONOS GUI -- Remote -- General Functions - Unit Tests
*/
// FIXME TypeError: $loc.search is not a function
xdescribe('factory: fw/remote/urlfn.js', function () {
describe('factory: fw/remote/urlfn.js', function () {
var $log, $loc, ufs, fs;
var protocol, host, port;
......@@ -32,7 +30,10 @@ xdescribe('factory: fw/remote/urlfn.js', function () {
return {
protocol: function () { return protocol; },
host: function () { return host; },
port: function () { return port; }
port: function () { return port; },
search: function() {
return {debug: 'true'};
}
};
})
}));
......
......@@ -18,9 +18,7 @@
ONOS GUI -- Remote -- Web Socket Service - Unit Tests
*/
// FIXME TypeError: $loc.search is not a function
xdescribe('factory: fw/remote/websocket.js', function () {
describe('factory: fw/remote/websocket.js', function () {
var $log, fs, wss;
var noop = function () {},
......@@ -56,7 +54,10 @@ xdescribe('factory: fw/remote/websocket.js', function () {
return {
protocol: function () { return 'http'; },
host: function () { return 'foo'; },
port: function () { return '80'; }
port: function () { return '80'; },
search: function() {
return {debug: 'true'};
}
};
})
}));
......@@ -77,7 +78,9 @@ xdescribe('factory: fw/remote/websocket.js', function () {
expect(fs.areFunctions(wss, [
'resetSid', 'resetState',
'createWebSocket', 'bindHandlers', 'unbindHandlers',
'addOpenListener', 'removeOpenListener', 'sendEvent'
'addOpenListener', 'removeOpenListener', 'sendEvent',
'isConnected', 'loggedInUser',
'_setVeilDelegate', '_setLoadingDelegate'
])).toBeTruthy();
});
......
......@@ -18,7 +18,7 @@
ONOS GUI -- Remote -- Web Socket Event Service - Unit Tests
*/
// NOTE WsEventService does not exist
// NOTE WsEventService does not exist, it has been removed?
xdescribe('factory: fw/remote/wsevent.js', function () {
var $log, fs, wse;
......
......@@ -35,9 +35,9 @@ describe('factory: fw/svg/geodata.js', function() {
expect(gds).toBeDefined();
});
xit('should define api functions', function () {
it('should define api functions', function () {
expect(fs.areFunctions(gds, [
'clearCache', 'fetchTopoData', 'createPathGenerator'
'clearCache', 'fetchTopoData', 'createPathGenerator', 'rescaleProjection'
])).toBeTruthy();
});
......@@ -46,20 +46,20 @@ describe('factory: fw/svg/geodata.js', function() {
expect(promise).toBeNull();
});
xit('should augment the id of a bundled map', function () {
it('should augment the id of a bundled map', function () {
var id = '*foo';
promise = gds.fetchTopoData(id);
expect(promise.meta).toBeDefined();
expect(promise.meta.id).toBe(id);
expect(promise.meta.url).toBe('data/map/foo.json');
expect(promise.meta.url).toBe('data/map/foo.topojson');
});
xit('should treat an external id as the url itself', function () {
it('should treat an external id as the url itself', function () {
var id = 'some/path/to/foo';
promise = gds.fetchTopoData(id);
expect(promise.meta).toBeDefined();
expect(promise.meta.id).toBe(id);
expect(promise.meta.url).toBe(id + '.json');
expect(promise.meta.url).toBe(id + '.topojson');
});
it('should cache the returned objects', function () {
......@@ -91,16 +91,16 @@ describe('factory: fw/svg/geodata.js', function() {
});
xit('should log a warning if data fails to load', function () {
it('should log a warning if data fails to load', function () {
var id = 'foo';
$httpBackend.expectGET('foo.json').respond(404, 'Not found');
$httpBackend.expectGET('foo.topojson').respond(404, 'Not found');
spyOn($log, 'warn');
promise = gds.fetchTopoData(id);
$httpBackend.flush();
expect(promise.topodata).toBeUndefined();
expect($log.warn)
.toHaveBeenCalledWith('Failed to retrieve map TopoJSON data: foo.json',
.toHaveBeenCalledWith('Failed to retrieve map TopoJSON data: foo.topojson',
404, 'Not found');
});
......@@ -125,8 +125,8 @@ describe('factory: fw/svg/geodata.js', function() {
return simpleTopology({type: "LineString", arcs: [1, 2]});
}
xit('should use default settings if none are supplied', function () {
var gen = gds.createPathGenerator(simpleLineStringTopo());
it('should use default settings if none are supplied', function () {
var gen = gds.createPathGenerator(simpleLineStringTopo(), {adjustScale: true});
expect(gen.settings.objectTag).toBe('states');
expect(gen.settings.logicalSize).toBe(1000);
expect(gen.settings.mapFillScale).toBe(.95);
......@@ -143,8 +143,8 @@ describe('factory: fw/svg/geodata.js', function() {
expect(gen.settings.mapFillScale).toBe(.80);
});
xit('should create transformed geodata, and a path generator', function () {
var gen = gds.createPathGenerator(simpleLineStringTopo());
it('should create transformed geodata, and a path generator', function () {
var gen = gds.createPathGenerator(simpleLineStringTopo(), {adjustScale: true});
expect(fs.isO(gen.settings)).toBeTruthy();
expect(fs.isO(gen.geodata)).toBeTruthy();
expect(fs.isF(gen.pathgen)).toBeTruthy();
......
......@@ -25,10 +25,14 @@ describe('factory: fw/widget/chartBuilder.js', function () {
mockWss = {
bindHandlers: function () {},
sendEvent: function () {},
unbindHandlers: function () {}
unbindHandlers: function () {},
_setLoadingDelegate: function(){},
isConnected: function() {
return true;
}
};
beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg'));
beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer'));
beforeEach(function () {
module(function ($provide) {
......@@ -71,6 +75,7 @@ describe('factory: fw/widget/chartBuilder.js', function () {
expect(mockObj.scope.requestCallback).not.toBeDefined();
cbs.buildChart(mockObj);
expect(mockObj.scope.requestCallback).toBeDefined();
mockObj.scope.requestCallback();
expect(mockWss.sendEvent).toHaveBeenCalled();
});
......@@ -88,4 +93,4 @@ describe('factory: fw/widget/chartBuilder.js', function () {
mockObj.scope.$destroy();
expect(mockWss.unbindHandlers).toHaveBeenCalled();
});
}
\ No newline at end of file
});
......
......@@ -18,14 +18,18 @@
ONOS GUI -- Widget -- Table Builder Service - Unit Tests
*/
xdescribe('factory: fw/widget/tableBuilder.js', function () {
describe('factory: fw/widget/tableBuilder.js', function () {
var $log, $rootScope, fs, tbs, is;
var mockObj,
mockWss = {
bindHandlers: function () {},
sendEvent: function () {},
unbindHandlers: function () {}
unbindHandlers: function () {},
_setLoadingDelegate: function(){},
isConnected: function() {
return true;
}
};
beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg', 'onosLayer'));
......
......@@ -26,10 +26,11 @@ describe('Controller: OnosCtrl', function () {
// we need an instance of the controller
beforeEach(inject(function(_$log_, $controller) {
$log = _$log_;
ctrl = $controller('OnosCtrl');
var $scope = {};
ctrl = $controller('OnosCtrl', { $scope: $scope });
}));
xit('should report version 1.2.0', function () {
expect(ctrl.version).toEqual('1.2.0');
it('should report version 1.5.0', function () {
expect(ctrl.version).toEqual('1.5.0');
});
});
\ No newline at end of file
......
......@@ -40,7 +40,10 @@ module.exports = function(config) {
// unit test code...
'app/*-spec.js',
'app/**/*-spec.js'
'app/**/*-spec.js',
// server mock
'./server.mock.js'
],
......
......@@ -40,7 +40,10 @@ module.exports = function(config) {
// unit test code...
'app/*-spec.js',
'app/**/*-spec.js'
'app/**/*-spec.js',
// server mock
'./server.mock.js'
],
......
onosAuth = '';
userPrefs = {};
\ No newline at end of file