2017-12-19 09:06:54 -06:00
|
|
|
import _ from "lodash";
|
|
|
|
import { DashboardModel } from "../dashboard_model";
|
|
|
|
import { PanelModel } from "../panel_model";
|
2017-01-06 03:03:17 -06:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
jest.mock("app/core/services/context_srv", () => ({}));
|
2017-10-24 05:33:14 -05:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("DashboardModel", function() {
|
|
|
|
describe("when creating new dashboard model defaults only", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({}, {});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should have title", function() {
|
|
|
|
expect(model.title).toBe("No Title");
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should have meta", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.meta.canSave).toBe(true);
|
|
|
|
expect(model.meta.canShare).toBe(true);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should have default properties", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.panels.length).toBe(0);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("when getting next panel id", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({
|
2017-12-19 09:06:54 -06:00
|
|
|
panels: [{ id: 5 }]
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should return max id + 1", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.getNextPanelId()).toBe(6);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("getSaveModelClone", function() {
|
|
|
|
it("should sort keys", () => {
|
2017-01-06 03:03:17 -06:00
|
|
|
var model = new DashboardModel({});
|
|
|
|
var saveModel = model.getSaveModelClone();
|
|
|
|
var keys = _.keys(saveModel);
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
expect(keys[0]).toBe("annotations");
|
|
|
|
expect(keys[1]).toBe("autoUpdate");
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("row and panel manipulation", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var dashboard;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
dashboard = new DashboardModel({});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("adding panel should new up panel model", function() {
|
|
|
|
dashboard.addPanel({ type: "test", title: "test" });
|
2017-01-06 03:03:17 -06:00
|
|
|
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(dashboard.panels[0] instanceof PanelModel).toBe(true);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("duplicate panel should try to add to the right if there is space", function() {
|
2017-10-25 05:37:34 -05:00
|
|
|
var panel = { id: 10, gridPos: { x: 0, y: 0, w: 6, h: 2 } };
|
2017-01-06 03:03:17 -06:00
|
|
|
|
2017-10-12 12:01:02 -05:00
|
|
|
dashboard.addPanel(panel);
|
|
|
|
dashboard.duplicatePanel(dashboard.panels[0]);
|
2017-01-06 03:03:17 -06:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
expect(dashboard.panels[1].gridPos).toMatchObject({
|
|
|
|
x: 6,
|
|
|
|
y: 0,
|
|
|
|
h: 2,
|
|
|
|
w: 6
|
|
|
|
});
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("duplicate panel should remove repeat data", function() {
|
|
|
|
var panel = {
|
|
|
|
id: 10,
|
|
|
|
gridPos: { x: 0, y: 0, w: 6, h: 2 },
|
|
|
|
repeat: "asd",
|
|
|
|
scopedVars: { test: "asd" }
|
|
|
|
};
|
2017-01-06 03:03:17 -06:00
|
|
|
|
2017-10-12 12:01:02 -05:00
|
|
|
dashboard.addPanel(panel);
|
|
|
|
dashboard.duplicatePanel(dashboard.panels[0]);
|
2017-01-06 03:03:17 -06:00
|
|
|
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(dashboard.panels[1].repeat).toBe(undefined);
|
|
|
|
expect(dashboard.panels[1].scopedVars).toBe(undefined);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("Given editable false dashboard", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2017-10-25 05:37:34 -05:00
|
|
|
model = new DashboardModel({ editable: false });
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("Should set meta canEdit and canSave to false", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.meta.canSave).toBe(false);
|
|
|
|
expect(model.meta.canEdit).toBe(false);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("getSaveModelClone should remove meta", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var clone = model.getSaveModelClone();
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(clone.meta).toBe(undefined);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("when loading dashboard with old influxdb query schema", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var model;
|
|
|
|
var target;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({
|
2017-10-25 05:37:34 -05:00
|
|
|
panels: [
|
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
type: "graph",
|
2017-10-25 05:37:34 -05:00
|
|
|
grid: {},
|
|
|
|
yaxes: [{}, {}],
|
|
|
|
targets: [
|
2017-10-12 05:01:13 -05:00
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
alias: "$tag_datacenter $tag_source $col",
|
|
|
|
column: "value",
|
|
|
|
measurement: "logins.count",
|
2017-10-25 05:37:34 -05:00
|
|
|
fields: [
|
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
func: "mean",
|
|
|
|
name: "value",
|
|
|
|
mathExpr: "*2",
|
|
|
|
asExpr: "value"
|
2017-10-25 05:37:34 -05:00
|
|
|
},
|
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
name: "one-minute",
|
|
|
|
func: "mean",
|
|
|
|
mathExpr: "*3",
|
|
|
|
asExpr: "one-minute"
|
|
|
|
}
|
2017-10-25 05:37:34 -05:00
|
|
|
],
|
|
|
|
tags: [],
|
2017-12-19 09:06:54 -06:00
|
|
|
fill: "previous",
|
|
|
|
function: "mean",
|
2017-10-25 05:37:34 -05:00
|
|
|
groupBy: [
|
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
interval: "auto",
|
|
|
|
type: "time"
|
2017-10-25 05:37:34 -05:00
|
|
|
},
|
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
key: "source",
|
|
|
|
type: "tag"
|
2017-10-25 05:37:34 -05:00
|
|
|
},
|
|
|
|
{
|
2017-12-19 09:06:54 -06:00
|
|
|
type: "tag",
|
|
|
|
key: "datacenter"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-10-12 05:01:13 -05:00
|
|
|
target = model.panels[0].targets[0];
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should update query schema", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(target.fields).toBe(undefined);
|
|
|
|
expect(target.select.length).toBe(2);
|
|
|
|
expect(target.select[0].length).toBe(4);
|
2017-12-19 09:06:54 -06:00
|
|
|
expect(target.select[0][0].type).toBe("field");
|
|
|
|
expect(target.select[0][1].type).toBe("mean");
|
|
|
|
expect(target.select[0][2].type).toBe("math");
|
|
|
|
expect(target.select[0][3].type).toBe("alias");
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("when creating dashboard model with missing list for annoations or templating", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({
|
|
|
|
annotations: {
|
2017-12-19 09:06:54 -06:00
|
|
|
enable: true
|
2017-01-06 03:03:17 -06:00
|
|
|
},
|
|
|
|
templating: {
|
2017-12-19 09:06:54 -06:00
|
|
|
enable: true
|
|
|
|
}
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should add empty list", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.annotations.list.length).toBe(1);
|
|
|
|
expect(model.templating.list.length).toBe(0);
|
2017-10-07 03:31:39 -05:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should add builtin annotation query", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.annotations.list[0].builtIn).toBe(1);
|
|
|
|
expect(model.templating.list.length).toBe(0);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("Formatting epoch timestamp when timezone is set as utc", function() {
|
2017-01-06 03:03:17 -06:00
|
|
|
var dashboard;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2017-12-19 09:06:54 -06:00
|
|
|
dashboard = new DashboardModel({ timezone: "utc" });
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("Should format timestamp with second resolution by default", function() {
|
|
|
|
expect(dashboard.formatDate(1234567890000)).toBe("2009-02-13 23:31:30");
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("Should format timestamp with second resolution even if second format is passed as parameter", function() {
|
|
|
|
expect(dashboard.formatDate(1234567890007, "YYYY-MM-DD HH:mm:ss")).toBe(
|
|
|
|
"2009-02-13 23:31:30"
|
|
|
|
);
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("Should format timestamp with millisecond resolution if format is passed as parameter", function() {
|
|
|
|
expect(
|
|
|
|
dashboard.formatDate(1234567890007, "YYYY-MM-DD HH:mm:ss.SSS")
|
|
|
|
).toBe("2009-02-13 23:31:30.007");
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("updateSubmenuVisibility with empty lists", function() {
|
2017-04-12 08:01:17 -05:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({});
|
|
|
|
model.updateSubmenuVisibility();
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should not enable submmenu", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.meta.submenuEnabled).toBe(false);
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("updateSubmenuVisibility with annotation", function() {
|
2017-04-12 08:01:17 -05:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({
|
|
|
|
annotations: {
|
2017-12-19 09:06:54 -06:00
|
|
|
list: [{}]
|
|
|
|
}
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
model.updateSubmenuVisibility();
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should enable submmenu", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.meta.submenuEnabled).toBe(true);
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("updateSubmenuVisibility with template var", function() {
|
2017-04-12 08:01:17 -05:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({
|
|
|
|
templating: {
|
2017-12-19 09:06:54 -06:00
|
|
|
list: [{}]
|
|
|
|
}
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
model.updateSubmenuVisibility();
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should enable submmenu", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.meta.submenuEnabled).toBe(true);
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("updateSubmenuVisibility with hidden template var", function() {
|
2017-04-12 08:01:17 -05:00
|
|
|
var model;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
model = new DashboardModel({
|
|
|
|
templating: {
|
2017-12-19 09:06:54 -06:00
|
|
|
list: [{ hide: 2 }]
|
|
|
|
}
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
model.updateSubmenuVisibility();
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should not enable submmenu", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(model.meta.submenuEnabled).toBe(false);
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("updateSubmenuVisibility with hidden annotation toggle", function() {
|
2017-10-13 06:51:05 -05:00
|
|
|
var dashboard;
|
2017-04-12 08:01:17 -05:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2017-10-13 06:51:05 -05:00
|
|
|
dashboard = new DashboardModel({
|
2017-04-12 08:01:17 -05:00
|
|
|
annotations: {
|
2017-12-19 09:06:54 -06:00
|
|
|
list: [{ hide: true }]
|
|
|
|
}
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
2017-10-13 06:51:05 -05:00
|
|
|
dashboard.updateSubmenuVisibility();
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should not enable submmenu", function() {
|
2017-10-24 03:47:24 -05:00
|
|
|
expect(dashboard.meta.submenuEnabled).toBe(false);
|
2017-04-12 08:01:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("When collapsing row", function() {
|
2017-10-16 09:09:23 -05:00
|
|
|
var dashboard;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
dashboard = new DashboardModel({
|
|
|
|
panels: [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, type: "graph", gridPos: { x: 0, y: 0, w: 24, h: 2 } },
|
|
|
|
{ id: 2, type: "row", gridPos: { x: 0, y: 2, w: 24, h: 2 } },
|
|
|
|
{ id: 3, type: "graph", gridPos: { x: 0, y: 4, w: 12, h: 2 } },
|
|
|
|
{ id: 4, type: "graph", gridPos: { x: 12, y: 4, w: 12, h: 2 } },
|
|
|
|
{ id: 5, type: "row", gridPos: { x: 0, y: 6, w: 24, h: 2 } }
|
|
|
|
]
|
2017-10-16 09:09:23 -05:00
|
|
|
});
|
|
|
|
dashboard.toggleRow(dashboard.panels[1]);
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should remove panels and put them inside collapsed row", function() {
|
2017-10-24 05:33:14 -05:00
|
|
|
expect(dashboard.panels.length).toBe(3);
|
|
|
|
expect(dashboard.panels[1].panels.length).toBe(2);
|
2017-10-16 09:09:23 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
describe("When expanding row", function() {
|
2017-10-17 07:53:52 -05:00
|
|
|
var dashboard;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
dashboard = new DashboardModel({
|
|
|
|
panels: [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 1, type: "graph", gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
2017-10-17 07:53:52 -05:00
|
|
|
{
|
|
|
|
id: 2,
|
2017-12-19 09:06:54 -06:00
|
|
|
type: "row",
|
2017-10-25 05:37:34 -05:00
|
|
|
gridPos: { x: 0, y: 6, w: 24, h: 2 },
|
2017-10-17 07:53:52 -05:00
|
|
|
collapsed: true,
|
|
|
|
panels: [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 3, type: "graph", gridPos: { x: 0, y: 2, w: 12, h: 2 } },
|
|
|
|
{ id: 4, type: "graph", gridPos: { x: 12, y: 2, w: 12, h: 2 } }
|
|
|
|
]
|
2017-10-17 07:53:52 -05:00
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
{ id: 5, type: "graph", gridPos: { x: 0, y: 6, w: 1, h: 1 } }
|
|
|
|
]
|
2017-10-17 07:53:52 -05:00
|
|
|
});
|
|
|
|
dashboard.toggleRow(dashboard.panels[1]);
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should add panels back", function() {
|
2017-10-24 05:33:14 -05:00
|
|
|
expect(dashboard.panels.length).toBe(5);
|
2017-10-17 07:53:52 -05:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should add them below row in array", function() {
|
2017-10-24 05:33:14 -05:00
|
|
|
expect(dashboard.panels[2].id).toBe(3);
|
|
|
|
expect(dashboard.panels[3].id).toBe(4);
|
2017-10-17 07:53:52 -05:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should position them below row", function() {
|
|
|
|
expect(dashboard.panels[2].gridPos).toMatchObject({
|
|
|
|
x: 0,
|
|
|
|
y: 8,
|
|
|
|
w: 12,
|
|
|
|
h: 2
|
|
|
|
});
|
2017-10-17 07:53:52 -05:00
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
it("should move panels below down", function() {
|
|
|
|
expect(dashboard.panels[4].gridPos).toMatchObject({
|
|
|
|
x: 0,
|
|
|
|
y: 10,
|
|
|
|
w: 1,
|
|
|
|
h: 1
|
|
|
|
});
|
2017-10-24 05:33:14 -05:00
|
|
|
});
|
2017-10-17 07:53:52 -05:00
|
|
|
});
|
2017-01-06 03:03:17 -06:00
|
|
|
});
|