fix tests
This commit is contained in:
@@ -4,6 +4,12 @@ import { Datasource } from "../module";
|
|||||||
import { zabbixTemplateFormat } from "../datasource";
|
import { zabbixTemplateFormat } from "../datasource";
|
||||||
import { dateMath } from '@grafana/data';
|
import { dateMath } from '@grafana/data';
|
||||||
|
|
||||||
|
jest.mock('@grafana/runtime', () => ({
|
||||||
|
getBackendSrv: () => ({
|
||||||
|
datasourceRequest: jest.fn().mockResolvedValue({data: {result: ''}}),
|
||||||
|
}),
|
||||||
|
}), {virtual: true});
|
||||||
|
|
||||||
describe('ZabbixDatasource', () => {
|
describe('ZabbixDatasource', () => {
|
||||||
let ctx = {};
|
let ctx = {};
|
||||||
|
|
||||||
@@ -25,7 +31,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
||||||
ctx.zabbixAlertingSrv = mocks.zabbixAlertingSrvMock;
|
ctx.zabbixAlertingSrv = mocks.zabbixAlertingSrvMock;
|
||||||
|
|
||||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.datasourceSrv, ctx.zabbixAlertingSrv);
|
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.zabbixAlertingSrv);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When querying data', () => {
|
describe('When querying data', () => {
|
||||||
|
|||||||
@@ -52,16 +52,16 @@ export class ZabbixAPICore {
|
|||||||
datasourceRequest(requestOptions) {
|
datasourceRequest(requestOptions) {
|
||||||
return getBackendSrv().datasourceRequest(requestOptions)
|
return getBackendSrv().datasourceRequest(requestOptions)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.data) {
|
if (!response?.data) {
|
||||||
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
|
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
|
||||||
} else if (response.data.error) {
|
} else if (response?.data.error) {
|
||||||
|
|
||||||
// Handle Zabbix API errors
|
// Handle Zabbix API errors
|
||||||
return Promise.reject(new ZabbixAPIError(response.data.error));
|
return Promise.reject(new ZabbixAPIError(response.data.error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
return response.data.result;
|
return response?.data.result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import mocks from '../../test-setup/mocks';
|
|
||||||
import { Zabbix } from './zabbix';
|
import { Zabbix } from './zabbix';
|
||||||
|
|
||||||
|
jest.mock('@grafana/runtime', () => ({
|
||||||
|
getBackendSrv: () => ({
|
||||||
|
datasourceRequest: jest.fn().mockResolvedValue({data: {result: ''}}),
|
||||||
|
}),
|
||||||
|
}), {virtual: true});
|
||||||
|
|
||||||
describe('Zabbix', () => {
|
describe('Zabbix', () => {
|
||||||
let ctx = {};
|
let ctx = {};
|
||||||
let zabbix;
|
let zabbix;
|
||||||
@@ -13,8 +18,8 @@ describe('Zabbix', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.options = options;
|
ctx.options = options;
|
||||||
// ctx.backendSrv = mocks.backendSrvMock;
|
// ctx.backendSrv = mocks.backendSrvMock;
|
||||||
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
// ctx.datasourceSrv = mocks.datasourceSrvMock;
|
||||||
zabbix = new Zabbix(ctx.options, ctx.datasourceSrvMock);
|
zabbix = new Zabbix(ctx.options);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When querying proxies', () => {
|
describe('When querying proxies', () => {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import { PanelCtrl, MetricsPanelCtrl } from './panelStub';
|
import { PanelCtrl, MetricsPanelCtrl } from './panelStub';
|
||||||
|
|
||||||
|
console.log = () => {};
|
||||||
|
|
||||||
// Mock Grafana modules that are not available outside of the core project
|
// Mock Grafana modules that are not available outside of the core project
|
||||||
// Required for loading module.js
|
// Required for loading module.js
|
||||||
jest.mock('angular', () => {
|
jest.mock('angular', () => {
|
||||||
@@ -18,6 +20,14 @@ jest.mock('angular', () => {
|
|||||||
};
|
};
|
||||||
}, {virtual: true});
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('@grafana/runtime', () => {
|
||||||
|
return {
|
||||||
|
getBackendSrv: () => ({
|
||||||
|
datasourceRequest: jest.fn().mockResolvedValue(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
jest.mock('grafana/app/core/core_module', () => {
|
jest.mock('grafana/app/core/core_module', () => {
|
||||||
return {
|
return {
|
||||||
directive: function() {},
|
directive: function() {},
|
||||||
|
|||||||
Reference in New Issue
Block a user