|
|
@@ -1,191 +1,194 @@
|
|
|
define([
|
|
|
+ 'helpers',
|
|
|
'features/dashboard/dashboardSrv'
|
|
|
-], function() {
|
|
|
+], function(helpers) {
|
|
|
'use strict';
|
|
|
|
|
|
- describe('when creating new dashboard with defaults only', function() {
|
|
|
- var model;
|
|
|
+ describe('dashboardSrv', function() {
|
|
|
+ var _dashboardSrv;
|
|
|
+ var contextSrv = new helpers.ContextSrvStub();
|
|
|
|
|
|
beforeEach(module('grafana.services'));
|
|
|
+ beforeEach(module(function($provide) {
|
|
|
+ $provide.value('contextSrv', contextSrv);
|
|
|
+ }));
|
|
|
+
|
|
|
beforeEach(inject(function(dashboardSrv) {
|
|
|
- model = dashboardSrv.create({});
|
|
|
+ _dashboardSrv = dashboardSrv;
|
|
|
}));
|
|
|
|
|
|
- it('should have title', function() {
|
|
|
- expect(model.title).to.be('No Title');
|
|
|
- });
|
|
|
+ describe('when creating new dashboard with defaults only', function() {
|
|
|
+ var model;
|
|
|
|
|
|
- it('should have default properties', function() {
|
|
|
- expect(model.rows.length).to.be(0);
|
|
|
- expect(model.nav.length).to.be(1);
|
|
|
- });
|
|
|
+ beforeEach(function() {
|
|
|
+ model = _dashboardSrv.create({}, {});
|
|
|
+ });
|
|
|
|
|
|
- });
|
|
|
+ it('should have title', function() {
|
|
|
+ expect(model.title).to.be('No Title');
|
|
|
+ });
|
|
|
|
|
|
- describe('when getting next panel id', function() {
|
|
|
- var model;
|
|
|
+ it('should have meta', function() {
|
|
|
+ expect(model.meta.canSave).to.be(false);
|
|
|
+ expect(model.meta.canShare).to.be(true);
|
|
|
+ });
|
|
|
|
|
|
- beforeEach(module('grafana.services'));
|
|
|
- beforeEach(inject(function(dashboardSrv) {
|
|
|
- model = dashboardSrv.create({
|
|
|
- rows: [{ panels: [{ id: 5 }]}]
|
|
|
+ it('should have default properties', function() {
|
|
|
+ expect(model.rows.length).to.be(0);
|
|
|
+ expect(model.nav.length).to.be(1);
|
|
|
});
|
|
|
- }));
|
|
|
|
|
|
- it('should return max id + 1', function() {
|
|
|
- expect(model.getNextPanelId()).to.be(6);
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
- describe('row and panel manipulation', function() {
|
|
|
- var dashboard;
|
|
|
+ describe('when getting next panel id', function() {
|
|
|
+ var model;
|
|
|
|
|
|
- beforeEach(module('grafana.services'));
|
|
|
- beforeEach(inject(function(dashboardSrv) {
|
|
|
- dashboard = dashboardSrv.create({});
|
|
|
- }));
|
|
|
+ beforeEach(function() {
|
|
|
+ model = _dashboardSrv.create({
|
|
|
+ rows: [{ panels: [{ id: 5 }]}]
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- it('row span should sum spans', function() {
|
|
|
- var spanLeft = dashboard.rowSpan({ panels: [{ span: 2 }, { span: 3 }] });
|
|
|
- expect(spanLeft).to.be(5);
|
|
|
+ it('should return max id + 1', function() {
|
|
|
+ expect(model.getNextPanelId()).to.be(6);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('adding default should split span in half', function() {
|
|
|
- dashboard.rows = [{ panels: [{ span: 12, id: 7 }] }];
|
|
|
- dashboard.add_panel({span: 4}, dashboard.rows[0]);
|
|
|
+ describe('row and panel manipulation', function() {
|
|
|
+ var dashboard;
|
|
|
|
|
|
- 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);
|
|
|
- });
|
|
|
+ beforeEach(function() {
|
|
|
+ dashboard = _dashboardSrv.create({});
|
|
|
+ });
|
|
|
|
|
|
- it('duplicate panel should try to add it to same row', function() {
|
|
|
- var panel = { span: 4, attr: '123', id: 10 };
|
|
|
- dashboard.rows = [{ panels: [panel] }];
|
|
|
- dashboard.duplicatePanel(panel, dashboard.rows[0]);
|
|
|
+ it('row span should sum spans', function() {
|
|
|
+ var spanLeft = dashboard.rowSpan({ panels: [{ span: 2 }, { span: 3 }] });
|
|
|
+ expect(spanLeft).to.be(5);
|
|
|
+ });
|
|
|
|
|
|
- expect(dashboard.rows[0].panels[0].span).to.be(4);
|
|
|
- expect(dashboard.rows[0].panels[1].span).to.be(4);
|
|
|
- expect(dashboard.rows[0].panels[1].attr).to.be('123');
|
|
|
- expect(dashboard.rows[0].panels[1].id).to.be(11);
|
|
|
- });
|
|
|
+ it('adding default should split span in half', function() {
|
|
|
+ dashboard.rows = [{ panels: [{ span: 12, id: 7 }] }];
|
|
|
+ dashboard.add_panel({span: 4}, dashboard.rows[0]);
|
|
|
|
|
|
- });
|
|
|
+ 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);
|
|
|
+ });
|
|
|
|
|
|
- describe('when creating dashboard with editable false', function() {
|
|
|
- var model;
|
|
|
+ it('duplicate panel should try to add it to same row', function() {
|
|
|
+ var panel = { span: 4, attr: '123', id: 10 };
|
|
|
+ dashboard.rows = [{ panels: [panel] }];
|
|
|
+ dashboard.duplicatePanel(panel, dashboard.rows[0]);
|
|
|
|
|
|
- beforeEach(module('grafana.services'));
|
|
|
- beforeEach(inject(function(dashboardSrv) {
|
|
|
- model = dashboardSrv.create({
|
|
|
- editable: false
|
|
|
+ expect(dashboard.rows[0].panels[0].span).to.be(4);
|
|
|
+ expect(dashboard.rows[0].panels[1].span).to.be(4);
|
|
|
+ expect(dashboard.rows[0].panels[1].attr).to.be('123');
|
|
|
+ expect(dashboard.rows[0].panels[1].id).to.be(11);
|
|
|
});
|
|
|
- }));
|
|
|
|
|
|
- it('should set editable false', function() {
|
|
|
- expect(model.editable).to.be(false);
|
|
|
});
|
|
|
|
|
|
- });
|
|
|
+ describe('when creating dashboard with editable false', function() {
|
|
|
+ var model;
|
|
|
|
|
|
- describe('when creating dashboard with old schema', function() {
|
|
|
- var model;
|
|
|
- var graph;
|
|
|
+ beforeEach(function() {
|
|
|
+ model = _dashboardSrv.create({
|
|
|
+ editable: false
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- beforeEach(module('grafana.services'));
|
|
|
- beforeEach(inject(function(dashboardSrv) {
|
|
|
- model = dashboardSrv.create({
|
|
|
- services: { filter: { time: { from: 'now-1d', to: 'now'}, list: [{}] }},
|
|
|
- pulldowns: [
|
|
|
- {
|
|
|
- type: 'filtering',
|
|
|
- enable: true
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'annotations',
|
|
|
- enable: true,
|
|
|
- annotations: [{name: 'old'}]
|
|
|
- }
|
|
|
- ],
|
|
|
- rows: [
|
|
|
- {
|
|
|
- panels: [
|
|
|
- {
|
|
|
- type: 'graphite',
|
|
|
- legend: true,
|
|
|
- aliasYAxis: { test: 2 },
|
|
|
- grid: { min: 1, max: 10 }
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
+ it('should set editable false', function() {
|
|
|
+ expect(model.editable).to.be(false);
|
|
|
});
|
|
|
|
|
|
- graph = model.rows[0].panels[0];
|
|
|
+ });
|
|
|
|
|
|
- }));
|
|
|
+ describe('when creating dashboard with old schema', function() {
|
|
|
+ var model;
|
|
|
+ var graph;
|
|
|
+
|
|
|
+ beforeEach(function() {
|
|
|
+ model = _dashboardSrv.create({
|
|
|
+ services: { filter: { time: { from: 'now-1d', to: 'now'}, list: [{}] }},
|
|
|
+ pulldowns: [
|
|
|
+ {type: 'filtering', enable: true},
|
|
|
+ {type: 'annotations', enable: true, annotations: [{name: 'old'}]}
|
|
|
+ ],
|
|
|
+ rows: [
|
|
|
+ {
|
|
|
+ panels: [
|
|
|
+ {type: 'graphite', legend: true, aliasYAxis: { test: 2 }, grid: { min: 1, max: 10 }}
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+
|
|
|
+ graph = model.rows[0].panels[0];
|
|
|
+ });
|
|
|
|
|
|
- it('should have title', function() {
|
|
|
- expect(model.title).to.be('No Title');
|
|
|
- });
|
|
|
+ it('should have title', function() {
|
|
|
+ expect(model.title).to.be('No Title');
|
|
|
+ });
|
|
|
|
|
|
- it('should have panel id', function() {
|
|
|
- expect(graph.id).to.be(1);
|
|
|
- });
|
|
|
+ it('should have panel id', function() {
|
|
|
+ expect(graph.id).to.be(1);
|
|
|
+ });
|
|
|
|
|
|
- it('should move time and filtering list', function() {
|
|
|
- expect(model.time.from).to.be('now-1d');
|
|
|
- expect(model.templating.list[0].allFormat).to.be('glob');
|
|
|
- });
|
|
|
+ it('should move time and filtering list', function() {
|
|
|
+ expect(model.time.from).to.be('now-1d');
|
|
|
+ expect(model.templating.list[0].allFormat).to.be('glob');
|
|
|
+ });
|
|
|
|
|
|
- it('graphite panel should change name too graph', function() {
|
|
|
- expect(graph.type).to.be('graph');
|
|
|
- });
|
|
|
+ it('graphite panel should change name too graph', function() {
|
|
|
+ expect(graph.type).to.be('graph');
|
|
|
+ });
|
|
|
|
|
|
- it('update legend setting', function() {
|
|
|
- expect(graph.legend.show).to.be(true);
|
|
|
- });
|
|
|
+ it('update legend setting', function() {
|
|
|
+ expect(graph.legend.show).to.be(true);
|
|
|
+ });
|
|
|
|
|
|
- it('update grid options', function() {
|
|
|
- expect(graph.grid.leftMin).to.be(1);
|
|
|
- expect(graph.grid.leftMax).to.be(10);
|
|
|
- });
|
|
|
+ it('update grid options', function() {
|
|
|
+ expect(graph.grid.leftMin).to.be(1);
|
|
|
+ expect(graph.grid.leftMax).to.be(10);
|
|
|
+ });
|
|
|
|
|
|
- it('move aliasYAxis to series override', function() {
|
|
|
- expect(graph.seriesOverrides[0].alias).to.be("test");
|
|
|
- expect(graph.seriesOverrides[0].yaxis).to.be(2);
|
|
|
- });
|
|
|
+ it('move aliasYAxis to series override', function() {
|
|
|
+ expect(graph.seriesOverrides[0].alias).to.be("test");
|
|
|
+ expect(graph.seriesOverrides[0].yaxis).to.be(2);
|
|
|
+ });
|
|
|
|
|
|
- it('should move pulldowns to new schema', function() {
|
|
|
- expect(model.annotations.list[0].name).to.be('old');
|
|
|
- });
|
|
|
+ it('should move pulldowns to new schema', function() {
|
|
|
+ expect(model.annotations.list[0].name).to.be('old');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('dashboard schema version should be set to latest', function() {
|
|
|
+ expect(model.schemaVersion).to.be(6);
|
|
|
+ });
|
|
|
|
|
|
- it('dashboard schema version should be set to latest', function() {
|
|
|
- expect(model.schemaVersion).to.be(6);
|
|
|
});
|
|
|
|
|
|
- });
|
|
|
+ describe('when creating dashboard model with missing list for annoations or templating', function() {
|
|
|
+ var model;
|
|
|
|
|
|
- describe('when creating dashboard model with missing list for annoations or templating', function() {
|
|
|
- var model;
|
|
|
+ beforeEach(function() {
|
|
|
+ model = _dashboardSrv.create({
|
|
|
+ annotations: {
|
|
|
+ enable: true,
|
|
|
+ },
|
|
|
+ templating: {
|
|
|
+ enable: true
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- beforeEach(module('grafana.services'));
|
|
|
- beforeEach(inject(function(dashboardSrv) {
|
|
|
- model = dashboardSrv.create({
|
|
|
- annotations: {
|
|
|
- enable: true,
|
|
|
- },
|
|
|
- templating: {
|
|
|
- enable: true
|
|
|
- }
|
|
|
+ it('should add empty list', function() {
|
|
|
+ expect(model.annotations.list.length).to.be(0);
|
|
|
+ expect(model.templating.list.length).to.be(0);
|
|
|
});
|
|
|
- }));
|
|
|
|
|
|
- it('should add empty list', function() {
|
|
|
- expect(model.annotations.list.length).to.be(0);
|
|
|
- expect(model.templating.list.length).to.be(0);
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
+
|
|
|
});
|