Files
grafana/public/app/features/dashboard/specs/save_as_modal.test.ts

68 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-12-20 12:33:33 +01:00
import { SaveDashboardAsModalCtrl } from '../save_as_modal';
import { describe, it, expect } from 'test/lib/common';
2017-12-20 12:33:33 +01:00
describe('saving dashboard as', () => {
2017-11-17 16:18:30 +01:00
function scenario(name, panel, verify) {
describe(name, () => {
const json = {
2017-12-20 12:33:33 +01:00
title: 'name',
panels: [panel],
2017-11-17 16:18:30 +01:00
};
const mockDashboardSrv = {
getCurrent: () => {
2017-11-17 16:18:30 +01:00
return {
id: 5,
meta: {},
getSaveModelClone: () => {
2017-11-17 16:18:30 +01:00
return json;
2017-12-20 12:33:33 +01:00
},
2017-11-17 16:18:30 +01:00
};
2017-12-20 12:33:33 +01:00
},
2017-11-17 16:18:30 +01:00
};
const ctrl = new SaveDashboardAsModalCtrl(mockDashboardSrv);
const ctx: any = {
2017-11-17 16:18:30 +01:00
clone: ctrl.clone,
ctrl: ctrl,
2017-12-20 12:33:33 +01:00
panel: panel,
2017-11-17 16:18:30 +01:00
};
2017-12-20 12:33:33 +01:00
it('verify', () => {
2017-11-17 16:18:30 +01:00
verify(ctx);
});
});
2017-11-17 16:18:30 +01:00
}
2017-12-20 12:33:33 +01:00
scenario('default values', {}, ctx => {
const clone = ctx.clone;
2017-11-17 16:18:30 +01:00
expect(clone.id).toBe(null);
2017-12-20 12:33:33 +01:00
expect(clone.title).toBe('name Copy');
2017-11-17 16:18:30 +01:00
expect(clone.editable).toBe(true);
expect(clone.hideControls).toBe(false);
});
const graphPanel = {
id: 1,
2017-12-20 12:33:33 +01:00
type: 'graph',
alert: { rule: 1 },
2017-12-20 12:33:33 +01:00
thresholds: { value: 3000 },
};
2017-12-20 12:33:33 +01:00
scenario('should remove alert from graph panel', graphPanel, ctx => {
2017-11-17 16:18:30 +01:00
expect(ctx.panel.alert).toBe(undefined);
});
2017-12-20 12:33:33 +01:00
scenario('should remove threshold from graph panel', graphPanel, ctx => {
2017-11-17 16:18:30 +01:00
expect(ctx.panel.thresholds).toBe(undefined);
});
scenario('singlestat should keep threshold', { id: 1, type: 'singlestat', thresholds: { value: 3000 } }, ctx => {
expect(ctx.panel.thresholds).not.toBe(undefined);
});
2017-11-17 16:18:30 +01:00
scenario('table should keep threshold', { id: 1, type: 'table', thresholds: { value: 3000 } }, ctx => {
expect(ctx.panel.thresholds).not.toBe(undefined);
});
});