2022-04-22 08:33:13 -05:00
|
|
|
import { DataSourceApi } from '@grafana/data';
|
|
|
|
|
|
|
|
import { LegacyVariableQueryEditor } from './LegacyVariableQueryEditor';
|
2022-02-07 16:31:42 -06:00
|
|
|
import {
|
|
|
|
AdHocVariableEditorState,
|
|
|
|
DataSourceVariableEditorState,
|
|
|
|
initialVariableEditorState,
|
|
|
|
QueryVariableEditorState,
|
|
|
|
} from './reducer';
|
2022-04-22 08:33:13 -05:00
|
|
|
import {
|
|
|
|
getAdhocVariableEditorState,
|
|
|
|
getDatasourceVariableEditorState,
|
|
|
|
getQueryVariableEditorState,
|
|
|
|
} from './selectors';
|
2022-02-07 16:31:42 -06:00
|
|
|
|
|
|
|
const adhocExtended: AdHocVariableEditorState = {
|
2022-08-25 02:56:45 -05:00
|
|
|
infoText: 'infoText',
|
2022-02-07 16:31:42 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
const datasourceExtended: DataSourceVariableEditorState = {
|
|
|
|
dataSourceTypes: [
|
|
|
|
{ text: 'Prometheus', value: 'ds-prom' },
|
|
|
|
{ text: 'Loki', value: 'ds-loki' },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const queryExtended: QueryVariableEditorState = {
|
|
|
|
VariableQueryEditor: LegacyVariableQueryEditor,
|
|
|
|
dataSource: {} as unknown as DataSourceApi,
|
|
|
|
};
|
|
|
|
|
|
|
|
const adhocVariableState = {
|
|
|
|
...initialVariableEditorState,
|
|
|
|
extended: adhocExtended,
|
|
|
|
};
|
|
|
|
|
|
|
|
const datasourceVariableState = {
|
|
|
|
...initialVariableEditorState,
|
|
|
|
extended: datasourceExtended,
|
|
|
|
};
|
|
|
|
|
|
|
|
const queryVariableState = {
|
|
|
|
...initialVariableEditorState,
|
|
|
|
extended: queryExtended,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('getAdhocVariableEditorState', () => {
|
|
|
|
it('returns the extended properties for adhoc variable state', () => {
|
|
|
|
expect(getAdhocVariableEditorState(adhocVariableState)).toBe(adhocExtended);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for datasource variable state', () => {
|
|
|
|
expect(getAdhocVariableEditorState(datasourceVariableState)).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for query variable state', () => {
|
|
|
|
expect(getAdhocVariableEditorState(queryVariableState)).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getDatasourceVariableEditorState', () => {
|
|
|
|
it('returns the extended properties for datasource variable state', () => {
|
|
|
|
expect(getDatasourceVariableEditorState(datasourceVariableState)).toBe(datasourceExtended);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for adhoc variable state', () => {
|
|
|
|
expect(getDatasourceVariableEditorState(adhocVariableState)).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for query variable state', () => {
|
|
|
|
expect(getDatasourceVariableEditorState(queryVariableState)).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getQueryVariableEditorState', () => {
|
|
|
|
it('returns the extended properties for query variable state', () => {
|
|
|
|
expect(getQueryVariableEditorState(queryVariableState)).toBe(queryExtended);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for adhoc variable state', () => {
|
|
|
|
expect(getQueryVariableEditorState(adhocVariableState)).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for datasource variable state', () => {
|
|
|
|
expect(getQueryVariableEditorState(datasourceVariableState)).toBeNull();
|
|
|
|
});
|
|
|
|
});
|