diff options
Diffstat (limited to 'framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget')
5 files changed, 0 insertions, 994 deletions
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/button-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/button-spec.js deleted file mode 100644 index 5226984d..00000000 --- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/button-spec.js +++ /dev/null @@ -1,300 +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 -- Widget -- Button Service - Unit Tests - */ -describe('factory: fw/widget/button.js', function () { - var $log, fs, bns, d3Elem; - - beforeEach(module('onosWidget', 'onosSvg')); - - beforeEach(inject(function (_$log_, FnService, ButtonService) { - $log = _$log_; - fs = FnService; - bns = ButtonService; - })); - - beforeEach(function () { - d3Elem = d3.select('body').append('div').attr('id', 'testDiv'); - }); - - afterEach(function () { - d3.select('#testDiv').remove(); - }); - - - // re-usable null function - function nullFunc () {} - - it('should define ButtonService', function () { - expect(bns).toBeDefined(); - }); - - it('should define api functions', function () { - expect(fs.areFunctions(bns, [ - 'button', 'toggle', 'radioSet' - ])).toBeTruthy(); - }); - - it('should verify button glyph', function () { - var btn = bns.button(d3Elem, 'foo-id', 'crown', nullFunc); - var el = d3Elem.select('#foo-id'); - expect(el.classed('button')).toBeTruthy(); - expect(el.attr('id')).toBe('foo-id'); - expect(el.select('svg')).toBeTruthy(); - expect(el.select('use')).toBeTruthy(); - expect(el.select('use').classed('glyph')).toBeTruthy(); - expect(el.select('use').attr('xlink:href')).toBe('#crown'); - }); - - - it('should not append button to an undefined div', function () { - spyOn($log, 'warn'); - expect(bns.button(null, 'id', 'gid', nullFunc)).toBeNull(); - expect($log.warn).toHaveBeenCalledWith('div undefined (button)'); - }); - - it('should verify button callback', function () { - var count = 0; - function cb() { count++; } - var btn = bns.button(d3Elem, 'test', 'nothing', cb); - expect(count).toBe(0); - d3Elem.select('#test').on('click')(); - expect(count).toBe(1); - }); - - it('should ignore non-function callbacks button', function () { - var count = 0; - var btn = bns.button(d3Elem, 'test', 'nothing', 'foo'); - expect(count).toBe(0); - d3Elem.select('#test').on('click')(); - expect(count).toBe(0); - }); - - it('should not append toggle to an undefined div', function () { - spyOn($log, 'warn'); - expect(bns.toggle(undefined, 'id', 'gid', false, nullFunc)).toBeNull(); - expect($log.warn).toHaveBeenCalledWith('div undefined (toggle button)'); - }); - - it('should verify toggle glyph', function () { - var tog = bns.toggle(d3Elem, 'foo-id', 'crown', false, nullFunc); - var el = d3Elem.select('#foo-id'); - expect(el.classed('toggleButton')).toBeTruthy(); - expect(el.attr('id')).toBe('foo-id'); - expect(el.select('svg')).toBeTruthy(); - expect(el.select('use')).toBeTruthy(); - expect(el.select('use').classed('glyph')).toBeTruthy(); - expect(el.select('use').attr('xlink:href')).toBe('#crown'); - }); - - it('should toggle the selected state', function () { - var tog = bns.toggle(d3Elem, 'test', 'nothing'); - expect(tog.selected()).toBe(false); - tog.toggle(); - expect(tog.selected()).toBe(true); - tog.toggle(); - expect(tog.selected()).toBe(false); - }); - - it('should set toggle state', function () { - var tog = bns.toggle(d3Elem, 'test', 'nothing'); - tog.toggle(true); - expect(tog.selected()).toBe(true); - tog.toggle(); - expect(tog.selected()).toBe(false); - tog.toggle('truthy string'); - expect(tog.selected()).toBe(true); - tog.toggle(null); - expect(tog.selected()).toBe(false); - tog.toggle(''); - expect(tog.selected()).toBe(false); - }); - - it('should verity toggle initial state', function () { - var tog = bns.toggle(d3Elem, 'id', 'gid', true); - expect(tog.selected()).toBe(true); - tog = bns.toggle(d3Elem, 'id', 'gid', false); - expect(tog.selected()).toBe(false); - tog = bns.toggle(d3Elem, 'id', 'gid', ''); - expect(tog.selected()).toBe(false); - tog = bns.toggle(d3Elem, 'id', 'gid', 'something'); - expect(tog.selected()).toBe(true); - }); - - it('should not append radio button set to an undefined div', function () { - spyOn($log, 'warn'); - expect(bns.radioSet(undefined, 'id', [])).toBeNull(); - expect($log.warn).toHaveBeenCalledWith('div undefined (radio button set)'); - }); - - it('should not create radio button set from a non-array', function () { - var rads = {test: 'test'}; - var warning = 'invalid array (radio button set)'; - - spyOn($log, 'warn'); - - expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); - expect($log.warn).toHaveBeenCalledWith(warning); - rads = 'rads'; - expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); - expect($log.warn).toHaveBeenCalledWith(warning); - rads = {arr: [1, 2, 3]}; - expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); - expect($log.warn).toHaveBeenCalledWith(warning); - }); - - it('should not create radio button set from empty array', function () { - var rads = []; - spyOn($log, 'warn'); - expect(bns.radioSet(d3Elem, 'test', rads)).toBeNull(); - expect($log.warn).toHaveBeenCalledWith('invalid array (radio button set)'); - }); - - it('should verify radio button glyph structure', function () { - var rads = [ - { gid: 'crown', cb: nullFunc, tooltip: 'n/a'} - ], rdiv; - - spyOn($log, 'warn'); - expect(bns.radioSet(d3Elem, 'foo', rads)).toBeTruthy(); - expect($log.warn).not.toHaveBeenCalled(); - - rdiv = d3Elem.select('div'); - expect(rdiv.classed('radioSet')).toBe(true); - expect(rdiv.select('div').classed('radioButton')).toBe(true); - expect(rdiv.select('div').attr('id')).toBe('foo-0'); - expect(rdiv.select('div').select('svg')).toBeTruthy(); - expect(rdiv.select('use').classed('glyph')).toBeTruthy(); - expect(rdiv.select('use').attr('xlink:href')).toBe('#crown'); - }); - - it('should verify more than one radio button glyph was added', function () { - var rads = [ - { gid: 'crown', cb: nullFunc, tooltip: 'n/a'}, - { gid: 'router', cb: nullFunc, tooltip: 'n/a'} - ], rdiv; - - expect(bns.radioSet(d3Elem, 'foo', rads)).toBeTruthy(); - rdiv = d3Elem.select('div'); - expect(rdiv.select('#foo-0')).toBeTruthy(); - expect(rdiv.select('#foo-1')).toBeTruthy(); - - expect(rdiv.select('#foo-0') - .select('use') - .classed('glyph')) - .toBeTruthy(); - expect(rdiv.select('#foo-0') - .select('use') - .attr('xlink:href')) - .toBe('#crown'); - - expect(rdiv.select('#foo-1') - .select('use') - .classed('glyph')) - .toBeTruthy(); - expect(rdiv.select('#foo-1') - .select('use') - .attr('xlink:href')) - .toBe('#router'); - }); - - it('should select radio button by index', function () { - var count0 = 0, - count1 = 9; - function cb0() { count0++; } - function cb1() { count1++; } - - function validate(expSel, exp0, exp1) { - expect(rset.selected()).toBe(expSel); - expect(count0).toBe(exp0); - expect(count1).toBe(exp1); - } - - function checkWarn(msg, index) { - expect($log.warn).toHaveBeenCalledWith(msg, index); - } - - var rads = [ - { gid: 'crown', cb: cb0, tooltip: 'n/a'}, - { gid: 'router', cb: cb1, tooltip: 'n/a'} - ], - rset = bns.radioSet(d3Elem, 'test', rads); - spyOn($log, 'warn'); - - validate(0, 0, 9); - rset.selectedIndex(0); - validate(0, 0, 9); - - rset.selectedIndex(1); - validate(1, 0, 10); - - rset.selectedIndex(-1); - checkWarn('invalid radio button index:', -1); - validate(1, 0, 10); - - rset.selectedIndex(66); - checkWarn('invalid radio button index:', 66); - validate(1, 0, 10); - - rset.selectedIndex(0); - validate(0, 1, 10); - }); - - it('should select radio button by key', function () { - var count0 = 0, - count1 = 9; - function cb0() { count0++; } - function cb1() { count1++; } - - function validate(expSel, exp0, exp1) { - expect(rset.selected()).toBe(expSel); - expect(count0).toBe(exp0); - expect(count1).toBe(exp1); - } - - function checkWarn(msg, index) { - expect($log.warn).toHaveBeenCalledWith(msg, index); - } - - var rads = [ - { key: 'foo', gid: 'crown', cb: cb0, tooltip: 'n/a'}, - { key: 'bar', gid: 'router', cb: cb1, tooltip: 'n/a'} - ], - rset = bns.radioSet(d3Elem, 'test', rads); - spyOn($log, 'warn'); - - validate('foo', 0, 9); - rset.selected('foo'); - validate('foo', 0, 9); - - rset.selected('bar'); - validate('bar', 0, 10); - - rset.selected('blob'); - checkWarn('no radio button with key:', 'blob'); - validate('bar', 0, 10); - - rset.selected('foo'); - validate('foo', 1, 10); - - rset.selected('foo'); - validate('foo', 1, 10); - checkWarn('current index already selected:', 0); - }); - -}); diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/table-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/table-spec.js deleted file mode 100644 index 4f8f0c0f..00000000 --- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/table-spec.js +++ /dev/null @@ -1,340 +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 -- Widget -- Table Service - Unit Tests - */ -describe('factory: fw/widget/table.js', function () { - var $log, $compile, $rootScope, - fs, ts, mast, is, - scope, - containerDiv, - headerDiv, bodyDiv, - header, body, - mockHeader, - mockHeaderHeight = 40; - - var onosFixedHeaderTags = - '<div class="summary-list" onos-fixed-header>' + - '<div class="table-header">' + - '<table>' + - '<tr>' + - '<td colId="type" class="table-icon"></td>' + - '<td colId="id">Host ID </td>' + - '<td colId="mac" sortable>MAC Address </td>' + - '<td colId="location" col-width="110px">Location </td>' + - '</tr>' + - '</table>' + - '</div>' + - - '<div class="table-body">' + - '<table>' + - '<tr class="ignore-width">' + - '<td class="not-picked"></td>' + - '</tr>' + - '<tr>' + - '<td class="table-icon">Some Icon</td>' + - '<td>Some ID</td>' + - '<td>Some MAC Address</td>' + - '<td>Some Location</td>' + - '</tr>' + - '</table>' + - '</div>' + - '</div>', - - onosSortableHeaderTags = - '<div onos-sortable-header ' + - 'sort-callback="sortCallback(requestParams)">' + - '<table>' + - '<tr>' + - '<td colId="type"></td>' + - '<td colId="id" sortable>Host ID </td>' + - '<td colId="mac" sortable>MAC Address </td>' + - '<td colId="location" sortable>Location </td>' + - '</tr>' + - '</table>' + - '</div>'; - - beforeEach(module('onosWidget', 'onosUtil', 'onosMast', 'onosSvg')); - - var mockWindow = { - innerWidth: 600, - innerHeight: 400, - navigator: { - userAgent: 'defaultUA' - }, - on: function () {}, - addEventListener: function () {} - }; - - beforeEach(function () { - module(function ($provide) { - $provide.value('$window', mockWindow); - }); - }); - - beforeEach(inject(function (_$log_, _$compile_, _$rootScope_, - FnService, TableService, MastService, IconService) { - $log = _$log_; - $compile = _$compile_; - $rootScope = _$rootScope_; - fs = FnService; - ts = TableService; - mast = MastService; - is = IconService; - })); - - beforeEach(function () { - scope = $rootScope.$new(); - scope.tableData = []; - }); - - // Note: dummy header so that d3 doesn't trip up. - // $compile has to be used on the directive tag element, so it can't - // be included in the tag strings declared above. - beforeEach(function () { - mockHeader = d3.select('body') - .append('h2') - .classed('tabular-header', true) - .style({ - height: mockHeaderHeight + 'px', - margin: 0, - padding: 0 - }) - .text('Some Header'); - }); - - afterEach(function () { - containerDiv = undefined; - headerDiv = undefined; - bodyDiv = undefined; - header = undefined; - body = undefined; - mockHeader.remove(); - }); - - function populateTableData() { - scope.tableData = [ - { - type: 'endstation', - id: '1234', - mac: '00:00:03', - location: 'USA' - } - ]; - } - - it('should define TableBuilderService', function () { - expect(ts).toBeDefined(); - }); - - it('should define api functions', function () { - expect(fs.areFunctions(ts, [ - 'resetSortIcons' - ])).toBeTruthy(); - }); - - function compile(elem) { - var compiled = $compile(elem); - compiled(scope); - scope.$digest(); - } - - function selectTables() { - expect(containerDiv.find('div').length).toBe(2); - - headerDiv = angular.element(containerDiv[0].querySelector('.table-header')); - expect(headerDiv.length).toBe(1); - - bodyDiv = angular.element(containerDiv[0].querySelector('.table-body')); - expect(bodyDiv.length).toBe(1); - - header = headerDiv.find('table'); - expect(header.length).toBe(1); - - body = bodyDiv.find('table'); - expect(body.length).toBe(1); - } - - function verifyGivenTags(dirName, div) { - expect(div).toBeDefined(); - expect(div.attr(dirName)).toBe(''); - } - - function verifyDefaultSize() { - expect(header.css('width')).toBe('570px'); - expect(body.css('width')).toBe('570px'); - } - - function verifyHeight() { - var padding = 22, - mastHeight = 36, - tableHeight = (mockWindow.innerHeight - mockHeaderHeight) - - (fs.noPx(headerDiv.css('height')) + mastHeight + padding); - - expect(bodyDiv.css('height')).toBe(tableHeight + 'px'); - } - - function verifyColWidth() { - var hdrs = header.find('td'), - cols = body.find('td'); - - expect(angular.element(hdrs[0]).css('width')).toBe('33px'); - expect(angular.element(hdrs[3]).css('width')).toBe('110px'); - - expect(angular.element(cols[1]).css('width')).toBe('33px'); - expect(angular.element(cols[4]).css('width')).toBe('110px'); - } - - function verifyCallbacks(h) { - expect(scope.sortCallback).not.toHaveBeenCalled(); - - h[0].click(); - expect(scope.sortCallback).not.toHaveBeenCalled(); - - h[1].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'id', - sortDir: 'asc' - }); - h[1].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'id', - sortDir: 'desc' - }); - h[1].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'id', - sortDir: 'asc' - }); - - h[2].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'mac', - sortDir: 'asc' - }); - h[2].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'mac', - sortDir: 'desc' - }); - h[2].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'mac', - sortDir: 'asc' - }); - - h[3].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'location', - sortDir: 'asc' - }); - h[3].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'location', - sortDir: 'desc' - }); - h[3].click(); - expect(scope.sortCallback).toHaveBeenCalledWith({ - sortCol: 'location', - sortDir: 'asc' - }); - } - - function verifyIcons(h) { - var currH, div; - - h[1].click(); - currH = angular.element(h[1]); - div = currH.find('div'); - expect(div.html()).toBe( - '<svg class="embeddedIcon" width="10" height="10" viewBox="0 0 ' + - '50 50"><g class="icon upArrow"><rect width="50" height="50" ' + - 'rx="5"></rect><use width="50" height="50" class="glyph" xmlns:' + - 'xlink="http://www.w3.org/1999/xlink" xlink:href="#triangleUp">' + - '</use></g></svg>' - ); - h[1].click(); - div = currH.find('div'); - expect(div.html()).toBe( - '<svg class="embeddedIcon" width="10" height="10" viewBox="0 0 ' + - '50 50"><g class="icon downArrow"><rect width="50" height="50" ' + - 'rx="5"></rect><use width="50" height="50" class="glyph" xmlns:' + - 'xlink="http://www.w3.org/1999/xlink" xlink:href="#triangleDown">' + - '</use></g></svg>' - ); - - h[2].click(); - div = currH.children(); - // clicked on a new element, so the previous icon should have been deleted - expect(div.html()).toBeFalsy(); - - // the new element should have the ascending icon - currH = angular.element(h[2]); - div = currH.children(); - expect(div.html()).toBe( - '<svg class="embeddedIcon" width="10" height="10" viewBox="0 0 ' + - '50 50"><g class="icon upArrow"><rect width="50" height="50" ' + - 'rx="5"></rect><use width="50" height="50" class="glyph" xmlns:' + - 'xlink="http://www.w3.org/1999/xlink" xlink:href="#triangleUp">' + - '</use></g></svg>' - ); - } - - it('should affirm that onos-fixed-header is working', function () { - containerDiv = angular.element(onosFixedHeaderTags); - - compile(containerDiv); - - verifyGivenTags('onos-fixed-header', containerDiv); - selectTables(); - verifyDefaultSize(); - - populateTableData(); - - scope.$emit('LastElement'); - scope.$digest(); - - verifyHeight(); - verifyColWidth(); - - mockWindow.innerHeight = 300; - scope.$digest(); - verifyHeight(); - - mockWindow.innerWidth = 500; - scope.$digest(); - verifyColWidth(); - }); - - it('should affirm that onos-sortable-header is working', function () { - headerDiv = angular.element(onosSortableHeaderTags); - - compile(headerDiv); - verifyGivenTags('onos-sortable-header', headerDiv); - - scope.sortCallback = jasmine.createSpy('sortCallback'); - - header = headerDiv.find('td'); - verifyCallbacks(header); - verifyIcons(header); - }); - - // Note: testing resetSortIcons isn't feasible because due to the nature of - // directive compilation: they are jQuery elements, not d3 elements, - // so the function doesn't work. - -}); diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js deleted file mode 100644 index 0372a25f..00000000 --- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/tableBuilder-spec.js +++ /dev/null @@ -1,95 +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 -- Widget -- Table Builder Service - Unit Tests - */ - -describe('factory: fw/widget/tableBuilder.js', function () { - var $log, $rootScope, fs, tbs, is; - - var mockObj, - mockWss = { - bindHandlers: function () {}, - sendEvent: function () {}, - unbindHandlers: function () {} - }; - - beforeEach(module('onosWidget', 'onosUtil', 'onosRemote', 'onosSvg')); - - beforeEach(function () { - module(function ($provide) { - $provide.value('WebSocketService', mockWss); - }); - }); - - beforeEach(inject(function (_$log_, _$rootScope_, - FnService, TableBuilderService, IconService) { - $log = _$log_; - $rootScope = _$rootScope_; - fs = FnService; - tbs = TableBuilderService; - is = IconService; - })); - - function mockSelCb(event, sel) {} - - beforeEach(function () { - mockObj = { - scope: $rootScope.$new(), - tag: 'foo', - selCb: mockSelCb - }; - }); - - afterEach(function () { - mockObj = {}; - }); - - it('should define TableBuilderService', function () { - expect(tbs).toBeDefined(); - }); - - it('should define api functions', function () { - expect(fs.areFunctions(tbs, [ - 'buildTable' - ])).toBeTruthy(); - }); - - it('should verify sortCb', function () { - spyOn(mockWss, 'sendEvent'); - expect(mockObj.scope.sortCallback).not.toBeDefined(); - tbs.buildTable(mockObj); - expect(mockObj.scope.sortCallback).toBeDefined(); - expect(mockWss.sendEvent).toHaveBeenCalled(); - }); - - it('should set tableData', function () { - expect(mockObj.scope.tableData).not.toBeDefined(); - tbs.buildTable(mockObj); - expect(fs.isA(mockObj.scope.tableData)).toBeTruthy(); - expect(mockObj.scope.tableData.length).toBe(0); - }); - - it('should unbind handlers on destroyed scope', function () { - spyOn(mockWss, 'unbindHandlers'); - tbs.buildTable(mockObj); - expect(mockWss.unbindHandlers).not.toHaveBeenCalled(); - mockObj.scope.$destroy(); - expect(mockWss.unbindHandlers).toHaveBeenCalled(); - }); - -}); diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/toolbar-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/toolbar-spec.js deleted file mode 100644 index 83fd042e..00000000 --- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/toolbar-spec.js +++ /dev/null @@ -1,180 +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 -- Widget -- Toolbar Service - Unit Tests - */ -describe('factory: fw/widget/toolbar.js', function () { - var $log, fs, tbs, ps, bns, is; - - beforeEach(module('onosWidget', 'onosUtil', 'onosLayer', 'onosSvg')); - - beforeEach(inject(function (_$log_, FnService, ToolbarService, - PanelService, ButtonService, IconService) { - $log = _$log_; - fs = FnService; - tbs = ToolbarService; - ps = PanelService; - bns = ButtonService; - is = IconService; - })); - - beforeEach(function () { - // panel service expects #floatpanels div into which panels are placed - d3.select('body').append('div').attr('id', 'floatpanels'); - tbs.init(); - ps.init(); - }); - - afterEach(function () { - tbs.init(); - ps.init(); - d3.select('#floatpanels').remove(); - }); - - function nullFunc() { } - - it('should define ToolbarService', function () { - expect(tbs).toBeDefined(); - }); - - it('should define api functions', function () { - expect(fs.areFunctions(tbs, [ - 'init', - 'createToolbar', 'destroyToolbar' - ])).toBeTruthy(); - }); - - it('should warn when no id is given', function () { - spyOn($log, 'warn'); - expect(tbs.createToolbar()).toBeNull(); - expect($log.warn).toHaveBeenCalledWith('createToolbar: ' + - 'no ID given: [undefined]'); - }); - - it('should warn when a duplicate id is given', function () { - spyOn($log, 'warn'); - expect(tbs.createToolbar('test')).toBeTruthy(); - expect(tbs.createToolbar('test')).toBeNull(); - expect($log.warn).toHaveBeenCalledWith('createToolbar: ' + - 'duplicate ID given: [test]'); - }); - - it('should verify the toolbar arrow div exists', function () { - tbs.createToolbar('test'); - - // NOTE: toolbar service prefixes id with 'toolbar-' - var tbar = d3.select('#toolbar-test'), - arrow = tbar.select('.tbar-arrow'); - - expect(arrow.size()).toBe(1); - expect(arrow.select('svg').size()).toBe(1); - expect(arrow.select('svg').select('g').select('use') - .attr('xlink:href')).toEqual('#triangleUp'); - }); - - - it('should create a button', function () { - spyOn($log, 'warn'); - var toolbar = tbs.createToolbar('foo'), - btn = toolbar.addButton('btn0', 'gid'); - expect(btn).not.toBeNull(); - expect(btn.id).toBe('toolbar-foo-btn0'); - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should not create an item with a duplicate id', function () { - spyOn($log, 'warn'); - var toolbar = tbs.createToolbar('foo'), - btn = toolbar.addButton('btn0', 'gid'), - dup; - expect(btn).not.toBeNull(); - expect(btn.id).toBe('toolbar-foo-btn0'); - - dup = toolbar.addButton('btn0', 'gid'); - expect($log.warn).toHaveBeenCalledWith('addButton: duplicate ID:', 'btn0'); - expect(dup).toBeNull(); - - dup = toolbar.addToggle('btn0', 'gid'); - expect($log.warn).toHaveBeenCalledWith('addToggle: duplicate ID:', 'btn0'); - expect(dup).toBeNull(); - - dup = toolbar.addRadioSet('btn0', []); - expect($log.warn).toHaveBeenCalledWith('addRadioSet: duplicate ID:', 'btn0'); - expect(dup).toBeNull(); - }); - - it('should create a toggle', function () { - spyOn($log, 'warn'); - var toolbar = tbs.createToolbar('foo'), - tog = toolbar.addButton('tog0', 'gid'); - expect(tog).not.toBeNull(); - expect(tog.id).toBe('toolbar-foo-tog0'); - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should create a radio button set', function () { - spyOn($log, 'warn'); - var toolbar = tbs.createToolbar('foo'), - rset = [ - { gid: 'crown', cb: nullFunc, tooltip: 'A Crown' }, - { gid: 'bird', cb: nullFunc, tooltip: 'A Bird' } - ], - rad = toolbar.addRadioSet('rad0', rset); - expect(rad).not.toBeNull(); - expect(rad.selectedIndex()).toBe(0); - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should create a separator div', function () { - spyOn($log, 'warn'); - var toolbar = tbs.createToolbar('foo'), - tbar = d3.select('#toolbar-foo'); - - toolbar.addSeparator(); - expect($log.warn).not.toHaveBeenCalled(); - - expect(tbar.select('.separator').size()).toBe(1); - }); - - it('should add another row of buttons', function () { - var toolbar = tbs.createToolbar('foo'), - tbar = d3.select('#toolbar-foo'), - rows; - toolbar.addButton('btn0', 'gid'); - toolbar.addRow(); - toolbar.addButton('btn1', 'gid'); - - rows = tbar.selectAll('.tbar-row'); - expect(rows.size()).toBe(2); - rows.each(function (d, i) { - expect(d3.select(this) - .select('div') - .attr('id','toolbar-foo-btn' + i) - .empty()) - .toBe(false); - }); - }); - - it('should not add a row if current row is empty', function () { - var toolbar = tbs.createToolbar('foo'); - expect(toolbar.addRow()).toBeNull(); - toolbar.addButton('btn0', 'gid'); - expect(toolbar.addRow()).not.toBeNull(); - expect(toolbar.addRow()).toBeNull(); - }); - -}); diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/tooltip-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/tooltip-spec.js deleted file mode 100644 index 0ae1f65d..00000000 --- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/widget/tooltip-spec.js +++ /dev/null @@ -1,79 +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 -- Widget -- Tooltip Service - Unit Tests - */ -describe('factory: fw/widget/tooltip.js', function () { - var $log, fs, tts, d3Elem; - - beforeEach(module('onosWidget', 'onosUtil')); - - beforeEach(inject(function (_$log_, FnService, TooltipService) { - $log = _$log_; - fs = FnService; - tts = TooltipService; - })); - - beforeEach(function () { - d3Elem = d3.select('body').append('div').attr('id', 'tooltip'); - }); - - afterEach(function () { - d3.select('#tooltip').remove(); - }); - - it('should define TooltipService', function () { - expect(tts).toBeDefined(); - }); - - it('should define api functions', function () { - expect(fs.areFunctions(tts, [ - 'showTooltip', 'cancelTooltip' - ])).toBeTruthy(); - }); - - it('should not accept undefined arguments', function () { - var btn = d3.select('body').append('div'); - expect(tts.showTooltip()).toBeFalsy(); - expect(tts.showTooltip(btn)).toBeFalsy(); - - expect(tts.cancelTooltip()).toBeFalsy(); - }); - - // TODO: figure out how to test this - // testing mouse events is tough - // showTooltip needs a d3 event, which currently has no test backend - // .each is a workaround, which provides this, d, and i - xit('should show a tooltip', function () { - var btn = d3.select('body').append('div').attr('id', 'foo'); - btn.each(function () { - tts.showTooltip(this, 'yay a tooltip'); - }); - // tests here - }); - - // can't cancel a tooltip until we show one - // because currElemId isn't set otherwise - xit('should cancel an existing tooltip', function () { - var btn = d3.select('body').append('div').attr('id', 'foo'); - btn.each(function () { - tts.cancelTooltip(this); - }); - expect(d3Elem.text()).toBe(''); - expect(d3Elem.style('display')).toBe('none'); - }); -}); |