mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add Jest stubs
This commit is contained in:
parent
69c85e0d7e
commit
80b2f5c756
@ -2,8 +2,8 @@ import _ from 'lodash';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import { ElasticDatasource } from '../datasource';
|
import { ElasticDatasource } from '../datasource';
|
||||||
import { TimeSrv } from 'app/features/dashboard/time_srv';
|
import { jestTimeSrvStub } from 'test/specs/helpers';
|
||||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
import { jestTemplateSrvStub } from 'test/specs/helpers';
|
||||||
import $q from 'q';
|
import $q from 'q';
|
||||||
|
|
||||||
describe('ElasticDatasource', function() {
|
describe('ElasticDatasource', function() {
|
||||||
@ -16,11 +16,9 @@ describe('ElasticDatasource', function() {
|
|||||||
appEvent: jest.fn(),
|
appEvent: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let templateSrv = new TemplateSrv();
|
let templateSrv = new jestTemplateSrvStub();
|
||||||
|
|
||||||
templateSrv.variables = [];
|
let timeSrv = new jestTimeSrvStub();
|
||||||
|
|
||||||
let timeSrv = new TimeSrv($rootScope, jest.fn(), {}, {}, {});
|
|
||||||
|
|
||||||
let ctx = <any>{
|
let ctx = <any>{
|
||||||
$rootScope,
|
$rootScope,
|
||||||
|
@ -195,13 +195,52 @@ export function TemplateSrvStub() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function jestTemplateSrvStub() {
|
||||||
|
this.variables = [];
|
||||||
|
this.templateSettings = { interpolate: /\[\[([\s\S]+?)\]\]/g };
|
||||||
|
this.data = {};
|
||||||
|
this.replace = jest.fn(text => _.template(text, this.templateSettings)(this.data));
|
||||||
|
this.init = jest.fn();
|
||||||
|
this.getAdhocFilters = jest.fn(() => []);
|
||||||
|
this.fillVariableValuesForUrl = jest.fn();
|
||||||
|
this.updateTemplateData = jest.fn();
|
||||||
|
this.variableExists = jest.fn(() => false);
|
||||||
|
this.variableInitialized = jest.fn();
|
||||||
|
this.highlightVariablesAsHtml = jest.fn(str => str);
|
||||||
|
this.setGrafanaVariable = jest.fn((name, value) => {
|
||||||
|
this.data[name] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function jestTimeSrvStub() {
|
||||||
|
this.init = jest.fn();
|
||||||
|
this.time = { from: 'now-1h', to: 'now' };
|
||||||
|
this.timeRange = jest.fn(parse => {
|
||||||
|
if (parse === false) {
|
||||||
|
return this.time;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
from: dateMath.parse(this.time.from, false),
|
||||||
|
to: dateMath.parse(this.time.to, true),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
this.replace = jest.fn(target => target);
|
||||||
|
|
||||||
|
this.setTime = jest.fn(time => {
|
||||||
|
this.time = time;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var allDeps = {
|
var allDeps = {
|
||||||
ContextSrvStub: ContextSrvStub,
|
ContextSrvStub,
|
||||||
TemplateSrvStub: TemplateSrvStub,
|
TemplateSrvStub,
|
||||||
TimeSrvStub: TimeSrvStub,
|
TimeSrvStub,
|
||||||
ControllerTestContext: ControllerTestContext,
|
ControllerTestContext,
|
||||||
ServiceTestContext: ServiceTestContext,
|
ServiceTestContext,
|
||||||
DashboardViewStateStub: DashboardViewStateStub,
|
DashboardViewStateStub,
|
||||||
|
jestTimeSrvStub,
|
||||||
|
jestTemplateSrvStub,
|
||||||
};
|
};
|
||||||
|
|
||||||
// for legacy
|
// for legacy
|
||||||
|
Loading…
Reference in New Issue
Block a user