/usr/share/grafana/public/app/plugins/datasource/grafana-pyroscope-datasource
import { render, screen } from '@testing-library/react'; import { DataSourceInstanceSettings } from '@grafana/data'; 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( <VariableQueryEditor datasource={getMockDatasource()} query={{ refId: 'A', type: 'profileType', }} onRunQuery={() => {}} onChange={() => {}} /> ); expect(screen.getByLabelText(/Query type/)).toBeInTheDocument(); }); it('renders correctly with type labels', async () => { render( <VariableQueryEditor datasource={getMockDatasource()} query={{ refId: 'A', type: 'label', profileTypeId: 'profile:type:1', }} onRunQuery={() => {}} onChange={() => {}} /> ); expect(screen.getByLabelText(/Query type/)).toBeInTheDocument(); expect(screen.getByLabelText(/Profile type/)).toBeInTheDocument(); expect(await screen.findByDisplayValue(/profile-type/)).toBeInTheDocument(); }); it('renders correctly with type labelValue', async () => { render( <VariableQueryEditor datasource={getMockDatasource()} query={{ refId: 'A', type: 'labelValue', labelName: 'foo', profileTypeId: 'cpu', }} onRunQuery={() => {}} onChange={() => {}} /> ); expect(screen.getByLabelText(/Query type/)).toBeInTheDocument(); expect(screen.getByLabelText(/Profile type/)).toBeInTheDocument(); // using custom value for change expect(await screen.findByDisplayValue(/cpu/)).toBeInTheDocument(); expect(screen.getByText('Label')).toBeInTheDocument(); expect(await screen.findByText(/foo/)).toBeInTheDocument(); }); }); function getMockDatasource() { const ds = new PyroscopeDataSource({} as DataSourceInstanceSettings<PyroscopeDataSourceOptions>, getTemplateSrv()); ds.getResource = jest.fn(); (ds.getResource as jest.Mock).mockImplementation(async (type: string) => { if (type === 'profileTypes') { return [ { label: 'profile type 1', id: 'profile:type:1' }, { label: 'profile type 2', id: 'profile:type:2' }, { label: 'profile type 3', id: 'profile:type:3' }, ]; } if (type === 'labelNames') { return ['foo', 'bar']; } return ['val1', 'val2']; }); return ds; }
.
Edit
..
Edit
.eslintignore
Edit
CHANGELOG.md
Edit
ConfigEditor.tsx
Edit
QueryEditor
Edit
README.md
Edit
VariableQueryEditor.test.tsx
Edit
VariableQueryEditor.tsx
Edit
VariableSupport.test.ts
Edit
VariableSupport.ts
Edit
dataquery.cue
Edit
dataquery.gen.ts
Edit
datasource.test.ts
Edit
datasource.ts
Edit
dist
Edit
img
Edit
jest-setup.js
Edit
jest.config.js
Edit
mocks.ts
Edit
module.ts
Edit
package.json
Edit
plugin.json
Edit
project.json
Edit
pyroscopeql
Edit
tsconfig.json
Edit
types.ts
Edit
utils.test.ts
Edit
utils.ts
Edit
webpack.config.ts
Edit