Variables: Ensures all variable values are strings (#31942)

* Variables: Ensures all variable values are strings

* Chore: remove redundant typings

* Chore: fixes tests
This commit is contained in:
Hugo Häggmark
2021-03-15 08:52:44 +01:00
committed by GitHub
parent 16027770c8
commit 31ab1a4afe
8 changed files with 75 additions and 24 deletions

View File

@ -1,4 +1,4 @@
import { findTemplateVarChanges, getCurrentText, getVariableRefresh, isAllVariable } from './utils';
import { ensureStringValues, findTemplateVarChanges, getCurrentText, getVariableRefresh, isAllVariable } from './utils';
import { VariableRefresh } from './types';
import { UrlQueryMap } from '@grafana/data';
@ -157,3 +157,19 @@ describe('findTemplateVarChanges', () => {
expect(findTemplateVarChanges(a, b)!['var-test']).toEqual(['test']);
});
});
describe('ensureStringValues', () => {
it.each`
value | expected
${null} | ${''}
${undefined} | ${''}
${{}} | ${''}
${{ current: {} }} | ${''}
${1} | ${'1'}
${[1, 2]} | ${['1', '2']}
${'1'} | ${'1'}
${['1', '2']} | ${['1', '2']}
`('when called with value:$value then result should be:$expected', ({ value, expected }) => {
expect(ensureStringValues(value)).toEqual(expected);
});
});