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/alerting/unified/GrafanaRuleQueryViewer.test...

83 lines
2.2 KiB

import { render, waitFor, screen } from '@testing-library/react';
import { TestProvider } from 'test/helpers/TestProvider';
import { DataSourceRef } from '@grafana/schema';
import { AlertQuery } from 'app/types/unified-alerting-dto';
import { GrafanaRuleQueryViewer } from './GrafanaRuleQueryViewer';
import { mockCombinedRule } from './mocks';
describe('GrafanaRuleQueryViewer', () => {
it('renders without crashing', async () => {
const rule = mockCombinedRule();
const getDataSourceQuery = (refId: string) => {
const query: AlertQuery = {
refId: refId,
datasourceUid: 'abc123',
queryType: '',
relativeTimeRange: {
from: 600,
to: 0,
},
model: {
refId: 'A',
},
};
return query;
};
const queries = [
getDataSourceQuery('A'),
getDataSourceQuery('B'),
getDataSourceQuery('C'),
getDataSourceQuery('D'),
getDataSourceQuery('E'),
];
const getExpression = (refId: string, dsRef: DataSourceRef) => {
const expr = {
refId: refId,
datasourceUid: '__expr__',
queryType: '',
model: {
refId: refId,
type: 'classic_conditions',
datasource: dsRef,
conditions: [
{
type: 'query',
evaluator: {
params: [3],
type: 'gt',
},
operator: {
type: 'and',
},
query: {
params: ['A'],
},
reducer: {
params: [],
type: 'last',
},
},
],
},
};
return expr;
};
const expressions = [
getExpression('A', { type: '' }),
getExpression('B', { type: '' }),
getExpression('C', { type: '' }),
getExpression('D', { type: '' }),
];
render(<GrafanaRuleQueryViewer queries={[...queries, ...expressions]} condition="A" rule={rule} />, {
wrapper: TestProvider,
});
await waitFor(() => expect(screen.getByTestId('queries-container')).toHaveStyle('flex-wrap: wrap'));
expect(screen.getByTestId('expressions-container')).toHaveStyle('flex-wrap: wrap');
});
});