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/loki/querybuilder/components/LokiQueryCodeEditor.test.tsx

46 lines
1.5 KiB

import { render, screen } from '@testing-library/react';
import React from 'react';
import { createLokiDatasource } from '../../mocks';
import { LokiQuery } from '../../types';
import { EXPLAIN_LABEL_FILTER_CONTENT } from './LokiQueryBuilderExplained';
import { LokiQueryCodeEditor } from './LokiQueryCodeEditor';
const defaultQuery: LokiQuery = {
expr: '{job="bar}',
refId: 'A',
};
const createDefaultProps = () => {
const datasource = createLokiDatasource();
const props = {
datasource,
onRunQuery: () => {},
onChange: () => {},
showExplain: false,
setQueryStats: () => {},
};
return props;
};
describe('LokiQueryCodeEditor', () => {
it('shows explain section when showExplain is true', async () => {
const props = createDefaultProps();
props.showExplain = true;
props.datasource.metadataRequest = jest.fn().mockResolvedValue([]);
render(<LokiQueryCodeEditor {...props} query={defaultQuery} />);
expect(await screen.findByText('Loading...')).toBeInTheDocument();
expect(screen.getByText(EXPLAIN_LABEL_FILTER_CONTENT)).toBeInTheDocument();
});
it('does not show explain section when showExplain is false', async () => {
const props = createDefaultProps();
props.datasource.metadataRequest = jest.fn().mockResolvedValue([]);
render(<LokiQueryCodeEditor {...props} query={defaultQuery} />);
expect(await screen.findByText('Loading...')).toBeInTheDocument();
expect(screen.queryByText(EXPLAIN_LABEL_FILTER_CONTENT)).not.toBeInTheDocument();
});
});