|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
import { UrlQueryMap } from '@grafana/data'; |
|
|
|
|
import { locationService } from '@grafana/runtime'; |
|
|
|
|
|
|
|
|
|
import { VariableRefresh } from './types'; |
|
|
|
|
import { |
|
|
|
|
@ -7,9 +8,17 @@ import { |
|
|
|
|
findTemplateVarChanges, |
|
|
|
|
getCurrentText, |
|
|
|
|
getVariableRefresh, |
|
|
|
|
getVariablesFromUrl, |
|
|
|
|
isAllVariable, |
|
|
|
|
} from './utils'; |
|
|
|
|
|
|
|
|
|
jest.mock('@grafana/runtime', () => ({ |
|
|
|
|
...jest.requireActual('@grafana/runtime'), |
|
|
|
|
getTemplateSrv: () => ({ |
|
|
|
|
getVariables: () => [{ name: 'query0' }, { name: 'query1' }], |
|
|
|
|
}), |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
describe('isAllVariable', () => { |
|
|
|
|
it.each` |
|
|
|
|
variable | expected |
|
|
|
|
@ -202,3 +211,22 @@ describe('containsVariable', () => { |
|
|
|
|
expect(containsVariable(value, 'var')).toEqual(expected); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('getVariablesFromUrl', () => { |
|
|
|
|
it('when called with simple var values for a var, then it returns just the value', () => { |
|
|
|
|
locationService.push('/test?orgId=1&var-query0=1&var-query1=value1'); |
|
|
|
|
const expected = { |
|
|
|
|
query0: '1', |
|
|
|
|
query1: 'value1', |
|
|
|
|
}; |
|
|
|
|
expect(getVariablesFromUrl()).toEqual(expected); |
|
|
|
|
}); |
|
|
|
|
it('when called with multiple var values for the same var, then it returns the correct array', () => { |
|
|
|
|
locationService.push('/test?orgId=1&var-query0=1&var-query1=value1&var-query1=value2&var-query1=value3'); |
|
|
|
|
const expected = { |
|
|
|
|
query0: '1', |
|
|
|
|
query1: ['value1', 'value2', 'value3'], |
|
|
|
|
}; |
|
|
|
|
expect(getVariablesFromUrl()).toEqual(expected); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|