Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alerting: Fix queries and expressions in rule view details. (#79497)
* fix queries and expressions in rule-view details * Add test
- Loading branch information
1 parent
4c6bbab
commit 6fffbe4
Showing
2 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
public/app/features/alerting/unified/GrafanaRuleQueryViewer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { render } from '@testing-library/react'; | ||
import { noop } from 'lodash'; | ||
import React from 'react'; | ||
|
||
import { DataSourceRef } from '@grafana/schema'; | ||
import { AlertQuery } from 'app/types/unified-alerting-dto'; | ||
|
||
import { GrafanaRuleQueryViewer } from './GrafanaRuleQueryViewer'; | ||
|
||
describe('GrafanaRuleQueryViewer', () => { | ||
it('renders without crashing', () => { | ||
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: '' }), | ||
]; | ||
const { getByTestId } = render( | ||
<GrafanaRuleQueryViewer queries={[...queries, ...expressions]} condition="A" onTimeRangeChange={noop} /> | ||
); | ||
expect(getByTestId('queries-container')).toHaveStyle('flex-wrap: wrap'); | ||
expect(getByTestId('expressions-container')).toHaveStyle('flex-wrap: wrap'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters