2019-01-22 21:36:36 +01:00
|
|
|
import { DashboardImportCtrl } from './DashboardImportCtrl';
|
|
|
|
|
import config from 'app/core/config';
|
2016-05-27 13:52:19 +02:00
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
describe('DashboardImportCtrl', () => {
|
2018-08-26 20:19:23 +02:00
|
|
|
const ctx: any = {};
|
2016-05-27 13:52:19 +02:00
|
|
|
|
2019-07-18 08:03:04 +02:00
|
|
|
let navModelSrv: any;
|
|
|
|
|
let backendSrv: any;
|
|
|
|
|
let validationSrv: any;
|
2016-05-27 13:52:19 +02:00
|
|
|
|
2017-12-04 16:51:37 +03:00
|
|
|
beforeEach(() => {
|
|
|
|
|
navModelSrv = {
|
2017-12-20 12:33:33 +01:00
|
|
|
getNav: () => {},
|
2017-12-04 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
backendSrv = {
|
|
|
|
|
search: jest.fn().mockReturnValue(Promise.resolve([])),
|
2018-05-28 22:19:14 +02:00
|
|
|
getDashboardByUid: jest.fn().mockReturnValue(Promise.resolve([])),
|
2017-12-20 12:33:33 +01:00
|
|
|
get: jest.fn(),
|
2017-12-04 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
|
2017-12-19 13:39:10 +01:00
|
|
|
validationSrv = {
|
2018-02-03 10:03:01 +01:00
|
|
|
validateNewDashboardName: jest.fn().mockReturnValue(Promise.resolve()),
|
2017-12-19 13:39:10 +01:00
|
|
|
};
|
|
|
|
|
|
2019-07-18 08:03:04 +02:00
|
|
|
ctx.ctrl = new DashboardImportCtrl(backendSrv, validationSrv, navModelSrv, {} as any, {} as any);
|
2017-12-04 16:51:37 +03:00
|
|
|
});
|
2016-05-27 13:52:19 +02:00
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
describe('when uploading json', () => {
|
|
|
|
|
beforeEach(() => {
|
2016-05-27 13:52:19 +02:00
|
|
|
config.datasources = {
|
|
|
|
|
ds: {
|
2017-12-20 12:33:33 +01:00
|
|
|
type: 'test-db',
|
2019-04-04 18:30:15 +02:00
|
|
|
} as any,
|
2016-05-27 13:52:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ctx.ctrl.onUpload({
|
2017-12-19 16:06:54 +01:00
|
|
|
__inputs: [
|
|
|
|
|
{
|
2017-12-20 12:33:33 +01:00
|
|
|
name: 'ds',
|
|
|
|
|
pluginId: 'test-db',
|
|
|
|
|
type: 'datasource',
|
|
|
|
|
pluginName: 'Test DB',
|
|
|
|
|
},
|
|
|
|
|
],
|
2016-05-27 13:52:19 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
it('should build input model', () => {
|
2017-12-04 16:51:37 +03:00
|
|
|
expect(ctx.ctrl.inputs.length).toBe(1);
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(ctx.ctrl.inputs[0].name).toBe('ds');
|
|
|
|
|
expect(ctx.ctrl.inputs[0].info).toBe('Select a Test DB data source');
|
2016-05-27 13:52:19 +02:00
|
|
|
});
|
|
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
it('should set inputValid to false', () => {
|
2017-12-04 16:51:37 +03:00
|
|
|
expect(ctx.ctrl.inputsValid).toBe(false);
|
2016-05-27 13:52:19 +02:00
|
|
|
});
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
|
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
describe('when specifying grafana.com url', () => {
|
|
|
|
|
beforeEach(() => {
|
2017-12-20 12:33:33 +01:00
|
|
|
ctx.ctrl.gnetUrl = 'http://grafana.com/dashboards/123';
|
2016-05-27 16:11:05 +02:00
|
|
|
// setup api mock
|
2017-12-04 16:51:37 +03:00
|
|
|
backendSrv.get = jest.fn(() => {
|
2016-05-27 16:11:05 +02:00
|
|
|
return Promise.resolve({
|
2017-12-20 12:33:33 +01:00
|
|
|
json: {},
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
|
|
|
|
});
|
2017-10-08 15:56:42 +02:00
|
|
|
return ctx.ctrl.checkGnetDashboard();
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
|
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
it('should call gnet api with correct dashboard id', () => {
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(backendSrv.get.mock.calls[0][0]).toBe('api/gnet/dashboards/123');
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
|
|
|
|
});
|
2016-05-27 13:52:19 +02:00
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
describe('when specifying dashboard id', () => {
|
|
|
|
|
beforeEach(() => {
|
2017-12-20 12:33:33 +01:00
|
|
|
ctx.ctrl.gnetUrl = '2342';
|
2016-05-27 16:11:05 +02:00
|
|
|
// setup api mock
|
2017-12-04 16:51:37 +03:00
|
|
|
backendSrv.get = jest.fn(() => {
|
2016-05-27 16:11:05 +02:00
|
|
|
return Promise.resolve({
|
2017-12-20 12:33:33 +01:00
|
|
|
json: {},
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
|
|
|
|
});
|
2017-10-08 15:56:42 +02:00
|
|
|
return ctx.ctrl.checkGnetDashboard();
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
|
|
|
|
|
2018-09-04 15:55:41 +02:00
|
|
|
it('should call gnet api with correct dashboard id', () => {
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(backendSrv.get.mock.calls[0][0]).toBe('api/gnet/dashboards/2342');
|
2016-05-27 16:11:05 +02:00
|
|
|
});
|
2016-05-27 13:52:19 +02:00
|
|
|
});
|
|
|
|
|
});
|