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/plugins/datasource/tempo/VariableQueryEditor.test.tsx

69 lines
2.0 KiB

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
import { TemplateSrv } from '@grafana/runtime';
import {
TempoVariableQuery,
TempoVariableQueryEditor,
TempoVariableQueryEditorProps,
TempoVariableQueryType,
} from './VariableQueryEditor';
import { createTempoDatasource } from './mocks';
const refId = 'TempoDatasourceVariableQueryEditor-VariableQuery';
describe('TempoVariableQueryEditor', () => {
let props: TempoVariableQueryEditorProps;
let onChange: (value: TempoVariableQuery) => void;
beforeEach(() => {
props = {
datasource: createTempoDatasource({} as unknown as TemplateSrv),
query: { type: 0, refId: 'test' },
onChange: (_: TempoVariableQuery) => {},
};
onChange = jest.fn();
});
test('Allows to create a Label names variable', async () => {
expect(onChange).not.toHaveBeenCalled();
render(<TempoVariableQueryEditor {...props} onChange={onChange} />);
await selectOptionInTest(screen.getByLabelText('Query type'), 'Label names');
await userEvent.click(document.body);
expect(onChange).toHaveBeenCalledWith({
type: TempoVariableQueryType.LabelNames,
label: '',
refId,
});
});
test('Allows to create a Label values variable', async () => {
jest.spyOn(props.datasource, 'labelNamesQuery').mockResolvedValue([
{
text: 'moon',
},
{
text: 'luna',
},
]);
expect(onChange).not.toHaveBeenCalled();
render(<TempoVariableQueryEditor {...props} onChange={onChange} />);
await selectOptionInTest(screen.getByLabelText('Query type'), 'Label values');
await selectOptionInTest(screen.getByLabelText('Label'), 'luna');
await userEvent.click(document.body);
expect(onChange).toHaveBeenCalledWith({
type: TempoVariableQueryType.LabelValues,
label: 'luna',
refId,
});
});
});