summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util')
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js446
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/keys-spec.js278
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/prefs-spec.js60
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/random-spec.js110
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js162
5 files changed, 0 insertions, 1056 deletions
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js
deleted file mode 100644
index c9f3bef6..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/fn-spec.js
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * Copyright 2014,2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Util -- General Purpose Functions - Unit Tests
- */
-describe('factory: fw/util/fn.js', function() {
- var $window,
- fs,
- someFunction = function () {},
- someArray = [1, 2, 3],
- someObject = { foo: 'bar'},
- someNumber = 42,
- someString = 'xyyzy',
- someDate = new Date(),
- stringArray = ['foo', 'bar'];
-
- beforeEach(module('onosUtil'));
-
- var mockWindow = {
- innerWidth: 400,
- innerHeight: 200,
- navigator: {
- userAgent: 'defaultUA'
- }
- };
-
- beforeEach(function () {
- module(function ($provide) {
- $provide.value('$window', mockWindow);
- });
- });
-
- beforeEach(inject(function (_$window_, FnService) {
- $window = _$window_;
- fs = FnService;
- }));
-
- // === Tests for isF()
- it('isF(): null for undefined', function () {
- expect(fs.isF(undefined)).toBeNull();
- });
- it('isF(): null for null', function () {
- expect(fs.isF(null)).toBeNull();
- });
- it('isF(): the reference for function', function () {
- expect(fs.isF(someFunction)).toBe(someFunction);
- });
- it('isF(): null for string', function () {
- expect(fs.isF(someString)).toBeNull();
- });
- it('isF(): null for number', function () {
- expect(fs.isF(someNumber)).toBeNull();
- });
- it('isF(): null for Date', function () {
- expect(fs.isF(someDate)).toBeNull();
- });
- it('isF(): null for array', function () {
- expect(fs.isF(someArray)).toBeNull();
- });
- it('isF(): null for object', function () {
- expect(fs.isF(someObject)).toBeNull();
- });
-
-
- // === Tests for isA()
- it('isA(): null for undefined', function () {
- expect(fs.isA(undefined)).toBeNull();
- });
- it('isA(): null for null', function () {
- expect(fs.isA(null)).toBeNull();
- });
- it('isA(): null for function', function () {
- expect(fs.isA(someFunction)).toBeNull();
- });
- it('isA(): null for string', function () {
- expect(fs.isA(someString)).toBeNull();
- });
- it('isA(): null for number', function () {
- expect(fs.isA(someNumber)).toBeNull();
- });
- it('isA(): null for Date', function () {
- expect(fs.isA(someDate)).toBeNull();
- });
- it('isA(): the reference for array', function () {
- expect(fs.isA(someArray)).toBe(someArray);
- });
- it('isA(): null for object', function () {
- expect(fs.isA(someObject)).toBeNull();
- });
-
-
- // === Tests for isS()
- it('isS(): null for undefined', function () {
- expect(fs.isS(undefined)).toBeNull();
- });
- it('isS(): null for null', function () {
- expect(fs.isS(null)).toBeNull();
- });
- it('isS(): null for function', function () {
- expect(fs.isS(someFunction)).toBeNull();
- });
- it('isS(): the reference for string', function () {
- expect(fs.isS(someString)).toBe(someString);
- });
- it('isS(): null for number', function () {
- expect(fs.isS(someNumber)).toBeNull();
- });
- it('isS(): null for Date', function () {
- expect(fs.isS(someDate)).toBeNull();
- });
- it('isS(): null for array', function () {
- expect(fs.isS(someArray)).toBeNull();
- });
- it('isS(): null for object', function () {
- expect(fs.isS(someObject)).toBeNull();
- });
-
-
- // === Tests for isO()
- it('isO(): null for undefined', function () {
- expect(fs.isO(undefined)).toBeNull();
- });
- it('isO(): null for null', function () {
- expect(fs.isO(null)).toBeNull();
- });
- it('isO(): null for function', function () {
- expect(fs.isO(someFunction)).toBeNull();
- });
- it('isO(): null for string', function () {
- expect(fs.isO(someString)).toBeNull();
- });
- it('isO(): null for number', function () {
- expect(fs.isO(someNumber)).toBeNull();
- });
- it('isO(): null for Date', function () {
- expect(fs.isO(someDate)).toBeNull();
- });
- it('isO(): null for array', function () {
- expect(fs.isO(someArray)).toBeNull();
- });
- it('isO(): the reference for object', function () {
- expect(fs.isO(someObject)).toBe(someObject);
- });
-
- // === Tests for contains()
- it('contains(): false for improper args', function () {
- expect(fs.contains()).toBeFalsy();
- });
- it('contains(): false for non-array', function () {
- expect(fs.contains(null, 1)).toBeFalsy();
- });
- it('contains(): true for contained item', function () {
- expect(fs.contains(someArray, 1)).toBeTruthy();
- expect(fs.contains(stringArray, 'bar')).toBeTruthy();
- });
- it('contains(): false for non-contained item', function () {
- expect(fs.contains(someArray, 109)).toBeFalsy();
- expect(fs.contains(stringArray, 'zonko')).toBeFalsy();
- });
-
- // === Tests for areFunctions()
- it('areFunctions(): false for non-array', function () {
- expect(fs.areFunctions({}, 'not-an-array')).toBeFalsy();
- });
- it('areFunctions(): true for empty-array', function () {
- expect(fs.areFunctions({}, [])).toBeTruthy();
- });
- it('areFunctions(): true for some api', function () {
- expect(fs.areFunctions({
- a: function () {},
- b: function () {}
- }, ['b', 'a'])).toBeTruthy();
- });
- it('areFunctions(): false for some other api', function () {
- expect(fs.areFunctions({
- a: function () {},
- b: 'not-a-function'
- }, ['b', 'a'])).toBeFalsy();
- });
- it('areFunctions(): extraneous stuff NOT ignored', function () {
- expect(fs.areFunctions({
- a: function () {},
- b: function () {},
- c: 1,
- d: 'foo'
- }, ['a', 'b'])).toBeFalsy();
- });
- it('areFunctions(): extraneous stuff ignored (alternate fn)', function () {
- expect(fs.areFunctionsNonStrict({
- a: function () {},
- b: function () {},
- c: 1,
- d: 'foo'
- }, ['a', 'b'])).toBeTruthy();
- });
-
- // == use the now-tested areFunctions() on our own api:
- it('should define api functions', function () {
- expect(fs.areFunctions(fs, [
- 'isF', 'isA', 'isS', 'isO', 'contains',
- 'areFunctions', 'areFunctionsNonStrict', 'windowSize', 'isMobile',
- 'find', 'inArray', 'removeFromArray', 'isEmptyObject', 'cap',
- 'noPx', 'noPxStyle', 'endsWith', 'parseBitRate'
- ])).toBeTruthy();
- });
-
-
- // === Tests for windowSize()
- it('windowSize(): noargs', function () {
- var dim = fs.windowSize();
- expect(dim.width).toEqual(400);
- expect(dim.height).toEqual(200);
- });
-
- it('windowSize(): adjust height', function () {
- var dim = fs.windowSize(50);
- expect(dim.width).toEqual(400);
- expect(dim.height).toEqual(150);
- });
-
- it('windowSize(): adjust width', function () {
- var dim = fs.windowSize(0, 50);
- expect(dim.width).toEqual(350);
- expect(dim.height).toEqual(200);
- });
-
- it('windowSize(): adjust width and height', function () {
- var dim = fs.windowSize(101, 201);
- expect(dim.width).toEqual(199);
- expect(dim.height).toEqual(99);
- });
-
- // === Tests for isMobile()
- var uaMap = {
- chrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) " +
- "AppleWebKit/537.36 (KHTML, like Gecko) " +
- "Chrome/41.0.2272.89 Safari/537.36",
-
- iPad: "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) " +
- "AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 " +
- "Mobile/11A465 Safari/9537.53",
-
- iPhone: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) " +
- "AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 " +
- "Mobile/11A465 Safari/9537.53"
- };
-
- function setUa(key) {
- var str = uaMap[key];
- expect(str).toBeTruthy();
- mockWindow.navigator.userAgent = str;
- }
-
- it('isMobile(): should be false for Chrome on Mac OS X', function () {
- setUa('chrome');
- expect(fs.isMobile()).toBe(false);
- });
- it('isMobile(): should be true for Safari on iPad', function () {
- setUa('iPad');
- expect(fs.isMobile()).toBe(true);
- });
- it('isMobile(): should be true for Safari on iPhone', function () {
- setUa('iPhone');
- expect(fs.isMobile()).toBe(true);
- });
-
- // === Tests for find()
- var dataset = [
- { id: 'foo', name: 'Furby'},
- { id: 'bar', name: 'Barbi'},
- { id: 'baz', name: 'Basil'},
- { id: 'goo', name: 'Gabby'},
- { id: 'zoo', name: 'Zevvv'}
- ];
-
- it('should not find ooo', function () {
- expect(fs.find('ooo', dataset)).toEqual(-1);
- });
- it('should find foo', function () {
- expect(fs.find('foo', dataset)).toEqual(0);
- });
- it('should find zoo', function () {
- expect(fs.find('zoo', dataset)).toEqual(4);
- });
-
- it('should not find Simon', function () {
- expect(fs.find('Simon', dataset, 'name')).toEqual(-1);
- });
- it('should find Furby', function () {
- expect(fs.find('Furby', dataset, 'name')).toEqual(0);
- });
- it('should find Zevvv', function () {
- expect(fs.find('Zevvv', dataset, 'name')).toEqual(4);
- });
-
-
- // === Tests for inArray()
- var objRef = { x:1, y:2 },
- array = [1, 3.14, 'hey', objRef, 'there', true],
- array2 = ['b', 'a', 'd', 'a', 's', 's'];
-
- it('should return -1 on non-arrays', function () {
- expect(fs.inArray(1, {x:1})).toEqual(-1);
- });
- it('should not find HOO', function () {
- expect(fs.inArray('HOO', array)).toEqual(-1);
- });
- it('should find 1', function () {
- expect(fs.inArray(1, array)).toEqual(0);
- });
- it('should find pi', function () {
- expect(fs.inArray(3.14, array)).toEqual(1);
- });
- it('should find hey', function () {
- expect(fs.inArray('hey', array)).toEqual(2);
- });
- it('should find the object', function () {
- expect(fs.inArray(objRef, array)).toEqual(3);
- });
- it('should find there', function () {
- expect(fs.inArray('there', array)).toEqual(4);
- });
- it('should find true', function () {
- expect(fs.inArray(true, array)).toEqual(5);
- });
-
- it('should find the first occurrence A', function () {
- expect(fs.inArray('a', array2)).toEqual(1);
- });
- it('should find the first occurrence S', function () {
- expect(fs.inArray('s', array2)).toEqual(4);
- });
- it('should not find X', function () {
- expect(fs.inArray('x', array2)).toEqual(-1);
- });
-
- // === Tests for removeFromArray()
- it('should ignore non-arrays', function () {
- expect(fs.removeFromArray(1, {x:1})).toBe(false);
- });
- it('should keep the array the same, for non-match', function () {
- var array = [1, 2, 3];
- expect(fs.removeFromArray(4, array)).toBe(false);
- expect(array).toEqual([1, 2, 3]);
- });
- it('should remove a value', function () {
- var array = [1, 2, 3];
- expect(fs.removeFromArray(2, array)).toBe(true);
- expect(array).toEqual([1, 3]);
- });
- it('should remove the first occurrence', function () {
- var array = ['x', 'y', 'z', 'z', 'y'];
- expect(fs.removeFromArray('y', array)).toBe(true);
- expect(array).toEqual(['x', 'z', 'z', 'y']);
- expect(fs.removeFromArray('x', array)).toBe(true);
- expect(array).toEqual(['z', 'z', 'y']);
- });
-
- // === Tests for isEmptyObject()
- it('should return true if an object is empty', function () {
- expect(fs.isEmptyObject({})).toBe(true);
- });
- it('should return false if an object is not empty', function () {
- expect(fs.isEmptyObject({foo: 'bar'})).toBe(false);
- });
-
- // === Tests for cap()
- it('should ignore non-alpha', function () {
- expect(fs.cap('123')).toEqual('123');
- });
- it('should capitalize first char', function () {
- expect(fs.cap('Foo')).toEqual('Foo');
- expect(fs.cap('foo')).toEqual('Foo');
- expect(fs.cap('foo bar')).toEqual('Foo bar');
- expect(fs.cap('FOO BAR')).toEqual('Foo bar');
- expect(fs.cap('foo Bar')).toEqual('Foo bar');
- });
-
- // === Tests for noPx()
- it('should return the value without px suffix', function () {
- expect(fs.noPx('10px')).toBe(10);
- expect(fs.noPx('500px')).toBe(500);
- expect(fs.noPx('-80px')).toBe(-80);
- });
-
- // === Tests for noPxStyle()
- it("should give a style's property without px suffix", function () {
- var d3Elem = d3.select('body')
- .append('div')
- .attr('id', 'fooElem')
- .style({
- width: '500px',
- height: '200px',
- 'font-size': '12px'
- });
- expect(fs.noPxStyle(d3Elem, 'width')).toBe(500);
- expect(fs.noPxStyle(d3Elem, 'height')).toBe(200);
- expect(fs.noPxStyle(d3Elem, 'font-size')).toBe(12);
- d3.select('#fooElem').remove();
- });
-
- // === Tests for endsWith()
- it('should return true if string ends with foo', function () {
- expect(fs.endsWith("barfoo", "foo")).toBe(true);
- });
-
- it('should return false if string doesnt end with foo', function () {
- expect(fs.endsWith("barfood", "foo")).toBe(false);
- });
-
- // === Tests for parseBitRate()
- it('should return 5 - a', function () {
- expect(fs.parseBitRate('5.47 KBps')).toBe(5);
- });
-
- it('should return 5 - b', function () {
- expect(fs.parseBitRate('5. KBps')).toBe(5);
- });
-
- it('should return 5 - c', function () {
- expect(fs.parseBitRate('5 KBps')).toBe(5);
- });
-
- it('should return 5 - d', function () {
- expect(fs.parseBitRate('5 Kbps')).toBe(5);
- });
-
- it('should return 2001', function () {
- expect(fs.parseBitRate('2,001.59 Gbps')).toBe(2001);
- });
-});
-
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/keys-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/keys-spec.js
deleted file mode 100644
index 227d7904..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/keys-spec.js
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright 2014,2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Key Handler Service - Unit Tests
- */
-describe('factory: fw/util/keys.js', function() {
- var $log, ks, fs, qhs,
- d3Elem, elem, last;
-
-
- beforeEach(module('onosUtil', 'onosSvg', 'onosLayer', 'onosNav'));
-
- beforeEach(inject(function (_$log_, KeyService, FnService, QuickHelpService) {
- $log = _$log_;
- ks = KeyService;
- fs = FnService;
- qhs = QuickHelpService;
- d3Elem = d3.select('body').append('p').attr('id', 'ptest');
- elem = d3Elem.node();
- ks.installOn(d3Elem);
- ks.bindQhs(qhs);
- last = {
- view: null,
- key: null,
- code: null,
- ev: null
- };
- }));
-
- afterEach(function () {
- d3.select('#ptest').remove();
- });
-
- it('should define the key service', function () {
- expect(ks).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(ks, [
- 'bindQhs', 'installOn', 'keyBindings', 'gestureNotes', 'enableKeys'
- ])).toBeTruthy();
- });
-
- // This no longer works because 'initKeyboardEvent' has been depreciated.
- // Now there is a constructor for 'KeyboardEvent' where you can modify
- // the new event with a dictionary(?) 'KeyboardEventInit'.
- // However, the below code has been so recently depreciated, there are no
- // examples online of how to use the new interface, and some browsers
- // don't support it still. These tests will have to be put off for a
- // while more. (Investigated 4/28/15)
- // Also tried was Angular's triggerHandler() function, but it doesn't seem
- // that it can take arguments about the event.
- // Using jQuery in tests might be a good idea, for triggering test events.
- function jsKeyDown(element, code) {
- var ev = document.createEvent('KeyboardEvent');
-
- // Chromium Hack
- if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
- Object.defineProperty(ev, 'keyCode', {
- get: function () { return this.keyCodeVal; }
- });
- Object.defineProperty(ev, 'which', {
- get: function () { return this.keyCodeVal; }
- });
- }
-
- if (ev.initKeyboardEvent) {
- ev.initKeyboardEvent('keydown', true, true, document.defaultView,
- false, false, false, false, code, code);
- } else {
- ev.initKeyEvent('keydown', true, true, document.defaultView,
- false, false, false, false, code, 0);
- }
-
- ev.keyCodeVal = code;
-
- if (ev.keyCode !== code) {
- console.warn("keyCode mismatch " + ev.keyCode +
- "(" + ev.which + ") -> "+ code);
- }
- element.dispatchEvent(ev);
- }
-
- // === Key binding related tests
- it('should start with default key bindings', function () {
- var state = ks.keyBindings(),
- gk = state.globalKeys,
- mk = state.maskedKeys,
- vk = state.viewKeys,
- vf = state.viewFunction;
-
- expect(gk.length).toEqual(4);
- ['backSlash', 'slash', 'esc', 'T'].forEach(function (k) {
- expect(fs.contains(gk, k)).toBeTruthy();
- });
-
- expect(mk.length).toEqual(3);
- ['backSlash', 'slash', 'T'].forEach(function (k) {
- expect(fs.contains(mk, k)).toBeTruthy();
- });
-
- expect(vk.length).toEqual(0);
- expect(vf).toBeFalsy();
- });
-
- function bindTestKeys(withDescs) {
- var keys = ['A', '1', 'F5', 'equals'],
- kb = {};
-
- function cb(view, key, code, ev) {
- last.view = view;
- last.key = key;
- last.code = code;
- last.ev = ev;
- }
-
- function bind(k) {
- return withDescs ? [cb, 'desc for key ' + k] : cb;
- }
-
- keys.forEach(function (k) {
- kb[k] = bind(k);
- });
-
- ks.keyBindings(kb);
- }
-
- function verifyCall(key, code) {
- // TODO: update expectation, when view tokens are implemented
- expect(last.view).toEqual('NotYetAViewToken');
- last.view = null;
-
- expect(last.key).toEqual(key);
- last.key = null;
-
- expect(last.code).toEqual(code);
- last.code = null;
-
- expect(last.ev).toBeTruthy();
- last.ev = null;
- }
-
- function verifyNoCall() {
- expect(last.view).toBeNull();
- expect(last.key).toBeNull();
- expect(last.code).toBeNull();
- expect(last.ev).toBeNull();
- }
-
- function verifyTestKeys() {
- jsKeyDown(elem, 65); // 'A'
- verifyCall('A', 65);
- jsKeyDown(elem, 66); // 'B'
- verifyNoCall();
-
- jsKeyDown(elem, 49); // '1'
- verifyCall('1', 49);
- jsKeyDown(elem, 50); // '2'
- verifyNoCall();
-
- jsKeyDown(elem, 116); // 'F5'
- verifyCall('F5', 116);
- jsKeyDown(elem, 117); // 'F6'
- verifyNoCall();
-
- jsKeyDown(elem, 187); // 'equals'
- verifyCall('equals', 187);
- jsKeyDown(elem, 189); // 'dash'
- verifyNoCall();
-
- var vk = ks.keyBindings().viewKeys;
-
- expect(vk.length).toEqual(4);
- ['A', '1', 'F5', 'equals'].forEach(function (k) {
- expect(fs.contains(vk, k)).toBeTruthy();
- });
-
- expect(ks.keyBindings().viewFunction).toBeFalsy();
- }
-
- // TODO: jsKeyDown(...) no longer emulates key presses ?! :(
- // The following four unit tests ignored until we can figure this out.
- // INVESTIGATED: see jsKeyDown for details...
-
- xit('should allow specific key bindings', function () {
- bindTestKeys();
- verifyTestKeys();
- });
-
- xit('should allow specific key bindings with descriptions', function () {
- bindTestKeys(true);
- verifyTestKeys();
- });
-
- xit('should warn about masked keys', function () {
- var k = {'space': cb, 'T': cb},
- count = 0;
-
- function cb(token, key, code, ev) {
- count++;
- //console.debug('count = ' + count, token, key, code);
- }
-
- spyOn($log, 'warn');
-
- ks.keyBindings(k);
-
- expect($log.warn).toHaveBeenCalledWith('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);
- });
-
- xit('should block keys when disabled', function () {
- var cbCount = 0;
-
- function cb() { cbCount++; }
-
- function pressA() { jsKeyDown(elem, 65); } // 65 == 'A' keycode
-
- ks.keyBindings({ A: cb });
-
- expect(cbCount).toBe(0);
-
- pressA();
- expect(cbCount).toBe(1);
-
- ks.enableKeys(false);
- pressA();
- expect(cbCount).toBe(1);
-
- ks.enableKeys(true);
- pressA();
- expect(cbCount).toBe(2);
- });
-
- // === 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
-});
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/prefs-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/prefs-spec.js
deleted file mode 100644
index 02152895..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/prefs-spec.js
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Util -- User Preference Service - Unit Tests
- */
-describe('factory: fw/util/prefs.js', function() {
- var $cookies, ps, fs;
-
- beforeEach(module('onosUtil'));
-
- var mockCookies = {
- foo: 'bar'
- };
-
- beforeEach(function () {
- module(function ($provide) {
- $provide.value('$cookies', mockCookies);
- });
- });
-
- beforeEach(inject(function (PrefsService, FnService, _$cookies_) {
- ps = PrefsService;
- fs = FnService;
- $cookies = _$cookies_;
- }));
-
- it('should define PrefsService', function () {
- expect(ps).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(ps, [
- 'getPrefs', 'asNumbers', 'setPrefs'
- ])).toBe(true);
- });
-
- // === Tests for getPrefs()
- // TODO unit tests for getPrefs()
-
- // === Tests for asNumbers()
- // TODO unit tests for asNumbers()
-
- // === Tests for setPrefs()
- // TODO unit tests for setPrefs()
-
-});
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/random-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/random-spec.js
deleted file mode 100644
index c4c61f1a..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/random-spec.js
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2014,2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Util -- Random Service - Unit Tests
- */
-describe('factory: fw/util/random.js', function() {
- var rnd, $log, fs;
-
- beforeEach(module('onosUtil'));
-
- beforeEach(inject(function (RandomService, _$log_, FnService) {
- rnd = RandomService;
- $log = _$log_;
- fs = FnService;
- }));
-
- // interesting use of a custom matcher...
- beforeEach(function () {
- jasmine.addMatchers({
- toBeWithinOf: function () {
- return {
- compare: function (actual, distance, base) {
- var lower = base - distance,
- upper = base + distance,
- result = {};
-
- result.pass = Math.abs(actual - base) <= distance;
-
- if (result.pass) {
- // for negation with ".not"
- result.message = 'Expected ' + actual +
- ' to be outside ' + lower + ' and ' +
- upper + ' (inclusive)';
- } else {
- result.message = 'Expected ' + actual +
- ' to be between ' + lower + ' and ' +
- upper + ' (inclusive)';
- }
- return result;
- }
- }
- }
- });
- });
-
- it('should define RandomService', function () {
- expect(rnd).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(rnd, [
- 'spread', 'randDim'
- ])).toBeTruthy();
- });
-
- // really, can only do this heuristically.. hope this doesn't break
- it('should spread results across the range', function () {
- var load = 1000,
- s = 12,
- low = 0,
- high = 0,
- i, res,
- which = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- minCount = load / s * 0.5; // generous error
-
- for (i=0; i<load; i++) {
- res = rnd.spread(s);
- if (res < low) low = res;
- if (res > high) high = res;
- which[res + s/2]++;
- }
- expect(low).toBe(-6);
- expect(high).toBe(5);
-
- // check we got a good number of hits in each bucket
- for (i=0; i<s; i++) {
- expect(which[i]).toBeGreaterThan(minCount);
- }
- });
-
- // really, can only do this heuristically.. hope this doesn't break
- it('should choose results across the dimension', function () {
- var load = 1000,
- dim = 100,
- low = 999,
- high = 0,
- i, res;
-
- for (i=0; i<load; i++) {
- res = rnd.randDim(dim);
- if (res < low) low = res;
- if (res > high) high = res;
- expect(res).toBeWithinOf(36, 50);
- }
- });
-});
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js
deleted file mode 100644
index 1d400ed1..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright 2014,2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Util -- Theme Service - Unit Tests
- */
-describe('factory: fw/util/theme.js', function() {
- var ts, $log, fs;
-
- beforeEach(module('onosUtil'));
-
- beforeEach(inject(function (ThemeService, _$log_, FnService) {
- ts = ThemeService;
- $log = _$log_;
- fs = FnService;
- ts.init();
- }));
-
- it('should define ThemeService', function () {
- expect(ts).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(ts, [
- 'init', 'theme', 'toggleTheme', 'addListener', 'removeListener'
- ])).toBeTruthy();
- });
-
-
- function verifyBodyClass(yes, no) {
- function bodyHasClass(c) {
- return d3.select('body').classed(c);
- }
- expect(bodyHasClass(yes)).toBeTruthy();
- expect(bodyHasClass(no)).toBeFalsy();
- }
-
- it('should default to light theme', function () {
- expect(ts.theme()).toEqual('light');
- });
-
- it('should toggle to dark, then to light again', function () {
- // Note: re-work this once theme-change listeners are implemented
- spyOn($log, 'debug');
-
- expect(ts.toggleTheme()).toEqual('dark');
- expect(ts.theme()).toEqual('dark');
- expect($log.debug).toHaveBeenCalledWith('Theme-Change-(toggle): dark');
- verifyBodyClass('dark', 'light');
-
- expect(ts.toggleTheme()).toEqual('light');
- expect(ts.theme()).toEqual('light');
- expect($log.debug).toHaveBeenCalledWith('Theme-Change-(toggle): light');
- verifyBodyClass('light', 'dark');
- });
-
- it('should let us set the theme by name', function () {
- // Note: re-work this once theme-change listeners are implemented
- spyOn($log, 'debug');
-
- expect(ts.theme()).toEqual('light');
- ts.theme('dark');
- expect(ts.theme()).toEqual('dark');
- expect($log.debug).toHaveBeenCalledWith('Theme-Change-(set): dark');
- verifyBodyClass('dark', 'light');
- });
-
- it('should ignore unknown theme names', function () {
- // Note: re-work this once theme-change listeners are implemented
- spyOn($log, 'debug');
-
- expect(ts.theme()).toEqual('light');
- verifyBodyClass('light', 'dark');
-
- ts.theme('turquoise');
- expect(ts.theme()).toEqual('light');
- expect($log.debug).not.toHaveBeenCalled();
- verifyBodyClass('light', 'dark');
- });
-
-
- // === Unit Tests for listeners
-
- it('should report lack of callback', function () {
- spyOn($log, 'error');
- var list = ts.addListener();
- expect($log.error).toHaveBeenCalledWith(
- 'ThemeService.addListener(): callback not a function'
- );
- expect(list.error).toEqual('No callback defined');
- });
-
- it('should report non-functional callback', function () {
- spyOn($log, 'error');
- var list = ts.addListener(['some array']);
- expect($log.error).toHaveBeenCalledWith(
- 'ThemeService.addListener(): callback not a function'
- );
- expect(list.error).toEqual('No callback defined');
- });
-
- it('should invoke our callback with an event', function () {
- var event;
-
- function cb(ev) {
- event = ev;
- }
-
- expect(event).toBeUndefined();
- ts.addListener(cb);
- ts.theme('dark');
- expect(event).toEqual({
- event: 'themeChange',
- value: 'dark'
- });
- });
-
- it('should invoke our callback at appropriate times', function () {
- var calls = [],
- phase,
- listener;
-
- function cb() {
- calls.push(phase);
- }
-
- expect(calls).toEqual([]);
-
- phase = 'pre';
- ts.toggleTheme(); // -> dark
-
- phase = 'added';
- listener = ts.addListener(cb);
- ts.toggleTheme(); // -> light
-
- phase = 'same';
- ts.theme('light'); // (still light - no event)
-
- phase = 'diff';
- ts.theme('dark'); // -> dark
-
- phase = 'post';
- ts.removeListener(listener);
- ts.toggleTheme(); // -> light
-
- expect(calls).toEqual(['added', 'diff']);
- });
-
-});