mirror of https://github.com/grafana/grafana
Alerting: do not overwrite existing alert rule condition (#49920)
parent
4b1c4f7240
commit
82e9f4e7e7
@ -0,0 +1,39 @@ |
||||
import { render, screen } from '@testing-library/react'; |
||||
import React, { FC } from 'react'; |
||||
import { FormProvider, useForm, UseFormProps } from 'react-hook-form'; |
||||
|
||||
import { ExpressionDatasourceUID } from 'app/features/expressions/ExpressionDatasource'; |
||||
|
||||
import { RuleFormValues } from '../../types/rule-form'; |
||||
|
||||
import { ConditionField } from './ConditionField'; |
||||
|
||||
const FormProviderWrapper: FC<UseFormProps> = ({ children, ...props }) => { |
||||
const methods = useForm({ ...props }); |
||||
return <FormProvider {...methods}>{children}</FormProvider>; |
||||
}; |
||||
|
||||
describe('ConditionField', () => { |
||||
it('should render the correct condition when editing existing rule', () => { |
||||
const existingRule = { |
||||
name: 'ConditionsTest', |
||||
condition: 'B', |
||||
queries: [ |
||||
{ refId: 'A' }, |
||||
{ refId: 'B', datasourceUid: ExpressionDatasourceUID }, |
||||
{ refId: 'C', datasourceUid: ExpressionDatasourceUID }, |
||||
], |
||||
} as RuleFormValues; |
||||
|
||||
const form = ( |
||||
<FormProviderWrapper defaultValues={existingRule}> |
||||
<ConditionField existing={true} /> |
||||
</FormProviderWrapper> |
||||
); |
||||
|
||||
render(form); |
||||
expect(screen.getByLabelText(/^A/)).not.toBeChecked(); |
||||
expect(screen.getByLabelText(/^B/)).toBeChecked(); |
||||
expect(screen.getByLabelText(/^C/)).not.toBeChecked(); |
||||
}); |
||||
}); |
Loading…
Reference in new issue