blob: e48c27cd8dadb126522626179ca53d61f44b93c3 [file] [log] [blame]
Simon Huntb0ec1e52015-01-28 18:13:49 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Huntb0ec1e52015-01-28 18:13:49 -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 -- Topo View -- Topo Panel Service - Unit Tests
19 */
20describe('factory: view/topo/topoPanel.js', function() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070021 var $log, fs, tps, bns, ps, panelLayer;
22
23 var mockWindow = {
24 innerWidth: 300,
25 innerHeight: 100,
26 navigator: {
27 userAgent: 'defaultUA'
28 },
29 on: function () {},
30 addEventListener: function () {}
31 };
Simon Huntb0ec1e52015-01-28 18:13:49 -080032
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -070033 beforeEach(module('ovTopo', 'onosUtil', 'onosLayer', 'ngRoute', 'onosNav',
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070034 'onosWidget', 'onosMast'));
Simon Huntb0ec1e52015-01-28 18:13:49 -080035
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070036 beforeEach(function () {
37 module(function ($provide) {
38 $provide.value('$window', mockWindow);
39 });
40 });
41
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -070042 beforeEach(inject(function (_$log_, FnService,
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070043 TopoPanelService, ButtonService, PanelService) {
Simon Huntb0ec1e52015-01-28 18:13:49 -080044 $log = _$log_;
45 fs = FnService;
46 tps = TopoPanelService;
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -070047 bns = ButtonService;
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070048 ps = PanelService;
49 panelLayer = d3.select('body').append('div').attr('id', 'floatpanels');
Simon Huntb0ec1e52015-01-28 18:13:49 -080050 }));
51
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070052 afterEach(function () {
53 panelLayer.remove();
54 });
55
Simon Huntb0ec1e52015-01-28 18:13:49 -080056 it('should define TopoPanelService', function () {
57 expect(tps).toBeDefined();
58 });
59
Matteo Scandolo209c6c62016-05-21 10:08:57 -070060 it('should define api functions', function () {
Simon Huntb0ec1e52015-01-28 18:13:49 -080061 expect(fs.areFunctions(tps, [
Simon Hunt08f841d02015-02-10 14:39:20 -080062 'initPanels',
63 'destroyPanels',
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070064 'createTopoPanel',
65
Simon Hunt08f841d02015-02-10 14:39:20 -080066 'showSummary',
Simon Hunt6036b192015-02-11 11:20:26 -080067 'toggleSummary',
Matteo Scandolo209c6c62016-05-21 10:08:57 -070068 'hideSummary',
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070069
Simon Hunt239e5882015-04-23 15:07:04 -070070 'toggleUseDetailsFlag',
Simon Hunt08f841d02015-02-10 14:39:20 -080071 'displaySingle',
72 'displayMulti',
Simon Hunt3074fb22015-03-31 15:06:25 -070073 'displayLink',
74 'displayNothing',
75 'displaySomething',
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070076 'addAction',
77
Simon Hunt08f841d02015-02-10 14:39:20 -080078 'detailVisible',
Simon Hunt879ce452017-08-10 23:32:00 -070079 'summaryVisible',
80
81 'setLionBundle',
Simon Huntb0ec1e52015-01-28 18:13:49 -080082 ])).toBeTruthy();
83 });
84
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070085 // === topoPanel api ------------------
86
87 it('should define topoPanel api functions', function () {
88 var panel = tps.createTopoPanel('foo');
89 expect(fs.areFunctions(panel, [
90 'panel', 'setup', 'destroy',
91 'appendHeader', 'appendBody', 'appendFooter',
92 'adjustHeight'
93 ])).toBeTruthy();
94 panel.destroy();
95 });
96
97 it('should allow you to get panel', function () {
98 var panel = tps.createTopoPanel('foo');
99 expect(panel.panel()).toBeTruthy();
100 panel.destroy();
101 });
102
103 it('should set up panel', function () {
104 var p = tps.createTopoPanel('foo'),
105 h, b, f;
106 p.setup();
107 expect(p.panel().el().selectAll('div').size()).toBe(3);
108
109 h = p.panel().el().select('.header');
110 expect(h.empty()).toBe(false);
111 b = p.panel().el().select('.body');
112 expect(b.empty()).toBe(false);
113 f = p.panel().el().select('.footer');
114 expect(f.empty()).toBe(false);
115 p.destroy();
116 });
117
118 it('should destroy panel', function () {
119 spyOn(ps, 'destroyPanel').and.callThrough();
120 var p = tps.createTopoPanel('foo');
121 p.destroy();
122 expect(ps.destroyPanel).toHaveBeenCalledWith('foo');
123 });
124
125 it('should append to panel', function () {
126 var p = tps.createTopoPanel('foo');
127 p.setup();
128 p.appendHeader('div').attr('id', 'header-div');
129 expect(p.panel().el().select('#header-div').empty()).toBe(false);
130 p.appendBody('p').attr('id', 'body-paragraph');
131 expect(p.panel().el().select('#body-paragraph').empty()).toBe(false);
132 p.appendFooter('svg').attr('id', 'footer-svg');
133 expect(p.panel().el().select('#footer-svg').empty()).toBe(false);
134 p.destroy();
135 });
136
137 it('should warn if fromTop not given, adjustHeight', function () {
138 spyOn($log, 'warn');
139 var p = tps.createTopoPanel('foo');
140 p.adjustHeight();
141 expect($log.warn).toHaveBeenCalledWith(
142 'adjustHeight: height from top of page not given'
143 );
144 p.destroy();
145 });
146
Matteo Scandolo812aa5a2016-04-19 18:12:45 -0700147 xit('should warn if panel is not setup/defined, adjustHeight', function () {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700148 spyOn($log, 'warn');
149 var p = tps.createTopoPanel('foo');
150 p.adjustHeight(50);
151 expect($log.warn).toHaveBeenCalledWith(
152 'adjustHeight: panel contents are not defined'
153 );
154 p.destroy();
155 });
156
157 // TODO: test adjustHeight height adjustment
158
Simon Huntb0ec1e52015-01-28 18:13:49 -0800159 // TODO: more tests...
160});