mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 12:12:21 +08:00
Variables: Fixes issue with All variable not being resolved (#27151)
* Variables: Fixes issue with All variable not being resolved * Tests: update tests according to changes
This commit is contained in:
49
public/app/features/variables/utils.test.ts
Normal file
49
public/app/features/variables/utils.test.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { getCurrentText, isAllVariable } from './utils';
|
||||
|
||||
describe('isAllVariable', () => {
|
||||
it.each`
|
||||
variable | expected
|
||||
${null} | ${false}
|
||||
${undefined} | ${false}
|
||||
${{}} | ${false}
|
||||
${{ current: {} }} | ${false}
|
||||
${{ current: { text: '' } }} | ${false}
|
||||
${{ current: { text: null } }} | ${false}
|
||||
${{ current: { text: undefined } }} | ${false}
|
||||
${{ current: { text: 'Alll' } }} | ${false}
|
||||
${{ current: { text: 'All' } }} | ${true}
|
||||
${{ current: { text: [] } }} | ${false}
|
||||
${{ current: { text: [null] } }} | ${false}
|
||||
${{ current: { text: [undefined] } }} | ${false}
|
||||
${{ current: { text: ['Alll'] } }} | ${false}
|
||||
${{ current: { text: ['Alll', 'All'] } }} | ${false}
|
||||
${{ current: { text: ['All'] } }} | ${true}
|
||||
${{ current: { text: { prop1: 'test' } } }} | ${false}
|
||||
`("when called with params: 'variable': '$variable' then result should be '$expected'", ({ variable, expected }) => {
|
||||
expect(isAllVariable(variable)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCurrentText', () => {
|
||||
it.each`
|
||||
variable | expected
|
||||
${null} | ${''}
|
||||
${undefined} | ${''}
|
||||
${{}} | ${''}
|
||||
${{ current: {} }} | ${''}
|
||||
${{ current: { text: '' } }} | ${''}
|
||||
${{ current: { text: null } }} | ${''}
|
||||
${{ current: { text: undefined } }} | ${''}
|
||||
${{ current: { text: 'A' } }} | ${'A'}
|
||||
${{ current: { text: 'All' } }} | ${'All'}
|
||||
${{ current: { text: [] } }} | ${''}
|
||||
${{ current: { text: [null] } }} | ${''}
|
||||
${{ current: { text: [undefined] } }} | ${''}
|
||||
${{ current: { text: ['A'] } }} | ${'A'}
|
||||
${{ current: { text: ['A', 'All'] } }} | ${'A,All'}
|
||||
${{ current: { text: ['All'] } }} | ${'All'}
|
||||
${{ current: { text: { prop1: 'test' } } }} | ${''}
|
||||
`("when called with params: 'variable': '$variable' then result should be '$expected'", ({ variable, expected }) => {
|
||||
expect(getCurrentText(variable)).toEqual(expected);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user