[WEB-GUI Tests] Fixing UI unit tests
Change-Id: I6eb28a706e148da17f8b2d7d5f8e44821851462a
diff --git a/web/gui/src/main/webapp/tests/README.txt b/web/gui/src/main/webapp/tests/README.txt
index 1a6b767..831bf9a 100644
--- a/web/gui/src/main/webapp/tests/README.txt
+++ b/web/gui/src/main/webapp/tests/README.txt
@@ -37,7 +37,4 @@
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`
diff --git a/web/gui/src/main/webapp/tests/app/fw/layer/flash-spec.js b/web/gui/src/main/webapp/tests/app/fw/layer/flash-spec.js
index 7d9a982..4c08cd5 100644
--- a/web/gui/src/main/webapp/tests/app/fw/layer/flash-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/layer/flash-spec.js
@@ -45,9 +45,9 @@
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);
});
diff --git a/web/gui/src/main/webapp/tests/app/fw/layer/panel-spec.js b/web/gui/src/main/webapp/tests/app/fw/layer/panel-spec.js
index 452a4be..07a1b35 100644
--- a/web/gui/src/main/webapp/tests/app/fw/layer/panel-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/layer/panel-spec.js
@@ -27,6 +27,8 @@
$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 @@
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 @@
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 @@
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 @@
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', {
diff --git a/web/gui/src/main/webapp/tests/app/fw/layer/veil-spec.js b/web/gui/src/main/webapp/tests/app/fw/layer/veil-spec.js
index 0b80e89..49f2d96 100644
--- a/web/gui/src/main/webapp/tests/app/fw/layer/veil-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/layer/veil-spec.js
@@ -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'));
diff --git a/web/gui/src/main/webapp/tests/app/fw/mast/mast-spec.js b/web/gui/src/main/webapp/tests/app/fw/mast/mast-spec.js
index 34d0a03..0178d8a 100644
--- a/web/gui/src/main/webapp/tests/app/fw/mast/mast-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/mast/mast-spec.js
@@ -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 @@
// 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;
}));
diff --git a/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js b/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js
index a8916e7..cd859ba 100644
--- a/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js
@@ -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 @@
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 @@
it('should define api functions', function () {
expect(fs.areFunctions(rs, [
- 'get'
+ 'get',
+ 'post'
])).toBeTruthy();
});
diff --git a/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js b/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js
index 9c35976..a998e0a 100644
--- a/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js
@@ -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 @@
return {
protocol: function () { return protocol; },
host: function () { return host; },
- port: function () { return port; }
+ port: function () { return port; },
+ search: function() {
+ return {debug: 'true'};
+ }
};
})
}));
diff --git a/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js b/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js
index 9e211bc..c3599cb 100644
--- a/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js
@@ -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 @@
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 @@
expect(fs.areFunctions(wss, [
'resetSid', 'resetState',
'createWebSocket', 'bindHandlers', 'unbindHandlers',
- 'addOpenListener', 'removeOpenListener', 'sendEvent'
+ 'addOpenListener', 'removeOpenListener', 'sendEvent',
+ 'isConnected', 'loggedInUser',
+ '_setVeilDelegate', '_setLoadingDelegate'
])).toBeTruthy();
});
diff --git a/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js b/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js
index 6e3bbf8..a06aa9d 100644
--- a/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js
@@ -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;
diff --git a/web/gui/src/main/webapp/tests/app/fw/svg/geodata-spec.js b/web/gui/src/main/webapp/tests/app/fw/svg/geodata-spec.js
index 20406dd..52705f0 100644
--- a/web/gui/src/main/webapp/tests/app/fw/svg/geodata-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/svg/geodata-spec.js
@@ -35,9 +35,9 @@
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 @@
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 @@
});
- 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 @@
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 @@
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();
diff --git a/web/gui/src/main/webapp/tests/app/fw/widget/chartBuilder-spec.js b/web/gui/src/main/webapp/tests/app/fw/widget/chartBuilder-spec.js
index 7780c7f..b500526 100644
--- a/web/gui/src/main/webapp/tests/app/fw/widget/chartBuilder-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/widget/chartBuilder-spec.js
@@ -25,10 +25,14 @@
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 @@
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 @@
mockObj.scope.$destroy();
expect(mockWss.unbindHandlers).toHaveBeenCalled();
});
-}
\ No newline at end of file
+});
diff --git a/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js b/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js
index 4564a26..7b66d76 100644
--- a/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js
@@ -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'));
diff --git a/web/gui/src/main/webapp/tests/app/onos-spec.js b/web/gui/src/main/webapp/tests/app/onos-spec.js
index f311e72..c7df8d8 100644
--- a/web/gui/src/main/webapp/tests/app/onos-spec.js
+++ b/web/gui/src/main/webapp/tests/app/onos-spec.js
@@ -26,10 +26,11 @@
// 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
diff --git a/web/gui/src/main/webapp/tests/karma.ci.js b/web/gui/src/main/webapp/tests/karma.ci.js
index 5729f0b..64c04cd 100644
--- a/web/gui/src/main/webapp/tests/karma.ci.js
+++ b/web/gui/src/main/webapp/tests/karma.ci.js
@@ -40,7 +40,10 @@
// unit test code...
'app/*-spec.js',
- 'app/**/*-spec.js'
+ 'app/**/*-spec.js',
+
+ // server mock
+ './server.mock.js'
],
diff --git a/web/gui/src/main/webapp/tests/karma.conf.js b/web/gui/src/main/webapp/tests/karma.conf.js
index 01fac6b..e77f903 100644
--- a/web/gui/src/main/webapp/tests/karma.conf.js
+++ b/web/gui/src/main/webapp/tests/karma.conf.js
@@ -40,7 +40,10 @@
// unit test code...
'app/*-spec.js',
- 'app/**/*-spec.js'
+ 'app/**/*-spec.js',
+
+ // server mock
+ './server.mock.js'
],
diff --git a/web/gui/src/main/webapp/tests/server.mock.js b/web/gui/src/main/webapp/tests/server.mock.js
new file mode 100644
index 0000000..3ecdbdb
--- /dev/null
+++ b/web/gui/src/main/webapp/tests/server.mock.js
@@ -0,0 +1,2 @@
+onosAuth = '';
+userPrefs = {};
\ No newline at end of file