GUI -- Fixed warning about undefined panel, added topoPanel destroy, added unit tests for topoPanel.
Change-Id: Ic7ecc2771aa64bb0db19fe3b8005dc3932b237c5
diff --git a/web/gui/src/main/webapp/tests/app/view/topo/topoPanel-spec.js b/web/gui/src/main/webapp/tests/app/view/topo/topoPanel-spec.js
index bd1c172..21513d1 100644
--- a/web/gui/src/main/webapp/tests/app/view/topo/topoPanel-spec.js
+++ b/web/gui/src/main/webapp/tests/app/view/topo/topoPanel-spec.js
@@ -18,19 +18,41 @@
ONOS GUI -- Topo View -- Topo Panel Service - Unit Tests
*/
describe('factory: view/topo/topoPanel.js', function() {
- var $log, fs, tps, bns;
+ var $log, fs, tps, bns, ps, panelLayer;
+
+ var mockWindow = {
+ innerWidth: 300,
+ innerHeight: 100,
+ navigator: {
+ userAgent: 'defaultUA'
+ },
+ on: function () {},
+ addEventListener: function () {}
+ };
beforeEach(module('ovTopo', 'onosUtil', 'onosLayer', 'ngRoute', 'onosNav',
'onosWidget'));
+ beforeEach(function () {
+ module(function ($provide) {
+ $provide.value('$window', mockWindow);
+ });
+ });
+
beforeEach(inject(function (_$log_, FnService,
- TopoPanelService, ButtonService) {
+ TopoPanelService, ButtonService, PanelService) {
$log = _$log_;
fs = FnService;
tps = TopoPanelService;
bns = ButtonService;
+ ps = PanelService;
+ panelLayer = d3.select('body').append('div').attr('id', 'floatpanels');
}));
+ afterEach(function () {
+ panelLayer.remove();
+ });
+
it('should define TopoPanelService', function () {
expect(tps).toBeDefined();
});
@@ -39,20 +61,99 @@
expect(fs.areFunctions(tps, [
'initPanels',
'destroyPanels',
+ 'createTopoPanel',
+
'showSummary',
'toggleSummary',
+
'toggleUseDetailsFlag',
'displaySingle',
'displayMulti',
- 'addAction',
'displayLink',
'displayNothing',
'displaySomething',
+ 'addAction',
+
'hideSummaryPanel',
+
'detailVisible',
'summaryVisible'
])).toBeTruthy();
});
+ // === topoPanel api ------------------
+
+ it('should define topoPanel api functions', function () {
+ var panel = tps.createTopoPanel('foo');
+ expect(fs.areFunctions(panel, [
+ 'panel', 'setup', 'destroy',
+ 'appendHeader', 'appendBody', 'appendFooter',
+ 'adjustHeight'
+ ])).toBeTruthy();
+ panel.destroy();
+ });
+
+ it('should allow you to get panel', function () {
+ var panel = tps.createTopoPanel('foo');
+ expect(panel.panel()).toBeTruthy();
+ panel.destroy();
+ });
+
+ it('should set up panel', function () {
+ var p = tps.createTopoPanel('foo'),
+ h, b, f;
+ p.setup();
+ expect(p.panel().el().selectAll('div').size()).toBe(3);
+
+ h = p.panel().el().select('.header');
+ expect(h.empty()).toBe(false);
+ b = p.panel().el().select('.body');
+ expect(b.empty()).toBe(false);
+ f = p.panel().el().select('.footer');
+ expect(f.empty()).toBe(false);
+ p.destroy();
+ });
+
+ it('should destroy panel', function () {
+ spyOn(ps, 'destroyPanel').and.callThrough();
+ var p = tps.createTopoPanel('foo');
+ p.destroy();
+ expect(ps.destroyPanel).toHaveBeenCalledWith('foo');
+ });
+
+ it('should append to panel', function () {
+ var p = tps.createTopoPanel('foo');
+ p.setup();
+ p.appendHeader('div').attr('id', 'header-div');
+ expect(p.panel().el().select('#header-div').empty()).toBe(false);
+ p.appendBody('p').attr('id', 'body-paragraph');
+ expect(p.panel().el().select('#body-paragraph').empty()).toBe(false);
+ p.appendFooter('svg').attr('id', 'footer-svg');
+ expect(p.panel().el().select('#footer-svg').empty()).toBe(false);
+ p.destroy();
+ });
+
+ it('should warn if fromTop not given, adjustHeight', function () {
+ spyOn($log, 'warn');
+ var p = tps.createTopoPanel('foo');
+ p.adjustHeight();
+ expect($log.warn).toHaveBeenCalledWith(
+ 'adjustHeight: height from top of page not given'
+ );
+ p.destroy();
+ });
+
+ it('should warn if panel is not setup/defined, adjustHeight', function () {
+ spyOn($log, 'warn');
+ var p = tps.createTopoPanel('foo');
+ p.adjustHeight(50);
+ expect($log.warn).toHaveBeenCalledWith(
+ 'adjustHeight: panel contents are not defined'
+ );
+ p.destroy();
+ });
+
+ // TODO: test adjustHeight height adjustment
+
// TODO: more tests...
});