From 1d13520358c242947a82e563a7039d32ae69198d Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 9 Oct 2019 15:41:02 +0300 Subject: [PATCH] fix tests --- .../specs/datasource.spec.js | 41 +++++++++---------- src/datasource-zabbix/timeseries.js | 2 +- src/test-setup/jest-setup.js | 1 + 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/datasource-zabbix/specs/datasource.spec.js b/src/datasource-zabbix/specs/datasource.spec.js index 7c95335..dd99f26 100644 --- a/src/datasource-zabbix/specs/datasource.spec.js +++ b/src/datasource-zabbix/specs/datasource.spec.js @@ -2,6 +2,7 @@ import _ from 'lodash'; import mocks from '../../test-setup/mocks'; import { Datasource } from "../module"; import { zabbixTemplateFormat } from "../datasource"; +import { dateMath } from '@grafana/data'; describe('ZabbixDatasource', () => { let ctx = {}; @@ -41,7 +42,10 @@ describe('ZabbixDatasource', () => { 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) => { @@ -59,7 +63,7 @@ describe('ZabbixDatasource', () => { let ranges = ['now-8d', 'now-169h', 'now-1M', 'now-1y']; _.forEach(ranges, range => { - ctx.options.range.from = range; + ctx.options.range.from = dateMath.parse(range); ctx.ds.queryNumericData = jest.fn(); ctx.ds.query(ctx.options); @@ -76,7 +80,7 @@ describe('ZabbixDatasource', () => { let ranges = ['now-7d', 'now-168h', 'now-1h', 'now-30m', 'now-30s']; _.forEach(ranges, range => { - ctx.options.range.from = range; + ctx.options.range.from = dateMath.parse(range); ctx.ds.queryNumericData = jest.fn(); ctx.ds.query(ctx.options); @@ -108,24 +112,19 @@ describe('ZabbixDatasource', () => { } ])); - ctx.options = { - range: {from: 'now-1h', to: 'now'}, - targets: [ - { - group: {filter: ""}, - host: {filter: "Zabbix server"}, - application: {filter: ""}, - item: {filter: "System information"}, - textFilter: "", - useCaptureGroups: true, - mode: 2, - resultFormat: "table", - options: { - skipEmptyValues: false - } - } - ], - }; + ctx.options.targets = [{ + group: {filter: ""}, + host: {filter: "Zabbix server"}, + application: {filter: ""}, + item: {filter: "System information"}, + textFilter: "", + useCaptureGroups: true, + mode: 2, + resultFormat: "table", + options: { + skipEmptyValues: false + } + }]; }); it('should return data in table format', (done) => { diff --git a/src/datasource-zabbix/timeseries.js b/src/datasource-zabbix/timeseries.js index 34853e8..109fa41 100644 --- a/src/datasource-zabbix/timeseries.js +++ b/src/datasource-zabbix/timeseries.js @@ -147,7 +147,7 @@ export function groupByRange(datapoints, groupByCallback) { frame_values.push(point[POINT_VALUE]); } const frame_value = groupByCallback(frame_values); - return [ [frame_value, frame_start], [frame_value, frame_end] ]; + return [[frame_value, frame_start], [frame_value, frame_end]]; } /** diff --git a/src/test-setup/jest-setup.js b/src/test-setup/jest-setup.js index dedf7a2..6d9ae49 100644 --- a/src/test-setup/jest-setup.js +++ b/src/test-setup/jest-setup.js @@ -45,6 +45,7 @@ jest.mock('grafana/app/core/utils/datemath', () => { jest.mock('grafana/app/core/utils/kbn', () => { return { round_interval: n => n, + secondsToHms: n => n + 'ms' }; }, {virtual: true});