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