Steven Burrows | b51380a | 2017-11-10 15:19:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Layer -- Veil Service - Unit Tests |
| 19 | */ |
| 20 | |
| 21 | describe('factory: fw/layer/details-panel.js', function () { |
| 22 | var $log, $timeout, fs, ps, dps, d3Elem, $scope; |
| 23 | |
| 24 | beforeEach(module('onosLayer', 'onosMast', 'onosRemote', 'onosSvg')); |
| 25 | |
| 26 | beforeEach(inject(function (_$log_, _$timeout_, $rootScope, FnService, PanelService, DetailsPanelService) { |
| 27 | $log = _$log_; |
| 28 | $timeout = _$timeout_; |
| 29 | $scope = $rootScope.$new(); |
| 30 | fs = FnService; |
| 31 | dps = DetailsPanelService; |
| 32 | ps = PanelService; |
| 33 | |
| 34 | spyOn(fs, 'debugOn').and.returnValue(true); |
| 35 | d3Elem = d3.select('body').append('div').attr('id', 'floatpanels'); |
| 36 | d3.select('body').append('div').attr('class', 'tabular-header').style({ height: 10 }); |
| 37 | ps.init(); |
| 38 | |
| 39 | })); |
| 40 | |
| 41 | afterEach(function () { |
| 42 | d3.select('#floatpanels').remove(); |
| 43 | ps.init(); |
| 44 | }); |
| 45 | |
| 46 | function floatPanelSelection() { |
| 47 | return d3Elem.selectAll('.floatpanel'); |
| 48 | } |
| 49 | |
| 50 | it('should define PanelService', function () { |
| 51 | expect(ps).toBeDefined(); |
| 52 | }); |
| 53 | |
| 54 | it('should define api functions', function () { |
| 55 | expect(fs.areFunctions(dps, [ |
| 56 | 'create', 'setResponse', |
| 57 | 'addContainers', 'addCloseButton', 'addHeading', 'addPropsList', |
| 58 | 'container', 'top', 'bottom', 'select', |
| 59 | 'empty', 'hide', 'destroy', |
| 60 | ])).toBeTruthy(); |
| 61 | }); |
| 62 | |
| 63 | it('should create a default panel', function () { |
| 64 | var p = dps.create('foo', { scope: $scope }); |
| 65 | expect(p).toBeDefined(); |
| 66 | }); |
| 67 | |
| 68 | it('should add response handler', function () { |
| 69 | var p = dps.create('foo', { scope: $scope }); |
| 70 | dps.setResponse('responseName', function () {}); |
| 71 | }); |
| 72 | |
| 73 | it('should add content', function () { |
| 74 | var p = dps.create('foo', { scope: $scope }); |
| 75 | |
| 76 | dps.addContainers(); |
| 77 | dps.addCloseButton(function () {}); |
| 78 | |
| 79 | expect(dps.container()).toBeDefined(); |
| 80 | expect(dps.top()).toBeDefined(); |
| 81 | expect(dps.bottom()).toBeDefined(); |
| 82 | |
| 83 | var top = dps.top(); |
| 84 | top.append('div').classed('top-content', true); |
| 85 | dps.addHeading('icon', false); |
| 86 | dps.addPropsList(dps.select('.top-content'), { id: 'foo', name: 'bar' }); |
| 87 | |
| 88 | // TODO: props have been added to the table |
| 89 | // TODO: close button has been created |
| 90 | // TODO: heading placeholder has been added |
| 91 | }); |
| 92 | |
| 93 | it('should add editable header', function () { |
| 94 | var p = dps.create('foo', { scope: $scope }); |
| 95 | dps.addHeading('icon', true); |
| 96 | // TODO: editable heading placeholder has been added |
| 97 | }); |
| 98 | |
| 99 | it('should add unbind on destroy', function () { |
| 100 | var p = dps.create('foo', { scope: $scope }); |
| 101 | dps.setResponse('responseName', function () {}); |
| 102 | dps.destroy(); |
| 103 | }); |
| 104 | |
| 105 | }); |