mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
recfactor: added unit test for the new scenario, #8143
This commit is contained in:
parent
a64e000f1a
commit
85baa50194
@ -28,7 +28,6 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
toggleEditorMode() {
|
||||
this.target.textEditor = !this.target.textEditor;
|
||||
this.parseTarget();
|
||||
}
|
||||
|
||||
@ -220,17 +219,17 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
this.target.target = _.reduce(this.functions, this.wrapFunction, metricPath);
|
||||
}
|
||||
|
||||
this.resolveTarget(this.target);
|
||||
this.updateRenderedTarget(this.target);
|
||||
|
||||
// loop through other queries and update targetFull as needed
|
||||
for (const target of this.panelCtrl.panel.targets || []) {
|
||||
if (target.refId !== this.target.refId) {
|
||||
this.resolveTarget(target);
|
||||
this.updateRenderedTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resolveTarget(target) {
|
||||
updateRenderedTarget(target) {
|
||||
// render nested query
|
||||
var targetsByRefId = _.keyBy(this.panelCtrl.panel.targets, 'refId');
|
||||
|
||||
@ -240,6 +239,8 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
var nestedSeriesRefRegex = /\#([A-Z])/g;
|
||||
var targetWithNestedQueries = target.target;
|
||||
|
||||
// Keep interpolating until there are no query references
|
||||
// The reason for the loop is that the referenced query might contain another reference to another query
|
||||
while (targetWithNestedQueries.match(nestedSeriesRefRegex)) {
|
||||
var updated = targetWithNestedQueries.replace(nestedSeriesRefRegex, (match, g1) => {
|
||||
var t = targetsByRefId[g1];
|
||||
@ -249,7 +250,6 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
|
||||
// no circular references
|
||||
delete targetsByRefId[g1];
|
||||
|
||||
return t.target;
|
||||
});
|
||||
|
||||
|
@ -186,4 +186,24 @@ describe('GraphiteQueryCtrl', function() {
|
||||
expect(ctx.ctrl.target.targetFull).to.be('scaleToSeconds(nested.query.count)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when updating target used in other query', function() {
|
||||
beforeEach(function() {
|
||||
ctx.ctrl.target.target = 'metrics.a.count';
|
||||
ctx.ctrl.target.refId = 'A';
|
||||
ctx.ctrl.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([{expandable: false}]));
|
||||
ctx.ctrl.parseTarget();
|
||||
|
||||
ctx.ctrl.panelCtrl.panel.targets = [
|
||||
ctx.ctrl.target, {target: 'sumSeries(#A)', refId: 'B'}
|
||||
];
|
||||
|
||||
ctx.ctrl.updateModelTarget();
|
||||
});
|
||||
|
||||
it('targetFull of other query should update', function() {
|
||||
expect(ctx.ctrl.panel.targets[1].targetFull).to.be('sumSeries(metrics.a.count)');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user