mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
* fix any's in tests * fix more any's in tests * more test type fixes * fixing any's in tests part 3 * more test type fixes * fixing test any's p5 * some tidy up * fix template_srv
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { DataSourceInstanceSettings } from '@grafana/data';
|
|
import { backendSrv } from 'app/core/services/backend_srv';
|
|
|
|
import { ExpressionDatasourceApi } from './ExpressionDatasource';
|
|
import { ExpressionQueryType } from './types';
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
...jest.requireActual('@grafana/runtime'),
|
|
getBackendSrv: () => backendSrv,
|
|
getTemplateSrv: () => ({
|
|
replace: (val: string) => (val ? val.replace('$input', '10').replace('$window', '10s') : val),
|
|
}),
|
|
}));
|
|
|
|
describe('ExpressionDatasourceApi', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('expression queries with template variables', () => {
|
|
it('should interpolate template variables in expression query', () => {
|
|
const ds = new ExpressionDatasourceApi({} as DataSourceInstanceSettings);
|
|
const query = ds.applyTemplateVariables(
|
|
{ type: ExpressionQueryType.math, refId: 'B', expression: '$input + 5 + $A' },
|
|
{}
|
|
);
|
|
expect(query.expression).toBe('10 + 5 + $A');
|
|
});
|
|
it('should interpolate template variables in expression query', () => {
|
|
const ds = new ExpressionDatasourceApi({} as DataSourceInstanceSettings);
|
|
const query = ds.applyTemplateVariables(
|
|
{ type: ExpressionQueryType.resample, refId: 'B', window: '$window' },
|
|
{}
|
|
);
|
|
expect(query.window).toBe('10s');
|
|
});
|
|
});
|
|
});
|