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/features/variables/datasource/DataSourceVariableEditor.te...

55 lines
1.9 KiB

import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { DataSourceVariableEditorUnConnected as DataSourceVariableEditor } from './DataSourceVariableEditor';
import { initialDataSourceVariableModelState } from './reducer';
import { selectOptionInTest } from '@grafana/ui';
import { getSelectParent } from '@grafana/ui/src/components/Select/test-utils';
const props = {
extended: {
dataSourceTypes: [
{ text: 'Prometheus', value: 'ds-prom' },
{ text: 'Loki', value: 'ds-loki' },
],
},
variable: { ...initialDataSourceVariableModelState },
onPropChange: jest.fn(),
// connected actions
initDataSourceVariableEditor: jest.fn(),
changeVariableMultiValue: jest.fn(),
};
describe('DataSourceVariableEditor', () => {
beforeEach(() => {
props.onPropChange.mockReset();
});
it('has a data source select menu', () => {
render(<DataSourceVariableEditor {...props} />);
const selectContainer = getSelectParent(screen.getByLabelText('Type'));
expect(selectContainer).toHaveTextContent('Prometheus');
});
it('calls the handler when the data source is changed', async () => {
render(<DataSourceVariableEditor {...props} />);
await selectOptionInTest(screen.getByLabelText('Type'), 'Loki');
expect(props.onPropChange).toBeCalledWith({ propName: 'query', propValue: 'ds-loki', updateOptions: true });
});
it('has a regex filter field', () => {
render(<DataSourceVariableEditor {...props} />);
const field = screen.getByLabelText('Instance name filter');
expect(field).toBeInTheDocument();
});
it('calls the handler when the regex filter is changed', () => {
render(<DataSourceVariableEditor {...props} />);
const field = screen.getByLabelText('Instance name filter');
fireEvent.change(field, { target: { value: '/prod/' } });
expect(props.onPropChange).toBeCalledWith({ propName: 'regex', propValue: '/prod/' });
});
});