|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { DataSourcePluginMeta, DataSourceSelectItem } from '@grafana/data'; |
|
|
|
|
import { DataSourceInstanceSettings, DataSourcePluginMeta } from '@grafana/data'; |
|
|
|
|
|
|
|
|
|
import { variableAdapters } from '../adapters'; |
|
|
|
|
import { createAdHocVariableAdapter } from './adapter'; |
|
|
|
@ -22,14 +22,14 @@ import { changeVariableEditorExtended, setIdInEditor } from '../editor/reducer'; |
|
|
|
|
import { adHocBuilder } from '../shared/testing/builders'; |
|
|
|
|
import { locationService } from '@grafana/runtime'; |
|
|
|
|
|
|
|
|
|
const getMetricSources = jest.fn().mockReturnValue([]); |
|
|
|
|
const getList = jest.fn().mockReturnValue([]); |
|
|
|
|
const getDatasource = jest.fn().mockResolvedValue({}); |
|
|
|
|
|
|
|
|
|
locationService.partial = jest.fn(); |
|
|
|
|
jest.mock('app/features/plugins/datasource_srv', () => ({ |
|
|
|
|
getDatasourceSrv: jest.fn(() => ({ |
|
|
|
|
get: getDatasource, |
|
|
|
|
getMetricSources, |
|
|
|
|
getList, |
|
|
|
|
})), |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
@ -351,7 +351,7 @@ describe('adhoc actions', () => { |
|
|
|
|
describe('when initAdHocVariableEditor is dispatched', () => { |
|
|
|
|
it('then correct actions are dispatched', async () => { |
|
|
|
|
const datasources = [ |
|
|
|
|
{ ...createDatasource('default', true), value: null }, |
|
|
|
|
{ ...createDatasource('default', true, true), value: null }, |
|
|
|
|
createDatasource('elasticsearch-v1'), |
|
|
|
|
createDatasource('loki', false), |
|
|
|
|
createDatasource('influx'), |
|
|
|
@ -359,19 +359,19 @@ describe('adhoc actions', () => { |
|
|
|
|
createDatasource('elasticsearch-v7'), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
getMetricSources.mockRestore(); |
|
|
|
|
getMetricSources.mockReturnValue(datasources); |
|
|
|
|
getList.mockRestore(); |
|
|
|
|
getList.mockReturnValue(datasources); |
|
|
|
|
|
|
|
|
|
const tester = reduxTester<RootReducerType>() |
|
|
|
|
.givenRootReducer(getRootReducer()) |
|
|
|
|
.whenActionIsDispatched(initAdHocVariableEditor()); |
|
|
|
|
|
|
|
|
|
const expectedDatasources = [ |
|
|
|
|
{ text: '', value: '' }, |
|
|
|
|
{ text: 'default (default)', value: null }, |
|
|
|
|
{ text: 'elasticsearch-v1', value: 'elasticsearch-v1' }, |
|
|
|
|
{ text: 'influx', value: 'influx' }, |
|
|
|
|
{ text: 'elasticsearch-v7', value: 'elasticsearch-v7' }, |
|
|
|
|
{ text: '', value: {} }, |
|
|
|
|
{ text: 'default (default)', value: { uid: 'default', type: 'default' } }, |
|
|
|
|
{ text: 'elasticsearch-v1', value: { uid: 'elasticsearch-v1', type: 'elasticsearch-v1' } }, |
|
|
|
|
{ text: 'influx', value: { uid: 'influx', type: 'influx' } }, |
|
|
|
|
{ text: 'elasticsearch-v7', value: { uid: 'elasticsearch-v7', type: 'elasticsearch-v7' } }, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsShouldEqual( |
|
|
|
@ -438,12 +438,14 @@ function createAddVariableAction(variable: VariableModel, index = 0) { |
|
|
|
|
return addVariable(toVariablePayload(identifier, data)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function createDatasource(name: string, selectable = true): DataSourceSelectItem { |
|
|
|
|
function createDatasource(name: string, selectable = true, isDefault = false): DataSourceInstanceSettings { |
|
|
|
|
return { |
|
|
|
|
name, |
|
|
|
|
value: name, |
|
|
|
|
meta: { |
|
|
|
|
mixed: !selectable, |
|
|
|
|
} as DataSourcePluginMeta, |
|
|
|
|
}; |
|
|
|
|
isDefault, |
|
|
|
|
uid: name, |
|
|
|
|
type: name, |
|
|
|
|
} as DataSourceInstanceSettings; |
|
|
|
|
} |
|
|
|
|