blob: 2f89f44c883f3830faf86dd5c8cd717777927a70 [file] [log] [blame]
Simon Huntb0ec1e52015-01-28 18:13:49 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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 Scandolo812aa5a2016-04-19 18:12:45 -070060 xit('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',
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070068
Simon Hunt239e5882015-04-23 15:07:04 -070069 'toggleUseDetailsFlag',
Simon Hunt08f841d02015-02-10 14:39:20 -080070 'displaySingle',
71 'displayMulti',
Simon Hunt3074fb22015-03-31 15:06:25 -070072 'displayLink',
73 'displayNothing',
74 'displaySomething',
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070075 'addAction',
76
Simon Huntc252aa62015-02-10 16:45:39 -080077 'hideSummaryPanel',
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070078
Simon Hunt08f841d02015-02-10 14:39:20 -080079 'detailVisible',
80 'summaryVisible'
Simon Huntb0ec1e52015-01-28 18:13:49 -080081 ])).toBeTruthy();
82 });
83
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070084 // === topoPanel api ------------------
85
86 it('should define topoPanel api functions', function () {
87 var panel = tps.createTopoPanel('foo');
88 expect(fs.areFunctions(panel, [
89 'panel', 'setup', 'destroy',
90 'appendHeader', 'appendBody', 'appendFooter',
91 'adjustHeight'
92 ])).toBeTruthy();
93 panel.destroy();
94 });
95
96 it('should allow you to get panel', function () {
97 var panel = tps.createTopoPanel('foo');
98 expect(panel.panel()).toBeTruthy();
99 panel.destroy();
100 });
101
102 it('should set up panel', function () {
103 var p = tps.createTopoPanel('foo'),
104 h, b, f;
105 p.setup();
106 expect(p.panel().el().selectAll('div').size()).toBe(3);
107
108 h = p.panel().el().select('.header');
109 expect(h.empty()).toBe(false);
110 b = p.panel().el().select('.body');
111 expect(b.empty()).toBe(false);
112 f = p.panel().el().select('.footer');
113 expect(f.empty()).toBe(false);
114 p.destroy();
115 });
116
117 it('should destroy panel', function () {
118 spyOn(ps, 'destroyPanel').and.callThrough();
119 var p = tps.createTopoPanel('foo');
120 p.destroy();
121 expect(ps.destroyPanel).toHaveBeenCalledWith('foo');
122 });
123
124 it('should append to panel', function () {
125 var p = tps.createTopoPanel('foo');
126 p.setup();
127 p.appendHeader('div').attr('id', 'header-div');
128 expect(p.panel().el().select('#header-div').empty()).toBe(false);
129 p.appendBody('p').attr('id', 'body-paragraph');
130 expect(p.panel().el().select('#body-paragraph').empty()).toBe(false);
131 p.appendFooter('svg').attr('id', 'footer-svg');
132 expect(p.panel().el().select('#footer-svg').empty()).toBe(false);
133 p.destroy();
134 });
135
136 it('should warn if fromTop not given, adjustHeight', function () {
137 spyOn($log, 'warn');
138 var p = tps.createTopoPanel('foo');
139 p.adjustHeight();
140 expect($log.warn).toHaveBeenCalledWith(
141 'adjustHeight: height from top of page not given'
142 );
143 p.destroy();
144 });
145
Matteo Scandolo812aa5a2016-04-19 18:12:45 -0700146 xit('should warn if panel is not setup/defined, adjustHeight', function () {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700147 spyOn($log, 'warn');
148 var p = tps.createTopoPanel('foo');
149 p.adjustHeight(50);
150 expect($log.warn).toHaveBeenCalledWith(
151 'adjustHeight: panel contents are not defined'
152 );
153 p.destroy();
154 });
155
156 // TODO: test adjustHeight height adjustment
157
Simon Huntb0ec1e52015-01-28 18:13:49 -0800158 // TODO: more tests...
159});