123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { DataSourceApi } from '@grafana/data';
- import { LegacyVariableQueryEditor } from './LegacyVariableQueryEditor';
- import {
- AdHocVariableEditorState,
- DataSourceVariableEditorState,
- initialVariableEditorState,
- QueryVariableEditorState,
- } from './reducer';
- import {
- getAdhocVariableEditorState,
- getDatasourceVariableEditorState,
- getQueryVariableEditorState,
- } from './selectors';
- 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();
- });
- });
|