Initial unit tests (using Mocha and Chai asserts).

This commit is contained in:
Alexander Zobnin
2016-08-14 11:58:23 +03:00
parent 2882a48f25
commit d247fc8a99
5 changed files with 136 additions and 8 deletions

View File

@@ -0,0 +1,40 @@
import {Datasource} from "../module";
import Q from "q";
describe('ZabbixDatasource', function() {
var ctx = {};
beforeEach(function() {
ctx.instanceSettings = {
jsonData: {
username: 'zabbix',
password: 'zabbix',
trends: false
}
};
ctx.$q = Q;
ctx.templateSrv = {};
ctx.alertSrv = {};
ctx.zabbixAPIService = function() {};
ctx.ZabbixCachingProxy = function() {};
ctx.QueryProcessor = function() {};
ctx.ds = new Datasource(ctx.instanceSettings, ctx.$q, ctx.templateSrv, ctx.alertSrv,
ctx.zabbixAPIService, ctx.ZabbixCachingProxy, ctx.QueryProcessor);
});
describe('When querying data', function() {
it('should return an empty array when no targets are set', function(done) {
var options = {
targets: [],
range: {from: null, to: null}
};
ctx.ds.query(options).then(function(result) {
expect(result.data).to.have.length(0);
done();
});
});
});
});

View File

@@ -0,0 +1,43 @@
// JSHint options
/* globals global: false */
import prunk from 'prunk';
import {jsdom} from 'jsdom';
import chai from 'chai';
// Mock angular module
var angularMocks = {
module: function() {
return {
directive: function() {},
service: function() {},
factory: function() {}
};
}
};
var datemathMock = {
parse: function() {}
};
// Mock Grafana modules that are not available outside of the core project
// Required for loading module.js
prunk.mock('./css/query-editor.css!', 'no css, dude.');
prunk.mock('app/plugins/sdk', {
QueryCtrl: null
});
prunk.mock('app/core/utils/datemath', datemathMock);
prunk.mock('angular', angularMocks);
prunk.mock('jquery', 'module not found');
// Setup jsdom
// Required for loading angularjs
global.document = jsdom('<html><head><script></script></head><body></body></html>');
global.window = global.document.parentWindow;
global.navigator = window.navigator = {};
global.Node = window.Node;
// Setup Chai
chai.should();
global.assert = chai.assert;
global.expect = chai.expect;