mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Pyroscope: Decouple from templateSrv (#79068)
* Decouple templateSrv * Update test
This commit is contained in:
parent
e3d14307ed
commit
4751013a91
@ -17,6 +17,13 @@ jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
setPluginExtensionGetter: jest.fn(),
|
||||
getPluginLinkExtensions: jest.fn(),
|
||||
getTemplateSrv: () => {
|
||||
return {
|
||||
replace: (query: string): string => {
|
||||
return query.replace(/\$var/g, 'interpolated');
|
||||
},
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
const getPluginLinkExtensionsMock = jest.mocked(getPluginLinkExtensions);
|
||||
|
@ -2,12 +2,24 @@ import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { DataSourceInstanceSettings } from '@grafana/data';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { getTemplateSrv } from '@grafana/runtime';
|
||||
|
||||
import { VariableQueryEditor } from './VariableQueryEditor';
|
||||
import { PyroscopeDataSource } from './datasource';
|
||||
import { PyroscopeDataSourceOptions } from './types';
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
const actual = jest.requireActual('@grafana/runtime');
|
||||
return {
|
||||
...actual,
|
||||
getTemplateSrv: () => {
|
||||
return {
|
||||
replace: jest.fn(),
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('VariableQueryEditor', () => {
|
||||
it('renders correctly with type profileType', () => {
|
||||
render(
|
||||
@ -69,7 +81,7 @@ describe('VariableQueryEditor', () => {
|
||||
});
|
||||
|
||||
function getMockDatasource() {
|
||||
const ds = new PyroscopeDataSource({} as DataSourceInstanceSettings<PyroscopeDataSourceOptions>, new TemplateSrv());
|
||||
const ds = new PyroscopeDataSource({} as DataSourceInstanceSettings<PyroscopeDataSourceOptions>, getTemplateSrv());
|
||||
ds.getResource = jest.fn();
|
||||
(ds.getResource as jest.Mock).mockImplementation(async (type: string) => {
|
||||
if (type === 'profileTypes') {
|
||||
|
@ -6,13 +6,26 @@ import {
|
||||
PluginType,
|
||||
DataSourceJsonData,
|
||||
} from '@grafana/data';
|
||||
import { setPluginExtensionGetter, getBackendSrv, setBackendSrv } from '@grafana/runtime';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { setPluginExtensionGetter, getBackendSrv, setBackendSrv, getTemplateSrv } from '@grafana/runtime';
|
||||
|
||||
import { defaultPyroscopeQueryType } from './dataquery.gen';
|
||||
import { normalizeQuery, PyroscopeDataSource } from './datasource';
|
||||
import { Query } from './types';
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
const actual = jest.requireActual('@grafana/runtime');
|
||||
return {
|
||||
...actual,
|
||||
getTemplateSrv: () => {
|
||||
return {
|
||||
replace: (query: string): string => {
|
||||
return query.replace(/\$var/g, 'interpolated');
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
/** The datasource QueryEditor fetches datasource settings to send to the extension's `configure` method */
|
||||
export function mockFetchPyroscopeDatasourceSettings(
|
||||
datasourceSettings?: Partial<DataSourceInstanceSettings<DataSourceJsonData>>
|
||||
@ -80,10 +93,7 @@ describe('Pyroscope data source', () => {
|
||||
});
|
||||
|
||||
describe('applyTemplateVariables', () => {
|
||||
const templateSrv = new TemplateSrv();
|
||||
templateSrv.replace = jest.fn((query: string): string => {
|
||||
return query.replace(/\$var/g, 'interpolated');
|
||||
});
|
||||
const templateSrv = getTemplateSrv();
|
||||
|
||||
it('should not update labelSelector if there are no template variables', () => {
|
||||
ds = new PyroscopeDataSource(defaultSettings, templateSrv);
|
||||
|
Loading…
Reference in New Issue
Block a user