Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 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 -- Panel Service - Unit Tests |
| 19 | */ |
| 20 | describe('factory: fw/layer/panel.js', function () { |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 21 | var $log, $timeout, fs, ps, d3Elem; |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 22 | |
| 23 | beforeEach(module('onosLayer')); |
| 24 | |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 25 | beforeEach(inject(function (_$log_, _$timeout_, FnService, PanelService) { |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 26 | $log = _$log_; |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 27 | $timeout = _$timeout_; |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 28 | fs = FnService; |
| 29 | ps = PanelService; |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 30 | d3Elem = d3.select('body').append('div').attr('id', 'floatpanels'); |
| 31 | ps.init(); |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 32 | })); |
| 33 | |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 34 | afterEach(function () { |
| 35 | d3.select('#floatpanels').remove(); |
| 36 | ps.init(); |
| 37 | }); |
| 38 | |
| 39 | function floatPanelSelection() { |
| 40 | return d3Elem.selectAll('.floatpanel'); |
| 41 | } |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 42 | |
| 43 | it('should define PanelService', function () { |
| 44 | expect(ps).toBeDefined(); |
| 45 | }); |
| 46 | |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 47 | xit('should define api functions', function () { |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 48 | expect(fs.areFunctions(ps, [ |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 49 | 'init', 'createPanel', 'destroyPanel' |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 50 | ])).toBeTruthy(); |
| 51 | }); |
| 52 | |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 53 | it('should have no panels to start', function () { |
| 54 | expect(floatPanelSelection().size()).toBe(0); |
| 55 | }); |
| 56 | |
| 57 | it('should log a warning if no ID is given', function () { |
| 58 | spyOn($log, 'warn'); |
| 59 | var p = ps.createPanel(); |
| 60 | expect(p).toBeNull(); |
| 61 | expect($log.warn).toHaveBeenCalledWith('createPanel: no ID given'); |
| 62 | expect(floatPanelSelection().size()).toBe(0); |
| 63 | }); |
| 64 | |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 65 | xit('should create a default panel', function () { |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 66 | spyOn($log, 'warn'); |
| 67 | spyOn($log, 'debug'); |
| 68 | var p = ps.createPanel('foo'); |
| 69 | expect(p).not.toBeNull(); |
| 70 | expect($log.warn).not.toHaveBeenCalled(); |
| 71 | expect(floatPanelSelection().size()).toBe(1); |
| 72 | expect($log.debug).toHaveBeenCalledWith('creating panel:', 'foo', { |
| 73 | edge: 'right', |
| 74 | width: 200, |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 75 | margin: 20, |
Simon Hunt | 7c7dd3e | 2015-02-27 11:42:18 -0800 | [diff] [blame] | 76 | hideMargin: 20, |
| 77 | xtnTime: 750, |
| 78 | fade: true |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 79 | }); |
| 80 | |
| 81 | // check basic properties |
| 82 | expect(p.width()).toEqual(200); |
| 83 | expect(p.isVisible()).toBeFalsy(); |
| 84 | |
| 85 | var el = floatPanelSelection(); |
| 86 | expect(el.style('width')).toEqual('200px'); |
| 87 | }); |
| 88 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 89 | it('should provide an api of panel functions', function () { |
| 90 | var p = ps.createPanel('foo'); |
| 91 | expect(fs.areFunctions(p, [ |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 92 | 'show', 'hide', 'toggle', 'empty', 'append', |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 93 | 'width', 'height', 'isVisible', 'classed', 'el' |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 94 | ])).toBeTruthy(); |
| 95 | }); |
| 96 | |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 97 | it('should complain when a duplicate ID is used', function () { |
| 98 | spyOn($log, 'warn'); |
| 99 | var p = ps.createPanel('foo'); |
| 100 | expect(p).not.toBeNull(); |
| 101 | expect($log.warn).not.toHaveBeenCalled(); |
| 102 | expect(floatPanelSelection().size()).toBe(1); |
| 103 | |
| 104 | var dup = ps.createPanel('foo'); |
| 105 | expect(dup).toBeNull(); |
| 106 | expect($log.warn).toHaveBeenCalledWith('Panel with ID "foo" already exists'); |
| 107 | expect(floatPanelSelection().size()).toBe(1); |
| 108 | }); |
| 109 | |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 110 | xit('should note when there is no panel to destroy', function () { |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 111 | spyOn($log, 'debug'); |
| 112 | ps.destroyPanel('bar'); |
Bri Prebilic Cole | 751804e | 2015-02-18 15:44:28 -0800 | [diff] [blame] | 113 | expect($log.debug).toHaveBeenCalledWith('no panel to destroy:', 'bar'); |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 114 | }); |
| 115 | |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 116 | xit('should destroy the panel', function () { |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 117 | spyOn($log, 'debug'); |
| 118 | var p = ps.createPanel('foo'); |
| 119 | expect(floatPanelSelection().size()).toBe(1); |
| 120 | |
| 121 | ps.destroyPanel('foo'); |
Bri Prebilic Cole | 751804e | 2015-02-18 15:44:28 -0800 | [diff] [blame] | 122 | expect($log.debug).toHaveBeenCalledWith('destroying panel:', 'foo'); |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 123 | expect(floatPanelSelection().size()).toBe(0); |
| 124 | }); |
| 125 | |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 126 | xit('should allow alternate settings to be given', function () { |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 127 | spyOn($log, 'debug'); |
| 128 | var p = ps.createPanel('foo', { width: 250, edge: 'left' }); |
| 129 | expect($log.debug).toHaveBeenCalledWith('creating panel:', 'foo', { |
| 130 | edge: 'left', |
| 131 | width: 250, |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 132 | margin: 20, |
Simon Hunt | 7c7dd3e | 2015-02-27 11:42:18 -0800 | [diff] [blame] | 133 | hideMargin: 20, |
| 134 | xtnTime: 750, |
| 135 | fade: true |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 136 | }); |
| 137 | }); |
| 138 | |
| 139 | it('should show and hide the panel', function () { |
| 140 | var p = ps.createPanel('foo', {xtnTime:0}); |
| 141 | expect(p.isVisible()).toBeFalsy(); |
| 142 | |
| 143 | p.show(); |
| 144 | expect(p.isVisible()).toBeTruthy(); |
| 145 | |
| 146 | p.hide(); |
| 147 | expect(p.isVisible()).toBeFalsy(); |
| 148 | }); |
| 149 | |
| 150 | it('should append content to the panel', function () { |
| 151 | var p = ps.createPanel('foo'); |
| 152 | var span = p.append('span').attr('id', 'thisIsMySpan'); |
| 153 | |
| 154 | expect(floatPanelSelection().selectAll('span').attr('id')) |
| 155 | .toEqual('thisIsMySpan'); |
| 156 | }); |
| 157 | |
| 158 | it('should remove content on empty', function () { |
| 159 | var p = ps.createPanel('voop'); |
| 160 | p.append('span'); |
| 161 | p.append('span'); |
| 162 | p.append('span'); |
| 163 | expect(floatPanelSelection().selectAll('span').size()).toEqual(3); |
| 164 | |
| 165 | p.empty(); |
| 166 | expect(floatPanelSelection().selectAll('span').size()).toEqual(0); |
| 167 | expect(floatPanelSelection().html()).toEqual(''); |
| 168 | }); |
| 169 | |
| 170 | it('should allow programmatic setting of width', function () { |
| 171 | var p = ps.createPanel('whatcha', {width:234}); |
| 172 | expect(floatPanelSelection().style('width')).toEqual('234px'); |
| 173 | expect(p.width()).toEqual(234); |
| 174 | |
| 175 | p.width(345); |
| 176 | expect(floatPanelSelection().style('width')).toEqual('345px'); |
| 177 | expect(p.width()).toEqual(345); |
| 178 | }); |
| 179 | |
| 180 | it('should allow programmatic setting of height', function () { |
| 181 | var p = ps.createPanel('ciao', {height:50}); |
| 182 | expect(floatPanelSelection().style('height')).toEqual('50px'); |
| 183 | expect(p.height()).toEqual(50); |
| 184 | |
| 185 | p.height(100); |
| 186 | expect(floatPanelSelection().style('height')).toEqual('100px'); |
| 187 | expect(p.height()).toEqual(100); |
| 188 | }); |
Simon Hunt | 988934e | 2015-01-23 11:49:24 -0800 | [diff] [blame] | 189 | }); |