blob: 16b67afd54636d5807c9646dd951eff075dc89d2 [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',
79 'summaryVisible'
Simon Huntb0ec1e52015-01-28 18:13:49 -080080 ])).toBeTruthy();
81 });
82
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070083 // === topoPanel api ------------------
84
85 it('should define topoPanel api functions', function () {
86 var panel = tps.createTopoPanel('foo');
87 expect(fs.areFunctions(panel, [
88 'panel', 'setup', 'destroy',
89 'appendHeader', 'appendBody', 'appendFooter',
90 'adjustHeight'
91 ])).toBeTruthy();
92 panel.destroy();
93 });
94
95 it('should allow you to get panel', function () {
96 var panel = tps.createTopoPanel('foo');
97 expect(panel.panel()).toBeTruthy();
98 panel.destroy();
99 });
100
101 it('should set up panel', function () {
102 var p = tps.createTopoPanel('foo'),
103 h, b, f;
104 p.setup();
105 expect(p.panel().el().selectAll('div').size()).toBe(3);
106
107 h = p.panel().el().select('.header');
108 expect(h.empty()).toBe(false);
109 b = p.panel().el().select('.body');
110 expect(b.empty()).toBe(false);
111 f = p.panel().el().select('.footer');
112 expect(f.empty()).toBe(false);
113 p.destroy();
114 });
115
116 it('should destroy panel', function () {
117 spyOn(ps, 'destroyPanel').and.callThrough();
118 var p = tps.createTopoPanel('foo');
119 p.destroy();
120 expect(ps.destroyPanel).toHaveBeenCalledWith('foo');
121 });
122
123 it('should append to panel', function () {
124 var p = tps.createTopoPanel('foo');
125 p.setup();
126 p.appendHeader('div').attr('id', 'header-div');
127 expect(p.panel().el().select('#header-div').empty()).toBe(false);
128 p.appendBody('p').attr('id', 'body-paragraph');
129 expect(p.panel().el().select('#body-paragraph').empty()).toBe(false);
130 p.appendFooter('svg').attr('id', 'footer-svg');
131 expect(p.panel().el().select('#footer-svg').empty()).toBe(false);
132 p.destroy();
133 });
134
135 it('should warn if fromTop not given, adjustHeight', function () {
136 spyOn($log, 'warn');
137 var p = tps.createTopoPanel('foo');
138 p.adjustHeight();
139 expect($log.warn).toHaveBeenCalledWith(
140 'adjustHeight: height from top of page not given'
141 );
142 p.destroy();
143 });
144
Matteo Scandolo812aa5a2016-04-19 18:12:45 -0700145 xit('should warn if panel is not setup/defined, adjustHeight', function () {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700146 spyOn($log, 'warn');
147 var p = tps.createTopoPanel('foo');
148 p.adjustHeight(50);
149 expect($log.warn).toHaveBeenCalledWith(
150 'adjustHeight: panel contents are not defined'
151 );
152 p.destroy();
153 });
154
155 // TODO: test adjustHeight height adjustment
156
Simon Huntb0ec1e52015-01-28 18:13:49 -0800157 // TODO: more tests...
158});