fix tests

This commit is contained in:
Alexander Zobnin
2019-10-09 15:41:02 +03:00
parent 1827aa942a
commit 1d13520358
3 changed files with 22 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ import _ from 'lodash';
import mocks from '../../test-setup/mocks'; import mocks from '../../test-setup/mocks';
import { Datasource } from "../module"; import { Datasource } from "../module";
import { zabbixTemplateFormat } from "../datasource"; import { zabbixTemplateFormat } from "../datasource";
import { dateMath } from '@grafana/data';
describe('ZabbixDatasource', () => { describe('ZabbixDatasource', () => {
let ctx = {}; let ctx = {};
@@ -41,7 +42,10 @@ describe('ZabbixDatasource', () => {
item: {filter: ""} item: {filter: ""}
} }
], ],
range: {from: 'now-7d', to: 'now'} range: {
from: dateMath.parse('now-1h'),
to: dateMath.parse('now')
}
}; };
it('should return an empty array when no targets are set', (done) => { it('should return an empty array when no targets are set', (done) => {
@@ -59,7 +63,7 @@ describe('ZabbixDatasource', () => {
let ranges = ['now-8d', 'now-169h', 'now-1M', 'now-1y']; let ranges = ['now-8d', 'now-169h', 'now-1M', 'now-1y'];
_.forEach(ranges, range => { _.forEach(ranges, range => {
ctx.options.range.from = range; ctx.options.range.from = dateMath.parse(range);
ctx.ds.queryNumericData = jest.fn(); ctx.ds.queryNumericData = jest.fn();
ctx.ds.query(ctx.options); ctx.ds.query(ctx.options);
@@ -76,7 +80,7 @@ describe('ZabbixDatasource', () => {
let ranges = ['now-7d', 'now-168h', 'now-1h', 'now-30m', 'now-30s']; let ranges = ['now-7d', 'now-168h', 'now-1h', 'now-30m', 'now-30s'];
_.forEach(ranges, range => { _.forEach(ranges, range => {
ctx.options.range.from = range; ctx.options.range.from = dateMath.parse(range);
ctx.ds.queryNumericData = jest.fn(); ctx.ds.queryNumericData = jest.fn();
ctx.ds.query(ctx.options); ctx.ds.query(ctx.options);
@@ -108,10 +112,7 @@ describe('ZabbixDatasource', () => {
} }
])); ]));
ctx.options = { ctx.options.targets = [{
range: {from: 'now-1h', to: 'now'},
targets: [
{
group: {filter: ""}, group: {filter: ""},
host: {filter: "Zabbix server"}, host: {filter: "Zabbix server"},
application: {filter: ""}, application: {filter: ""},
@@ -123,9 +124,7 @@ describe('ZabbixDatasource', () => {
options: { options: {
skipEmptyValues: false skipEmptyValues: false
} }
} }];
],
};
}); });
it('should return data in table format', (done) => { it('should return data in table format', (done) => {

View File

@@ -45,6 +45,7 @@ jest.mock('grafana/app/core/utils/datemath', () => {
jest.mock('grafana/app/core/utils/kbn', () => { jest.mock('grafana/app/core/utils/kbn', () => {
return { return {
round_interval: n => n, round_interval: n => n,
secondsToHms: n => n + 'ms'
}; };
}, {virtual: true}); }, {virtual: true});