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 {
return null;
}
rowSpan(row) {
return _.reduce(row.panels, function(p,v) {
return p + v.span;
},0);
};
addPanel(panel, row) {
panel.id = this.getNextPanelId();
row.addPanel(panel);
......@@ -540,6 +534,7 @@ export class DashboardModel {
// update graph yaxes changes
panelUpgrades.push(function(panel) {
if (panel.type !== 'graph') { return; }
if (!panel.grid) { return; }
panel.thresholds = [];
var t1: any = {}, t2: any = {};
......
......@@ -81,13 +81,13 @@ export class AddPanelCtrl {
addPanel(panelPluginInfo) {
var defaultSpan = 12;
var _as = 12 - this.dashboard.rowSpan(this.row);
var span = 12 - this.row.span;
var panel = {
id: null,
title: config.new_panel_title,
error: false,
span: _as < defaultSpan && _as > 0 ? _as : defaultSpan,
span: span < defaultSpan && span > 0 ? span : defaultSpan,
editable: true,
type: panelPluginInfo.id,
isNew: true,
......
......@@ -198,7 +198,7 @@ coreModule.directive('panelDropZone', function($timeout) {
return showPanel(12, 'Empty Space');
}
var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row);
var dropZoneSpan = 12 - row.span;
if (dropZoneSpan > 0) {
if (indrag) {
return showPanel(dropZoneSpan, 'Drop Here');
......@@ -209,7 +209,7 @@ coreModule.directive('panelDropZone', function($timeout) {
}
if (indrag === true) {
var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row);
var dropZoneSpan = 12 - row.span;
if (dropZoneSpan > 1) {
return showPanel(dropZoneSpan, 'Drop Here');
}
......
......@@ -51,18 +51,13 @@ describe('dashboardSrv', function() {
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() {
dashboard.rows = [{ panels: [{ span: 12, id: 7 }] }];
dashboard.addPanel({span: 4}, dashboard.rows[0]);
dashboard.addEmptyRow();
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[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() {
......
......@@ -3,6 +3,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co
import _ from 'lodash';
import config from 'app/core/config';
import {DashboardExporter} from '../export/exporter';
import {DashboardModel} from '../model';
describe('given dashboard with repeated panels', function() {
var dash, exported;
......@@ -77,6 +78,7 @@ describe('given dashboard with repeated panels', function() {
info: {version: "1.1.0"}
};
dash = new DashboardModel(dash, {});
var exporter = new DashboardExporter(datasourceSrvStub);
exporter.makeExportable(dash).then(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, _) {
module.service('unsavedChangesSrv', function($rootScope, $q, $location, $timeout, contextSrv, $window) {
function Tracker(dashboard, scope) {
function Tracker(dashboard, scope, originalCopyDelay) {
var self = this;
this.current = dashboard;
......@@ -44,10 +44,14 @@ function(angular, _) {
}
});
// wait for different services to patch the dashboard (missing properties)
$timeout(function() {
if (originalCopyDelay) {
$timeout(function() {
// wait for different services to patch the dashboard (missing properties)
self.original = dashboard.getSaveModelClone();
}, originalCopyDelay);
} else {
self.original = dashboard.getSaveModelClone();
}, 1000);
}
}
var p = Tracker.prototype;
......@@ -157,7 +161,7 @@ function(angular, _) {
this.Tracker = Tracker;
this.init = function(dashboard, scope) {
new Tracker(dashboard, scope);
return new Tracker(dashboard, scope, 1000);
};
});
});
......@@ -143,7 +143,8 @@ module.directive('panelResizer', function($rootScope) {
ctrl.panel.span = originalWidth + (((e.pageX - handleOffset.left) / maxWidth) * 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
if (Math.floor(rowSpan) < 14) {
......@@ -170,12 +171,6 @@ module.directive('panelResizer', function($rootScope) {
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();
// 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([
});
it('Should ignore row repeats', function() {
dash.rows.push({repeatRowId: 10});
dash.addEmptyRow();
dash.rows[1].repeatRowId = 10;
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