From dd1b5104b4a35f9edc4c4b1517edf14b72507583 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Wed, 15 Apr 2020 14:43:48 +0200 Subject: [PATCH] Prep tests --- .../app/features/templating/specs/template_srv.test.ts | 5 +++++ public/app/features/templating/template_srv.ts | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/app/features/templating/specs/template_srv.test.ts b/public/app/features/templating/specs/template_srv.test.ts index 635c97b5443..209e1f7c82e 100644 --- a/public/app/features/templating/specs/template_srv.test.ts +++ b/public/app/features/templating/specs/template_srv.test.ts @@ -1,6 +1,8 @@ import { TemplateSrv } from '../template_srv'; import { convertToStoreState } from 'test/helpers/convertToStoreState'; import { getTemplateSrvDependencies } from '../../../../test/helpers/getTemplateSrvDependencies'; +import { variableAdapters } from '../../variables/adapters'; +import { createQueryVariableAdapter } from '../../variables/query/adapter'; describe('templateSrv', () => { let _templateSrv: any; @@ -448,6 +450,9 @@ describe('templateSrv', () => { }); describe('fillVariableValuesForUrl with multi value', () => { + beforeAll(() => { + variableAdapters.register(createQueryVariableAdapter()); + }); beforeEach(() => { initTemplateSrv([ { diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 74e81749e93..52f66c8363c 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -7,6 +7,7 @@ import { variableRegex } from './utils'; import { isAdHoc } from '../variables/guard'; import { VariableModel } from './types'; import { setTemplateSrv, TemplateSrv as BaseTemplateSrv } from '@grafana/runtime'; +import { variableAdapters } from '../variables/adapters'; function luceneEscape(value: string) { return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, '\\$1'); @@ -398,8 +399,8 @@ export class TemplateSrv implements BaseTemplateSrv { }); } - fillVariableValuesForUrl(params: any, scopedVars?: ScopedVars) { - _.each(this._variables, variable => { + fillVariableValuesForUrl = (params: any, scopedVars?: ScopedVars) => { + _.each(this.getVariables(), variable => { if (scopedVars && scopedVars[variable.name] !== void 0) { if (scopedVars[variable.name].skipUrlSync) { return; @@ -409,10 +410,10 @@ export class TemplateSrv implements BaseTemplateSrv { if (variable.skipUrlSync) { return; } - params['var-' + variable.name] = variable.getValueForUrl(); + params['var-' + variable.name] = variableAdapters.get(variable.type).getValueForUrl(variable); } }); - } + }; distributeVariable(value: any, variable: any) { value = _.map(value, (val: any, index: number) => {