Commit 94b8cbdc by Tobias Skarhed

Karma to Jest: exporter

parent ff3db60e
import { describe, beforeEach, it, sinon, expect } from 'test/lib/common';
jest.mock('app/core/store', () => {
return {
getBool: jest.fn(),
};
});
import _ from 'lodash';
import config from 'app/core/config';
import { DashboardExporter } from '../export/exporter';
import { DashboardModel } from '../dashboard_model';
describe('given dashboard with repeated panels', function() {
describe('given dashboard with repeated panels', () => {
var dash, exported;
beforeEach(done => {
......@@ -65,41 +69,43 @@ describe('given dashboard with repeated panels', function() {
});
dash.panels.push({ id: 3, repeat: null, repeatPanelId: 2 });
var datasourceSrvStub = { get: sinon.stub() };
datasourceSrvStub.get.withArgs('gfdb').returns(
Promise.resolve({
name: 'gfdb',
meta: { id: 'testdb', info: { version: '1.2.1' }, name: 'TestDB' },
})
);
datasourceSrvStub.get.withArgs('other').returns(
Promise.resolve({
name: 'other',
meta: { id: 'other', info: { version: '1.2.1' }, name: 'OtherDB' },
})
);
datasourceSrvStub.get.withArgs('-- Mixed --').returns(
Promise.resolve({
name: 'mixed',
meta: {
id: 'mixed',
info: { version: '1.2.1' },
name: 'Mixed',
builtIn: true,
},
})
);
datasourceSrvStub.get.withArgs('-- Grafana --').returns(
Promise.resolve({
name: '-- Grafana --',
meta: {
id: 'grafana',
info: { version: '1.2.1' },
name: 'grafana',
builtIn: true,
},
})
);
//Mock test function calls
var datasourceSrvStub = {
get: jest.fn(arg => {
if (arg === 'gfdb') {
return Promise.resolve({
name: 'gfdb',
meta: { id: 'testdb', info: { version: '1.2.1' }, name: 'TestDB' },
});
} else if (arg === 'other') {
return Promise.resolve({
name: 'other',
meta: { id: 'other', info: { version: '1.2.1' }, name: 'OtherDB' },
});
} else if (arg === '-- Mixed --') {
return Promise.resolve({
name: 'mixed',
meta: {
id: 'mixed',
info: { version: '1.2.1' },
name: 'Mixed',
builtIn: true,
},
});
} else if (arg === '-- Grafana --') {
return Promise.resolve({
name: '-- Grafana --',
meta: {
id: 'grafana',
info: { version: '1.2.1' },
name: 'grafana',
builtIn: true,
},
});
}
return 0;
}),
};
config.panels['graph'] = {
id: 'graph',
......@@ -115,73 +121,73 @@ describe('given dashboard with repeated panels', function() {
});
});
it('should replace datasource refs', function() {
it('should replace datasource refs', () => {
var panel = exported.panels[0];
expect(panel.datasource).to.be('${DS_GFDB}');
expect(panel.datasource).toBe('${DS_GFDB}');
});
it('should replace datasource in variable query', function() {
expect(exported.templating.list[0].datasource).to.be('${DS_GFDB}');
expect(exported.templating.list[0].options.length).to.be(0);
expect(exported.templating.list[0].current.value).to.be(undefined);
expect(exported.templating.list[0].current.text).to.be(undefined);
it('should replace datasource in variable query', () => {
expect(exported.templating.list[0].datasource).toBe('${DS_GFDB}');
expect(exported.templating.list[0].options.length).toBe(0);
expect(exported.templating.list[0].current.value).toBe(undefined);
expect(exported.templating.list[0].current.text).toBe(undefined);
});
it('should replace datasource in annotation query', function() {
expect(exported.annotations.list[1].datasource).to.be('${DS_GFDB}');
it('should replace datasource in annotation query', () => {
expect(exported.annotations.list[1].datasource).toBe('${DS_GFDB}');
});
it('should add datasource as input', function() {
expect(exported.__inputs[0].name).to.be('DS_GFDB');
expect(exported.__inputs[0].pluginId).to.be('testdb');
expect(exported.__inputs[0].type).to.be('datasource');
it('should add datasource as input', () => {
expect(exported.__inputs[0].name).toBe('DS_GFDB');
expect(exported.__inputs[0].pluginId).toBe('testdb');
expect(exported.__inputs[0].type).toBe('datasource');
});
it('should add datasource to required', function() {
it('should add datasource to required', () => {
var require = _.find(exported.__requires, { name: 'TestDB' });
expect(require.name).to.be('TestDB');
expect(require.id).to.be('testdb');
expect(require.type).to.be('datasource');
expect(require.version).to.be('1.2.1');
expect(require.name).toBe('TestDB');
expect(require.id).toBe('testdb');
expect(require.type).toBe('datasource');
expect(require.version).toBe('1.2.1');
});
it('should not add built in datasources to required', function() {
it('should not add built in datasources to required', () => {
var require = _.find(exported.__requires, { name: 'Mixed' });
expect(require).to.be(undefined);
expect(require).toBe(undefined);
});
it('should add datasources used in mixed mode', function() {
it('should add datasources used in mixed mode', () => {
var require = _.find(exported.__requires, { name: 'OtherDB' });
expect(require).to.not.be(undefined);
expect(require).not.toBe(undefined);
});
it('should add panel to required', function() {
it('should add panel to required', () => {
var require = _.find(exported.__requires, { name: 'Graph' });
expect(require.name).to.be('Graph');
expect(require.id).to.be('graph');
expect(require.version).to.be('1.1.0');
expect(require.name).toBe('Graph');
expect(require.id).toBe('graph');
expect(require.version).toBe('1.1.0');
});
it('should add grafana version', function() {
it('should add grafana version', () => {
var require = _.find(exported.__requires, { name: 'Grafana' });
expect(require.type).to.be('grafana');
expect(require.id).to.be('grafana');
expect(require.version).to.be('3.0.2');
expect(require.type).toBe('grafana');
expect(require.id).toBe('grafana');
expect(require.version).toBe('3.0.2');
});
it('should add constant template variables as inputs', function() {
it('should add constant template variables as inputs', () => {
var input = _.find(exported.__inputs, { name: 'VAR_PREFIX' });
expect(input.type).to.be('constant');
expect(input.label).to.be('prefix');
expect(input.value).to.be('collectd');
expect(input.type).toBe('constant');
expect(input.label).toBe('prefix');
expect(input.value).toBe('collectd');
});
it('should templatize constant variables', function() {
it('should templatize constant variables', () => {
var variable = _.find(exported.templating.list, { name: 'prefix' });
expect(variable.query).to.be('${VAR_PREFIX}');
expect(variable.current.text).to.be('${VAR_PREFIX}');
expect(variable.current.value).to.be('${VAR_PREFIX}');
expect(variable.options[0].text).to.be('${VAR_PREFIX}');
expect(variable.options[0].value).to.be('${VAR_PREFIX}');
expect(variable.query).toBe('${VAR_PREFIX}');
expect(variable.current.text).toBe('${VAR_PREFIX}');
expect(variable.current.value).toBe('${VAR_PREFIX}');
expect(variable.options[0].text).toBe('${VAR_PREFIX}');
expect(variable.options[0].value).toBe('${VAR_PREFIX}');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment