本文整理汇总了TypeScript中test/lib/common.angularMocks类的典型用法代码示例。如果您正苦于以下问题:TypeScript angularMocks类的具体用法?TypeScript angularMocks怎么用?TypeScript angularMocks使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了angularMocks类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('BluefloodQueryCtrl', function() {
var ctx = new helpers.ControllerTestContext();
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase());
beforeEach(ctx.createControllerPhase('BluefloodQueryCtrl'));
beforeEach(function() {
ctx.scope.target = {target: 'aliasByNode(scaleToSeconds(test.prod.*,1),2)'};
ctx.scope.datasource = ctx.datasource;
ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
});
describe('init', function() {
beforeEach(function() {
ctx.scope.init();
ctx.scope.$digest();
});
it('should validate metric key exists', function() {
expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*');
});
it('should delete last segment if no metrics are found', function() {
expect(ctx.scope.segments[2].value).to.be('select metric');
});
it('should parse expression and build function model', function() {
expect(ctx.scope.functions.length).to.be(2);
});
});
describe('when adding function', function() {
beforeEach(function() {
ctx.scope.target.target = 'test.prod.*.count';
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));
ctx.scope.init();
ctx.scope.$digest();
ctx.scope.$parent = { get_data: sinon.spy() };
ctx.scope.addFunction(gfunc.getFuncDef('aliasByNode'));
});
it('should add function with correct node number', function() {
expect(ctx.scope.functions[0].params[0]).to.be(2);
});
it('should update target', function() {
expect(ctx.scope.target.target).to.be('aliasByNode(test.prod.*.count, 2)');
});
it('should call get_data', function() {
expect(ctx.scope.$parent.get_data.called).to.be(true);
});
});
describe('when adding function before any metric segment', function() {
beforeEach(function() {
ctx.scope.target.target = '';
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}]));
ctx.scope.init();
ctx.scope.$digest();
ctx.scope.$parent = { get_data: sinon.spy() };
ctx.scope.addFunction(gfunc.getFuncDef('asPercent'));
});
it('should add function and remove select metric link', function() {
expect(ctx.scope.segments.length).to.be(0);
});
});
describe('when initalizing target without metric expression and only function', function() {
beforeEach(function() {
ctx.scope.target.target = 'asPercent(#A, #B)';
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([]));
ctx.scope.init();
ctx.scope.$digest();
ctx.scope.$parent = { get_data: sinon.spy() };
});
it('should not add select metric segment', function() {
expect(ctx.scope.segments.length).to.be(0);
});
it('should add both series refs as params', function() {
expect(ctx.scope.functions[0].params.length).to.be(2);
});
});
describe('when initializing a target with single param func using variable', function() {
beforeEach(function() {
ctx.scope.target.target = 'movingAverage(prod.count, $var)';
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([]));
ctx.scope.init();
//.........这里部分代码省略.........
示例2: describe
describe('graphiteDatasource', function() {
var ctx = new helpers.ServiceTestContext();
var instanceSettings: any = {url: ['']};
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase(['backendSrv']));
beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
ctx.$q = $q;
ctx.$httpBackend = $httpBackend;
ctx.$rootScope = $rootScope;
ctx.$injector = $injector;
}));
beforeEach(function() {
ctx.ds = ctx.$injector.instantiate(Datasource, {instanceSettings: instanceSettings});
});
describe('When querying influxdb with one target using query editor target spec', function() {
var query = {
rangeRaw: { from: 'now-1h', to: 'now' },
targets: [{ target: 'prod1.count' }, {target: 'prod2.count'}],
maxDataPoints: 500,
};
var results;
var requestOptions;
beforeEach(function() {
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
};
ctx.ds.query(query).then(function(data) { results = data; });
ctx.$rootScope.$apply();
});
it('should generate the correct query', function() {
expect(requestOptions.url).to.be('/render');
});
it('should query correctly', function() {
var params = requestOptions.data.split('&');
expect(params).to.contain('target=prod1.count');
expect(params).to.contain('target=prod2.count');
expect(params).to.contain('from=-1h');
expect(params).to.contain('until=now');
});
it('should exclude undefined params', function() {
var params = requestOptions.data.split('&');
expect(params).to.not.contain('cacheTimeout=undefined');
});
it('should return series list', function() {
expect(results.data.length).to.be(1);
expect(results.data[0].target).to.be('prod1.count');
});
it('should convert to millisecond resolution', function() {
expect(results.data[0].datapoints[0][0]).to.be(10);
});
});
describe('building graphite params', function() {
it('should return empty array if no targets', function() {
var results = ctx.ds.buildGraphiteParams({
targets: [{}]
});
expect(results.length).to.be(0);
});
it('should uri escape targets', function() {
var results = ctx.ds.buildGraphiteParams({
targets: [{target: 'prod1.{test,test2}'}, {target: 'prod2.count'}]
});
expect(results).to.contain('target=prod1.%7Btest%2Ctest2%7D');
});
it('should replace target placeholder', function() {
var results = ctx.ds.buildGraphiteParams({
targets: [{target: 'series1'}, {target: 'series2'}, {target: 'asPercent(#A,#B)'}]
});
expect(results[2]).to.be('target=asPercent(series1%2Cseries2)');
});
it('should replace target placeholder for hidden series', function() {
var results = ctx.ds.buildGraphiteParams({
targets: [{target: 'series1', hide: true}, {target: 'sumSeries(#A)', hide: true}, {target: 'asPercent(#A,#B)'}]
});
expect(results[0]).to.be('target=' + encodeURIComponent('asPercent(series1,sumSeries(series1))'));
});
it('should replace target placeholder when nesting query references', function() {
var results = ctx.ds.buildGraphiteParams({
targets: [{target: 'series1'}, {target: 'sumSeries(#A)'}, {target: 'asPercent(#A,#B)'}]
});
expect(results[2]).to.be('target=' + encodeURIComponent("asPercent(series1,sumSeries(series1))"));
//.........这里部分代码省略.........
示例3: describe
describe('CloudWatchDatasource', function() {
var ctx = new helpers.ServiceTestContext();
var instanceSettings = {
jsonData: {defaultRegion: 'us-east-1', access: 'proxy'},
};
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
ctx.$q = $q;
ctx.$httpBackend = $httpBackend;
ctx.$rootScope = $rootScope;
ctx.ds = $injector.instantiate(Datasource, {instanceSettings: instanceSettings});
}));
describe('When performing CloudWatch query', function() {
var requestParams;
var query = {
range: { from: 'now-1h', to: 'now' },
targets: [
{
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: 'i-12345678'
},
statistics: ['Average'],
period: 300
}
]
};
var response = {
Datapoints: [
{
Average: 1,
Timestamp: 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)'
},
{
Average: 2,
Timestamp: 'Wed Dec 31 1969 16:05:00 GMT-0800 (PST)'
},
{
Average: 5,
Timestamp: 'Wed Dec 31 1969 16:15:00 GMT-0800 (PST)'
}
],
Label: 'CPUUtilization'
};
beforeEach(function() {
ctx.backendSrv.datasourceRequest = function(params) {
requestParams = params;
return ctx.$q.when({data: response});
};
});
it('should generate the correct query', function(done) {
ctx.ds.query(query).then(function() {
var params = requestParams.data.parameters;
expect(params.namespace).to.be(query.targets[0].namespace);
expect(params.metricName).to.be(query.targets[0].metricName);
expect(params.dimensions[0].Name).to.be(Object.keys(query.targets[0].dimensions)[0]);
expect(params.dimensions[0].Value).to.be(query.targets[0].dimensions[Object.keys(query.targets[0].dimensions)[0]]);
expect(params.statistics).to.eql(query.targets[0].statistics);
expect(params.period).to.be(query.targets[0].period);
done();
});
ctx.$rootScope.$apply();
});
it('should return series list', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].target).to.be('CPUUtilization_Average');
expect(result.data[0].datapoints[0][0]).to.be(response.Datapoints[0]['Average']);
done();
});
ctx.$rootScope.$apply();
});
it('should return null for missing data point', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].datapoints[2][0]).to.be(null);
done();
});
ctx.$rootScope.$apply();
});
});
function describeMetricFindQuery(query, func) {
describe('metricFindQuery ' + query, () => {
let scenario: any = {};
scenario.setup = setupCallback => {
beforeEach(() => {
setupCallback();
//.........这里部分代码省略.........
示例4: describe
describe('ElasticDatasource', function() {
var ctx = new helpers.ServiceTestContext();
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv', 'timeSrv']));
beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
ctx.$q = $q;
ctx.$httpBackend = $httpBackend;
ctx.$rootScope = $rootScope;
ctx.$injector = $injector;
$httpBackend.when('GET', /\.html$/).respond('');
}));
function createDatasource(instanceSettings) {
instanceSettings.jsonData = instanceSettings.jsonData || {};
ctx.ds = ctx.$injector.instantiate(ElasticDatasource, {instanceSettings: instanceSettings});
}
describe('When testing datasource with index pattern', function() {
beforeEach(function() {
createDatasource({url: 'http://es.com', index: '[asd-]YYYY.MM.DD', jsonData: {interval: 'Daily', esVersion: '2'}});
});
it('should translate index pattern to current day', function() {
var requestOptions;
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: {}});
};
ctx.ds.testDatasource();
ctx.$rootScope.$apply();
var today = moment.utc().format("YYYY.MM.DD");
expect(requestOptions.url).to.be("http://es.com/asd-" + today + '/_mapping');
});
});
describe('When issueing metric query with interval pattern', function() {
var requestOptions, parts, header;
beforeEach(function() {
createDatasource({url: 'http://es.com', index: '[asd-]YYYY.MM.DD', jsonData: {interval: 'Daily', esVersion: '2'}});
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: {responses: []}});
};
ctx.ds.query({
range: {
from: moment.utc([2015, 4, 30, 10]),
to: moment.utc([2015, 5, 1, 10])
},
targets: [{ bucketAggs: [], metrics: [{type: 'raw_document'}], query: 'escape\\:test' }]
});
ctx.$rootScope.$apply();
parts = requestOptions.data.split('\n');
header = angular.fromJson(parts[0]);
});
it('should translate index pattern to current day', function() {
expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
});
it('should json escape lucene query', function() {
var body = angular.fromJson(parts[1]);
expect(body.query.bool.filter[1].query_string.query).to.be('escape\\:test');
});
});
describe('When issueing document query', function() {
var requestOptions, parts, header;
beforeEach(function() {
createDatasource({url: 'http://es.com', index: 'test', jsonData: {esVersion: '2'}});
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: {responses: []}});
};
ctx.ds.query({
range: { from: moment([2015, 4, 30, 10]), to: moment([2015, 5, 1, 10]) },
targets: [{ bucketAggs: [], metrics: [{type: 'raw_document'}], query: 'test' }]
});
ctx.$rootScope.$apply();
parts = requestOptions.data.split('\n');
header = angular.fromJson(parts[0]);
});
it('should set search type to query_then_fetch', function() {
expect(header.search_type).to.eql('query_then_fetch');
});
//.........这里部分代码省略.........
示例5: describe
describe('PrometheusMetricFindQuery', function() {
var ctx = new helpers.ServiceTestContext();
var instanceSettings = {
url: 'proxied',
directUrl: 'direct',
user: 'test',
password: 'mupp',
jsonData: { httpMethod: 'GET' },
};
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(
angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
ctx.$q = $q;
ctx.$httpBackend = $httpBackend;
ctx.$rootScope = $rootScope;
ctx.ds = $injector.instantiate(PrometheusDatasource, {
instanceSettings: instanceSettings,
});
$httpBackend.when('GET', /\.html$/).respond('');
})
);
describe('When performing metricFindQuery', function() {
var results;
var response;
it('label_values(resource) should generate label search query', function() {
response = {
status: 'success',
data: ['value1', 'value2', 'value3'],
};
ctx.$httpBackend.expect('GET', 'proxied/api/v1/label/resource/values').respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(resource)', ctx.timeSrv);
pm.process().then(function(data) {
results = data;
});
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
expect(results.length).to.be(3);
});
it('label_values(metric, resource) should generate series query', function() {
response = {
status: 'success',
data: [
{ __name__: 'metric', resource: 'value1' },
{ __name__: 'metric', resource: 'value2' },
{ __name__: 'metric', resource: 'value3' },
],
};
ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/series\?match\[\]=metric&start=.*&end=.*/).respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)', ctx.timeSrv);
pm.process().then(function(data) {
results = data;
});
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
expect(results.length).to.be(3);
});
it('label_values(metric, resource) should pass correct time', function() {
ctx.timeSrv.setTime({
from: moment.utc('2011-01-01'),
to: moment.utc('2015-01-01'),
});
ctx.$httpBackend
.expect('GET', /proxied\/api\/v1\/series\?match\[\]=metric&start=1293840000&end=1420070400/)
.respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)', ctx.timeSrv);
pm.process().then(function(data) {
results = data;
});
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
});
it('label_values(metric{label1="foo", label2="bar", label3="baz"}, resource) should generate series query', function() {
response = {
status: 'success',
data: [
{ __name__: 'metric', resource: 'value1' },
{ __name__: 'metric', resource: 'value2' },
{ __name__: 'metric', resource: 'value3' },
],
};
ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/series\?match\[\]=metric&start=.*&end=.*/).respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)', ctx.timeSrv);
pm.process().then(function(data) {
results = data;
});
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
expect(results.length).to.be(3);
});
it('label_values(metric, resource) result should not contain empty string', function() {
response = {
status: 'success',
data: [
{ __name__: 'metric', resource: 'value1' },
{ __name__: 'metric', resource: 'value2' },
{ __name__: 'metric', resource: '' },
],
//.........这里部分代码省略.........
示例6: describe
describe('InfluxDBQueryCtrl', function() {
var ctx = new helpers.ControllerTestContext();
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase());
beforeEach(ctx.createControllerPhase('InfluxQueryCtrl'));
beforeEach(function() {
ctx.scope.target = {};
ctx.scope.$parent = { get_data: sinon.spy() };
ctx.scope.datasource = ctx.datasource;
ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
});
describe('init', function() {
beforeEach(function() {
ctx.scope.init();
});
it('should init tagSegments', function() {
expect(ctx.scope.tagSegments.length).to.be(1);
});
it('should init measurementSegment', function() {
expect(ctx.scope.measurementSegment.value).to.be('select measurement');
});
});
describe('when first tag segment is updated', function() {
beforeEach(function() {
ctx.scope.init();
ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
});
it('should update tag key', function() {
expect(ctx.scope.target.tags[0].key).to.be('asd');
expect(ctx.scope.tagSegments[0].type).to.be('key');
});
it('should add tagSegments', function() {
expect(ctx.scope.tagSegments.length).to.be(3);
});
});
describe('when last tag value segment is updated', function() {
beforeEach(function() {
ctx.scope.init();
ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
});
it('should update tag value', function() {
expect(ctx.scope.target.tags[0].value).to.be('server1');
});
it('should set tag operator', function() {
expect(ctx.scope.target.tags[0].operator).to.be('=');
});
it('should add plus button for another filter', function() {
expect(ctx.scope.tagSegments[3].fake).to.be(true);
});
});
describe('when last tag value segment is updated to regex', function() {
beforeEach(function() {
ctx.scope.init();
ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
ctx.scope.tagSegmentUpdated({value: '/server.*/', type: 'value'}, 2);
});
it('should update operator', function() {
expect(ctx.scope.tagSegments[1].value).to.be('=~');
expect(ctx.scope.target.tags[0].operator).to.be('=~');
});
});
describe('when second tag key is added', function() {
beforeEach(function() {
ctx.scope.init();
ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
});
it('should update tag key', function() {
expect(ctx.scope.target.tags[1].key).to.be('key2');
});
it('should add AND segment', function() {
expect(ctx.scope.tagSegments[3].value).to.be('AND');
});
});
describe('when condition is changed', function() {
beforeEach(function() {
ctx.scope.init();
//.........这里部分代码省略.........
示例7: describe
describe('ElasticDatasource', function() {
var ctx = new helpers.ServiceTestContext();
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
beforeEach(ctx.createService('ElasticDatasource'));
beforeEach(function() {
ctx.ds = new ctx.service({jsonData: {}});
});
describe('When testing datasource with index pattern', function() {
beforeEach(function() {
ctx.ds = new ctx.service({
url: 'http://es.com',
index: '[asd-]YYYY.MM.DD',
jsonData: { interval: 'Daily' }
});
});
it('should translate index pattern to current day', function() {
var requestOptions;
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({});
};
ctx.ds.testDatasource();
ctx.$rootScope.$apply();
var today = moment.utc().format("YYYY.MM.DD");
expect(requestOptions.url).to.be("http://es.com/asd-" + today + '/_stats');
});
});
describe('When issueing metric query with interval pattern', function() {
var requestOptions, parts, header;
beforeEach(function() {
ctx.ds = new ctx.service({
url: 'http://es.com',
index: '[asd-]YYYY.MM.DD',
jsonData: { interval: 'Daily' }
});
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: {responses: []}});
};
ctx.ds.query({
range: {
from: moment([2015, 4, 30, 10]),
to: moment([2015, 5, 1, 10])
},
targets: [{ bucketAggs: [], metrics: [], query: 'escape\\:test' }]
});
ctx.$rootScope.$apply();
parts = requestOptions.data.split('\n');
header = angular.fromJson(parts[0]);
});
it('should translate index pattern to current day', function() {
expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
});
it('should json escape lucene query', function() {
var body = angular.fromJson(parts[1]);
expect(body.query.filtered.query.query_string.query).to.be('escape\\:test');
});
});
describe('When issueing document query', function() {
var requestOptions, parts, header;
beforeEach(function() {
ctx.ds = new ctx.service({url: 'http://es.com', index: 'test', jsonData: {}});
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: {responses: []}});
};
ctx.ds.query({
range: { from: moment([2015, 4, 30, 10]), to: moment([2015, 5, 1, 10]) },
targets: [{ bucketAggs: [], metrics: [{type: 'raw_document'}], query: 'test' }]
});
ctx.$rootScope.$apply();
parts = requestOptions.data.split('\n');
header = angular.fromJson(parts[0]);
});
it('should set search type to query_then_fetch', function() {
expect(header.search_type).to.eql('query_then_fetch');
});
it('should set size', function() {
//.........这里部分代码省略.........
示例8: describe
describe('graphiteDatasource', function() {
let ctx = new helpers.ServiceTestContext();
let instanceSettings: any = {url: [''], name: 'graphiteProd', jsonData: {}};
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase(['backendSrv', 'templateSrv']));
beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
ctx.$q = $q;
ctx.$httpBackend = $httpBackend;
ctx.$rootScope = $rootScope;
ctx.$injector = $injector;
$httpBackend.when('GET', /\.html$/).respond('');
}));
beforeEach(function() {
ctx.ds = ctx.$injector.instantiate(GraphiteDatasource, {instanceSettings: instanceSettings});
});
describe('When querying graphite with one target using query editor target spec', function() {
let query = {
panelId: 3,
rangeRaw: { from: 'now-1h', to: 'now' },
targets: [{ target: 'prod1.count' }, {target: 'prod2.count'}],
maxDataPoints: 500,
};
let results;
let requestOptions;
beforeEach(function() {
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
};
ctx.ds.query(query).then(function(data) { results = data; });
ctx.$rootScope.$apply();
});
it('should generate the correct query', function() {
expect(requestOptions.url).to.be('/render');
});
it('should set unique requestId', function() {
expect(requestOptions.requestId).to.be('graphiteProd.panelId.3');
});
it('should query correctly', function() {
let params = requestOptions.data.split('&');
expect(params).to.contain('target=prod1.count');
expect(params).to.contain('target=prod2.count');
expect(params).to.contain('from=-1h');
expect(params).to.contain('until=now');
});
it('should exclude undefined params', function() {
let params = requestOptions.data.split('&');
expect(params).to.not.contain('cacheTimeout=undefined');
});
it('should return series list', function() {
expect(results.data.length).to.be(1);
expect(results.data[0].target).to.be('prod1.count');
});
it('should convert to millisecond resolution', function() {
expect(results.data[0].datapoints[0][0]).to.be(10);
});
});
describe('when fetching Graphite Events as annotations', () => {
let results;
const options = {
annotation: {
tags: 'tag1'
},
range: {
from: moment(1432288354),
to: moment(1432288401)
},
rangeRaw: {from: "now-24h", to: "now"}
};
describe('and tags are returned as string', () => {
const response = {
data: [
{
when: 1507222850,
tags: 'tag1 tag2',
data: 'some text',
id: 2,
what: 'Event - deploy'
}
]};
beforeEach(() => {
ctx.backendSrv.datasourceRequest = function(options) {
//.........这里部分代码省略.........
示例9: describe
describe('when the user wants to compare two revisions', function() {
var deferred;
beforeEach(
angularMocks.inject(($controller, $q) => {
deferred = $q.defer();
historySrv.getHistoryList.returns($q.when(versionsResponse));
historySrv.calculateDiff.returns(deferred.promise);
ctx.ctrl = $controller(
HistoryListCtrl,
{
historySrv,
$rootScope,
$scope: ctx.scope,
},
{
dashboard: {
id: 2,
version: 3,
formatDate: sinon.stub().returns('date'),
},
}
);
ctx.ctrl.$scope.onDashboardSaved = sinon.spy();
ctx.ctrl.$scope.$apply();
})
);
it('should have already fetched the history list', function() {
expect(historySrv.getHistoryList.calledOnce).to.be(true);
expect(ctx.ctrl.revisions.length).to.be.above(0);
});
it('should check that two valid versions are selected', function() {
// []
expect(ctx.ctrl.canCompare).to.be(false);
// single value
ctx.ctrl.revisions = [{ checked: true }];
ctx.ctrl.revisionSelectionChanged();
expect(ctx.ctrl.canCompare).to.be(false);
// both values in range
ctx.ctrl.revisions = [{ checked: true }, { checked: true }];
ctx.ctrl.revisionSelectionChanged();
expect(ctx.ctrl.canCompare).to.be(true);
});
describe('and the basic diff is successfully fetched', function() {
beforeEach(function() {
deferred.resolve(compare('basic'));
ctx.ctrl.revisions[1].checked = true;
ctx.ctrl.revisions[3].checked = true;
ctx.ctrl.getDiff('basic');
ctx.ctrl.$scope.$apply();
});
it('should fetch the basic diff if two valid versions are selected', function() {
expect(historySrv.calculateDiff.calledOnce).to.be(true);
expect(ctx.ctrl.delta.basic).to.be('<div></div>');
expect(ctx.ctrl.delta.json).to.be('');
});
it('should set the basic diff view as active', function() {
expect(ctx.ctrl.mode).to.be('compare');
expect(ctx.ctrl.diff).to.be('basic');
});
it('should indicate loading has finished', function() {
expect(ctx.ctrl.loading).to.be(false);
});
});
describe('and the json diff is successfully fetched', function() {
beforeEach(function() {
deferred.resolve(compare('json'));
ctx.ctrl.revisions[1].checked = true;
ctx.ctrl.revisions[3].checked = true;
ctx.ctrl.getDiff('json');
ctx.ctrl.$scope.$apply();
});
it('should fetch the json diff if two valid versions are selected', function() {
expect(historySrv.calculateDiff.calledOnce).to.be(true);
expect(ctx.ctrl.delta.basic).to.be('');
expect(ctx.ctrl.delta.json).to.be('<pre><code></code></pre>');
});
it('should set the json diff view as active', function() {
expect(ctx.ctrl.mode).to.be('compare');
expect(ctx.ctrl.diff).to.be('json');
});
it('should indicate loading has finished', function() {
expect(ctx.ctrl.loading).to.be(false);
});
});
describe('and diffs have already been fetched', function() {
//.........这里部分代码省略.........
示例10: describe
describe('CloudWatchDatasource', function() {
var ctx = new helpers.ServiceTestContext();
beforeEach(angularMocks.module('grafana.services'));
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
beforeEach(ctx.createService('CloudWatchDatasource'));
beforeEach(function() {
ctx.ds = new ctx.service({
jsonData: {
defaultRegion: 'us-east-1',
access: 'proxy'
}
});
});
describe('When performing CloudWatch query', function() {
var requestParams;
var query = {
range: { from: 'now-1h', to: 'now' },
targets: [
{
region: 'us-east-1',
namespace: 'AWS/EC2',
metricName: 'CPUUtilization',
dimensions: {
InstanceId: 'i-12345678'
},
statistics: ['Average'],
period: 300
}
]
};
var response = {
Datapoints: [
{
Average: 1,
Timestamp: 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)'
}
],
Label: 'CPUUtilization'
};
beforeEach(function() {
ctx.backendSrv.datasourceRequest = function(params) {
requestParams = params;
return ctx.$q.when({data: response});
};
});
it('should generate the correct query', function(done) {
ctx.ds.query(query).then(function() {
var params = requestParams.data.parameters;
expect(params.namespace).to.be(query.targets[0].namespace);
expect(params.metricName).to.be(query.targets[0].metricName);
expect(params.dimensions[0].Name).to.be(Object.keys(query.targets[0].dimensions)[0]);
expect(params.dimensions[0].Value).to.be(query.targets[0].dimensions[Object.keys(query.targets[0].dimensions)[0]]);
expect(params.statistics).to.eql(query.targets[0].statistics);
expect(params.period).to.be(query.targets[0].period);
done();
});
ctx.$rootScope.$apply();
});
it('should return series list', function(done) {
ctx.ds.query(query).then(function(result) {
expect(result.data[0].target).to.be('CPUUtilization_Average');
expect(result.data[0].datapoints[0][0]).to.be(response.Datapoints[0]['Average']);
done();
});
ctx.$rootScope.$apply();
});
});
function describeMetricFindQuery(query, func) {
describe('metricFindQuery ' + query, () => {
let scenario: any = {};
scenario.setup = setupCallback => {
beforeEach(() => {
setupCallback();
ctx.backendSrv.datasourceRequest = args => {
scenario.request = args;
return ctx.$q.when({data: scenario.requestResponse });
};
ctx.ds.metricFindQuery(query).then(args => {
scenario.result = args;
});
ctx.$rootScope.$apply();
});
};
func(scenario);
});
}
describeMetricFindQuery('regions()', scenario => {
scenario.setup(() => {
scenario.requestResponse = [{text: 'us-east-1'}];
//.........这里部分代码省略.........