Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -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 | b0ec1e5 | 2015-01-28 18:13:49 -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 -- Topo View -- Topo Panel Service - Unit Tests |
| 19 | */ |
| 20 | describe('factory: view/topo/topoPanel.js', function() { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 21 | 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 Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 32 | |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 33 | beforeEach(module('ovTopo', 'onosUtil', 'onosLayer', 'ngRoute', 'onosNav', |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 34 | 'onosWidget', 'onosMast')); |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 35 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 36 | beforeEach(function () { |
| 37 | module(function ($provide) { |
| 38 | $provide.value('$window', mockWindow); |
| 39 | }); |
| 40 | }); |
| 41 | |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 42 | beforeEach(inject(function (_$log_, FnService, |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 43 | TopoPanelService, ButtonService, PanelService) { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 44 | $log = _$log_; |
| 45 | fs = FnService; |
| 46 | tps = TopoPanelService; |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 47 | bns = ButtonService; |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 48 | ps = PanelService; |
| 49 | panelLayer = d3.select('body').append('div').attr('id', 'floatpanels'); |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 50 | })); |
| 51 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 52 | afterEach(function () { |
| 53 | panelLayer.remove(); |
| 54 | }); |
| 55 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 56 | it('should define TopoPanelService', function () { |
| 57 | expect(tps).toBeDefined(); |
| 58 | }); |
| 59 | |
Matteo Scandolo | 209c6c6 | 2016-05-21 10:08:57 -0700 | [diff] [blame] | 60 | it('should define api functions', function () { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 61 | expect(fs.areFunctions(tps, [ |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 62 | 'initPanels', |
| 63 | 'destroyPanels', |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 64 | 'createTopoPanel', |
| 65 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 66 | 'showSummary', |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 67 | 'toggleSummary', |
Matteo Scandolo | 209c6c6 | 2016-05-21 10:08:57 -0700 | [diff] [blame] | 68 | 'hideSummary', |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 69 | |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 70 | 'toggleUseDetailsFlag', |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 71 | 'displaySingle', |
| 72 | 'displayMulti', |
Simon Hunt | 3074fb2 | 2015-03-31 15:06:25 -0700 | [diff] [blame] | 73 | 'displayLink', |
| 74 | 'displayNothing', |
| 75 | 'displaySomething', |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 76 | 'addAction', |
| 77 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 78 | 'detailVisible', |
| 79 | 'summaryVisible' |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 80 | ])).toBeTruthy(); |
| 81 | }); |
| 82 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 83 | // === 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 Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 145 | xit('should warn if panel is not setup/defined, adjustHeight', function () { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 146 | 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 Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 157 | // TODO: more tests... |
| 158 | }); |