grafana/public/app/features/manage-dashboards/DashboardImportCtrl.test.ts
Torkel Ödegaard 47e51cb6b3
Refactor: Plugin exports & data source / panel types (#16364)
* wip: began work off removing meta and pluginExports from DataSourceApi interface

* WIP: changing how plugins are exports and loaded

* Down the refactoring rabit hole that keeps expanding

* TestData now returns DataSourcePlugin

* Refactoring: fixed app config page loading, type renamings and more typings

* Refactor: Correct casing on DatasourceStatus => DataSourceStatus
2019-04-04 18:30:15 +02:00

94 lines
2.3 KiB
TypeScript

import { DashboardImportCtrl } from './DashboardImportCtrl';
import config from 'app/core/config';
describe('DashboardImportCtrl', () => {
const ctx: any = {};
let navModelSrv;
let backendSrv;
let validationSrv;
beforeEach(() => {
navModelSrv = {
getNav: () => {},
};
backendSrv = {
search: jest.fn().mockReturnValue(Promise.resolve([])),
getDashboardByUid: jest.fn().mockReturnValue(Promise.resolve([])),
get: jest.fn(),
};
validationSrv = {
validateNewDashboardName: jest.fn().mockReturnValue(Promise.resolve()),
};
ctx.ctrl = new DashboardImportCtrl(backendSrv, validationSrv, navModelSrv, {}, {});
});
describe('when uploading json', () => {
beforeEach(() => {
config.datasources = {
ds: {
type: 'test-db',
} as any,
};
ctx.ctrl.onUpload({
__inputs: [
{
name: 'ds',
pluginId: 'test-db',
type: 'datasource',
pluginName: 'Test DB',
},
],
});
});
it('should build input model', () => {
expect(ctx.ctrl.inputs.length).toBe(1);
expect(ctx.ctrl.inputs[0].name).toBe('ds');
expect(ctx.ctrl.inputs[0].info).toBe('Select a Test DB data source');
});
it('should set inputValid to false', () => {
expect(ctx.ctrl.inputsValid).toBe(false);
});
});
describe('when specifying grafana.com url', () => {
beforeEach(() => {
ctx.ctrl.gnetUrl = 'http://grafana.com/dashboards/123';
// setup api mock
backendSrv.get = jest.fn(() => {
return Promise.resolve({
json: {},
});
});
return ctx.ctrl.checkGnetDashboard();
});
it('should call gnet api with correct dashboard id', () => {
expect(backendSrv.get.mock.calls[0][0]).toBe('api/gnet/dashboards/123');
});
});
describe('when specifying dashboard id', () => {
beforeEach(() => {
ctx.ctrl.gnetUrl = '2342';
// setup api mock
backendSrv.get = jest.fn(() => {
return Promise.resolve({
json: {},
});
});
return ctx.ctrl.checkGnetDashboard();
});
it('should call gnet api with correct dashboard id', () => {
expect(backendSrv.get.mock.calls[0][0]).toBe('api/gnet/dashboards/2342');
});
});
});