[Cases][Observability] Do not sync alerts status with case status (#114318)

* set sync status according to disable alerts

* Adding test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jonathan Buttner 2021-10-11 12:55:06 -04:00 committed by GitHub
parent c8a0108269
commit badc77828e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -239,6 +239,29 @@ describe('Create case', () => {
);
});
it('should set sync alerts to false when the sync setting is passed in as false and alerts are disabled', async () => {
useConnectorsMock.mockReturnValue({
...sampleConnectorData,
connectors: connectorsMock,
});
const wrapper = mount(
<TestProviders>
<FormContext onSuccess={onFormSubmitSuccess} syncAlertsDefaultValue={false}>
<CreateCaseForm {...defaultCreateCaseForm} disableAlerts={true} />
<SubmitCaseButton />
</FormContext>
</TestProviders>
);
fillForm(wrapper);
wrapper.find(`[data-test-subj="create-case-submit"]`).first().simulate('click');
await waitFor(() =>
expect(postCase).toBeCalledWith({ ...sampleData, settings: { syncAlerts: false } })
);
});
it('it should select the default connector set in the configuration', async () => {
useCaseConfigureMock.mockImplementation(() => ({
...useCaseConfigureResponse,

View file

@ -34,6 +34,7 @@ interface Props {
children?: JSX.Element | JSX.Element[];
hideConnectorServiceNowSir?: boolean;
onSuccess?: (theCase: Case) => Promise<void>;
syncAlertsDefaultValue?: boolean;
}
export const FormContext: React.FC<Props> = ({
@ -42,6 +43,7 @@ export const FormContext: React.FC<Props> = ({
children,
hideConnectorServiceNowSir,
onSuccess,
syncAlertsDefaultValue = true,
}) => {
const { connectors, loading: isLoadingConnectors } = useConnectors();
const owner = useOwnerContext();
@ -51,7 +53,12 @@ export const FormContext: React.FC<Props> = ({
const submitCase = useCallback(
async (
{ connectorId: dataConnectorId, fields, syncAlerts = true, ...dataWithoutConnectorId },
{
connectorId: dataConnectorId,
fields,
syncAlerts = syncAlertsDefaultValue,
...dataWithoutConnectorId
},
isValid
) => {
if (isValid) {
@ -94,6 +101,7 @@ export const FormContext: React.FC<Props> = ({
onSuccess,
postComment,
pushCaseToExternalService,
syncAlertsDefaultValue,
]
);

View file

@ -58,6 +58,8 @@ const CreateCaseComponent = ({
caseType={caseType}
hideConnectorServiceNowSir={hideConnectorServiceNowSir}
onSuccess={onSuccess}
// if we are disabling alerts, then we should not sync alerts
syncAlertsDefaultValue={!disableAlerts}
>
<CreateCaseForm
hideConnectorServiceNowSir={hideConnectorServiceNowSir}