The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/variables/editor/selectors.test.ts

89 lines
2.6 KiB

import {
getAdhocVariableEditorState,
getDatasourceVariableEditorState,
getQueryVariableEditorState,
} from './selectors';
import {
AdHocVariableEditorState,
DataSourceVariableEditorState,
initialVariableEditorState,
QueryVariableEditorState,
} from './reducer';
import { LegacyVariableQueryEditor } from './LegacyVariableQueryEditor';
import { DataSourceApi } from '@grafana/data';
const adhocExtended: AdHocVariableEditorState = {
dataSources: [
{ text: 'Prometheus', value: null }, // default datasource
{ text: 'Loki', value: { type: 'loki-ds', uid: 'abc' } },
],
};
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();
});
});