blob: 452a4be5b6ee8f29d95b7da0d797c728d1016908 [file] [log] [blame]
Simon Hunt988934e2015-01-23 11:49:24 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt988934e2015-01-23 11:49:24 -08003 *
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 */
20describe('factory: fw/layer/panel.js', function () {
Simon Hunt54442fa2015-01-26 14:17:38 -080021 var $log, $timeout, fs, ps, d3Elem;
Simon Hunt988934e2015-01-23 11:49:24 -080022
23 beforeEach(module('onosLayer'));
24
Simon Hunt54442fa2015-01-26 14:17:38 -080025 beforeEach(inject(function (_$log_, _$timeout_, FnService, PanelService) {
Simon Hunt988934e2015-01-23 11:49:24 -080026 $log = _$log_;
Simon Hunt54442fa2015-01-26 14:17:38 -080027 $timeout = _$timeout_;
Simon Hunt988934e2015-01-23 11:49:24 -080028 fs = FnService;
29 ps = PanelService;
Simon Hunt54442fa2015-01-26 14:17:38 -080030 d3Elem = d3.select('body').append('div').attr('id', 'floatpanels');
31 ps.init();
Simon Hunt988934e2015-01-23 11:49:24 -080032 }));
33
Simon Hunt54442fa2015-01-26 14:17:38 -080034 afterEach(function () {
35 d3.select('#floatpanels').remove();
36 ps.init();
37 });
38
39 function floatPanelSelection() {
40 return d3Elem.selectAll('.floatpanel');
41 }
Simon Hunt988934e2015-01-23 11:49:24 -080042
43 it('should define PanelService', function () {
44 expect(ps).toBeDefined();
45 });
46
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070047 xit('should define api functions', function () {
Simon Hunt988934e2015-01-23 11:49:24 -080048 expect(fs.areFunctions(ps, [
Simon Hunt54442fa2015-01-26 14:17:38 -080049 'init', 'createPanel', 'destroyPanel'
Simon Hunt988934e2015-01-23 11:49:24 -080050 ])).toBeTruthy();
51 });
52
Simon Hunt54442fa2015-01-26 14:17:38 -080053 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 Scandolo812aa5a2016-04-19 18:12:45 -070065 xit('should create a default panel', function () {
Simon Hunt54442fa2015-01-26 14:17:38 -080066 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 Hunt54442fa2015-01-26 14:17:38 -080075 margin: 20,
Simon Hunt7c7dd3e2015-02-27 11:42:18 -080076 hideMargin: 20,
77 xtnTime: 750,
78 fade: true
Simon Hunt54442fa2015-01-26 14:17:38 -080079 });
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 Hunt4b668592015-01-29 17:33:53 -080089 it('should provide an api of panel functions', function () {
90 var p = ps.createPanel('foo');
91 expect(fs.areFunctions(p, [
Simon Hunt5724fb42015-02-05 16:59:40 -080092 'show', 'hide', 'toggle', 'empty', 'append',
Simon Hunt08f841d02015-02-10 14:39:20 -080093 'width', 'height', 'isVisible', 'classed', 'el'
Simon Hunt4b668592015-01-29 17:33:53 -080094 ])).toBeTruthy();
95 });
96
Simon Hunt54442fa2015-01-26 14:17:38 -080097 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 Scandolo812aa5a2016-04-19 18:12:45 -0700110 xit('should note when there is no panel to destroy', function () {
Simon Hunt54442fa2015-01-26 14:17:38 -0800111 spyOn($log, 'debug');
112 ps.destroyPanel('bar');
Bri Prebilic Cole751804e2015-02-18 15:44:28 -0800113 expect($log.debug).toHaveBeenCalledWith('no panel to destroy:', 'bar');
Simon Hunt54442fa2015-01-26 14:17:38 -0800114 });
115
Matteo Scandolo812aa5a2016-04-19 18:12:45 -0700116 xit('should destroy the panel', function () {
Simon Hunt54442fa2015-01-26 14:17:38 -0800117 spyOn($log, 'debug');
118 var p = ps.createPanel('foo');
119 expect(floatPanelSelection().size()).toBe(1);
120
121 ps.destroyPanel('foo');
Bri Prebilic Cole751804e2015-02-18 15:44:28 -0800122 expect($log.debug).toHaveBeenCalledWith('destroying panel:', 'foo');
Simon Hunt54442fa2015-01-26 14:17:38 -0800123 expect(floatPanelSelection().size()).toBe(0);
124 });
125
Matteo Scandolo812aa5a2016-04-19 18:12:45 -0700126 xit('should allow alternate settings to be given', function () {
Simon Hunt54442fa2015-01-26 14:17:38 -0800127 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 Hunt54442fa2015-01-26 14:17:38 -0800132 margin: 20,
Simon Hunt7c7dd3e2015-02-27 11:42:18 -0800133 hideMargin: 20,
134 xtnTime: 750,
135 fade: true
Simon Hunt54442fa2015-01-26 14:17:38 -0800136 });
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 Hunt988934e2015-01-23 11:49:24 -0800189});