Commit 18056e53 by Torkel Ödegaard

ux(dashboard): Fixing broken unit test made by changes for dash edit mode, #6442

parent 786afda4
...@@ -158,12 +158,6 @@ export class DashboardModel { ...@@ -158,12 +158,6 @@ export class DashboardModel {
return null; return null;
} }
rowSpan(row) {
return _.reduce(row.panels, function(p,v) {
return p + v.span;
},0);
};
addPanel(panel, row) { addPanel(panel, row) {
panel.id = this.getNextPanelId(); panel.id = this.getNextPanelId();
row.addPanel(panel); row.addPanel(panel);
...@@ -540,6 +534,7 @@ export class DashboardModel { ...@@ -540,6 +534,7 @@ export class DashboardModel {
// update graph yaxes changes // update graph yaxes changes
panelUpgrades.push(function(panel) { panelUpgrades.push(function(panel) {
if (panel.type !== 'graph') { return; } if (panel.type !== 'graph') { return; }
if (!panel.grid) { return; }
panel.thresholds = []; panel.thresholds = [];
var t1: any = {}, t2: any = {}; var t1: any = {}, t2: any = {};
......
...@@ -81,13 +81,13 @@ export class AddPanelCtrl { ...@@ -81,13 +81,13 @@ export class AddPanelCtrl {
addPanel(panelPluginInfo) { addPanel(panelPluginInfo) {
var defaultSpan = 12; var defaultSpan = 12;
var _as = 12 - this.dashboard.rowSpan(this.row); var span = 12 - this.row.span;
var panel = { var panel = {
id: null, id: null,
title: config.new_panel_title, title: config.new_panel_title,
error: false, error: false,
span: _as < defaultSpan && _as > 0 ? _as : defaultSpan, span: span < defaultSpan && span > 0 ? span : defaultSpan,
editable: true, editable: true,
type: panelPluginInfo.id, type: panelPluginInfo.id,
isNew: true, isNew: true,
......
...@@ -198,7 +198,7 @@ coreModule.directive('panelDropZone', function($timeout) { ...@@ -198,7 +198,7 @@ coreModule.directive('panelDropZone', function($timeout) {
return showPanel(12, 'Empty Space'); return showPanel(12, 'Empty Space');
} }
var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row); var dropZoneSpan = 12 - row.span;
if (dropZoneSpan > 0) { if (dropZoneSpan > 0) {
if (indrag) { if (indrag) {
return showPanel(dropZoneSpan, 'Drop Here'); return showPanel(dropZoneSpan, 'Drop Here');
...@@ -209,7 +209,7 @@ coreModule.directive('panelDropZone', function($timeout) { ...@@ -209,7 +209,7 @@ coreModule.directive('panelDropZone', function($timeout) {
} }
if (indrag === true) { if (indrag === true) {
var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row); var dropZoneSpan = 12 - row.span;
if (dropZoneSpan > 1) { if (dropZoneSpan > 1) {
return showPanel(dropZoneSpan, 'Drop Here'); return showPanel(dropZoneSpan, 'Drop Here');
} }
......
...@@ -51,18 +51,13 @@ describe('dashboardSrv', function() { ...@@ -51,18 +51,13 @@ describe('dashboardSrv', function() {
dashboard = _dashboardSrv.create({}); dashboard = _dashboardSrv.create({});
}); });
it('row span should sum spans', function() {
var spanLeft = dashboard.rowSpan({ panels: [{ span: 2 }, { span: 3 }] });
expect(spanLeft).to.be(5);
});
it('adding default should split span in half', function() { it('adding default should split span in half', function() {
dashboard.rows = [{ panels: [{ span: 12, id: 7 }] }]; dashboard.addEmptyRow();
dashboard.addPanel({span: 4}, dashboard.rows[0]); dashboard.rows[0].addPanel({span: 12});
dashboard.rows[0].addPanel({span: 12});
expect(dashboard.rows[0].panels[0].span).to.be(6); expect(dashboard.rows[0].panels[0].span).to.be(6);
expect(dashboard.rows[0].panels[1].span).to.be(6); expect(dashboard.rows[0].panels[1].span).to.be(6);
expect(dashboard.rows[0].panels[1].id).to.be(8);
}); });
it('duplicate panel should try to add it to same row', function() { it('duplicate panel should try to add it to same row', function() {
......
...@@ -3,6 +3,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co ...@@ -3,6 +3,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co
import _ from 'lodash'; import _ from 'lodash';
import config from 'app/core/config'; import config from 'app/core/config';
import {DashboardExporter} from '../export/exporter'; import {DashboardExporter} from '../export/exporter';
import {DashboardModel} from '../model';
describe('given dashboard with repeated panels', function() { describe('given dashboard with repeated panels', function() {
var dash, exported; var dash, exported;
...@@ -77,6 +78,7 @@ describe('given dashboard with repeated panels', function() { ...@@ -77,6 +78,7 @@ describe('given dashboard with repeated panels', function() {
info: {version: "1.1.0"} info: {version: "1.1.0"}
}; };
dash = new DashboardModel(dash, {});
var exporter = new DashboardExporter(datasourceSrvStub); var exporter = new DashboardExporter(datasourceSrvStub);
exporter.makeExportable(dash).then(clean => { exporter.makeExportable(dash).then(clean => {
exported = clean; exported = clean;
......
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
import _ from 'lodash';
import {DashboardRow} from '../row/row_model';
describe('DashboardRow', function() {
});
...@@ -9,7 +9,7 @@ function(angular, _) { ...@@ -9,7 +9,7 @@ function(angular, _) {
module.service('unsavedChangesSrv', function($rootScope, $q, $location, $timeout, contextSrv, $window) { module.service('unsavedChangesSrv', function($rootScope, $q, $location, $timeout, contextSrv, $window) {
function Tracker(dashboard, scope) { function Tracker(dashboard, scope, originalCopyDelay) {
var self = this; var self = this;
this.current = dashboard; this.current = dashboard;
...@@ -44,10 +44,14 @@ function(angular, _) { ...@@ -44,10 +44,14 @@ function(angular, _) {
} }
}); });
// wait for different services to patch the dashboard (missing properties) if (originalCopyDelay) {
$timeout(function() { $timeout(function() {
// wait for different services to patch the dashboard (missing properties)
self.original = dashboard.getSaveModelClone();
}, originalCopyDelay);
} else {
self.original = dashboard.getSaveModelClone(); self.original = dashboard.getSaveModelClone();
}, 1000); }
} }
var p = Tracker.prototype; var p = Tracker.prototype;
...@@ -157,7 +161,7 @@ function(angular, _) { ...@@ -157,7 +161,7 @@ function(angular, _) {
this.Tracker = Tracker; this.Tracker = Tracker;
this.init = function(dashboard, scope) { this.init = function(dashboard, scope) {
new Tracker(dashboard, scope); return new Tracker(dashboard, scope, 1000);
}; };
}); });
}); });
...@@ -143,7 +143,8 @@ module.directive('panelResizer', function($rootScope) { ...@@ -143,7 +143,8 @@ module.directive('panelResizer', function($rootScope) {
ctrl.panel.span = originalWidth + (((e.pageX - handleOffset.left) / maxWidth) * 12); ctrl.panel.span = originalWidth + (((e.pageX - handleOffset.left) / maxWidth) * 12);
ctrl.panel.span = Math.min(Math.max(ctrl.panel.span, 1), 12); ctrl.panel.span = Math.min(Math.max(ctrl.panel.span, 1), 12);
var rowSpan = ctrl.dashboard.rowSpan(ctrl.row); ctrl.row.updateRowSpan();
var rowSpan = ctrl.row.span;
// auto adjust other panels // auto adjust other panels
if (Math.floor(rowSpan) < 14) { if (Math.floor(rowSpan) < 14) {
...@@ -170,12 +171,6 @@ module.directive('panelResizer', function($rootScope) { ...@@ -170,12 +171,6 @@ module.directive('panelResizer', function($rootScope) {
lastPanel.span = Math.round(lastPanel.span); lastPanel.span = Math.round(lastPanel.span);
} }
// if close to 12
var rowSpan = ctrl.dashboard.rowSpan(ctrl.row);
if (rowSpan < 12 && rowSpan > 11) {
lastPanel.span += 12 - rowSpan;
}
ctrl.row.panelSpanChanged(); ctrl.row.panelSpanChanged();
// first digest to propagate panel width change // first digest to propagate panel width change
......
define([
'./helpers',
'app/features/dashboard/rowCtrl'
], function(helpers) {
'use strict';
describe('RowCtrl', function() {
var ctx = new helpers.ControllerTestContext();
beforeEach(module('grafana.controllers'));
beforeEach(ctx.providePhase());
beforeEach(ctx.createControllerPhase('RowCtrl'));
describe('delete_row', function () {
describe('when row is empty (has no panels)', function () {
beforeEach(function () {
ctx.scope.dashboard.rows = [{id: 1, panels: []}];
ctx.scope.row = ctx.scope.dashboard.rows[0];
ctx.scope.appEvent = sinon.spy();
ctx.scope.deleteRow();
});
it('should NOT ask for confirmation', function () {
expect(ctx.scope.appEvent.called).to.be(false);
});
it('should delete row', function () {
expect(ctx.scope.dashboard.rows).to.not.contain(ctx.scope.row);
});
});
});
});
});
...@@ -77,7 +77,8 @@ define([ ...@@ -77,7 +77,8 @@ define([
}); });
it('Should ignore row repeats', function() { it('Should ignore row repeats', function() {
dash.rows.push({repeatRowId: 10}); dash.addEmptyRow();
dash.rows[1].repeatRowId = 10;
expect(tracker.hasChanges()).to.be(false); expect(tracker.hasChanges()).to.be(false);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment