mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 03:01:21 -04:00
[Security Solution] [Case] Fix Jira connector test form (#87580)
This commit is contained in:
parent
794c6b3b08
commit
130a8e766e
2 changed files with 53 additions and 8 deletions
|
@ -85,6 +85,14 @@ describe('JiraParamsFields renders', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const useGetFieldsByIssueTypeResponseNoPriority = {
|
||||||
|
...useGetFieldsByIssueTypeResponse,
|
||||||
|
fields: {
|
||||||
|
summary: { allowedValues: [], defaultValue: {} },
|
||||||
|
labels: { allowedValues: [], defaultValue: {} },
|
||||||
|
description: { allowedValues: [], defaultValue: {} },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
@ -386,5 +394,22 @@ describe('JiraParamsFields renders', () => {
|
||||||
expect(comments.simulate('change', emptyComment));
|
expect(comments.simulate('change', emptyComment));
|
||||||
expect(editAction.mock.calls.length).toEqual(1);
|
expect(editAction.mock.calls.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
test('Clears any left behind priority when issueType changes and hasPriority becomes false', () => {
|
||||||
|
useGetFieldsByIssueTypeMock
|
||||||
|
.mockReturnValueOnce(useGetFieldsByIssueTypeResponse)
|
||||||
|
.mockReturnValue(useGetFieldsByIssueTypeResponseNoPriority);
|
||||||
|
const wrapper = mount(<JiraParamsFields {...defaultProps} />);
|
||||||
|
wrapper.setProps({
|
||||||
|
...{
|
||||||
|
...defaultProps,
|
||||||
|
actionParams: {
|
||||||
|
...defaultProps.actionParams,
|
||||||
|
incident: { issueType: '10001' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(editAction.mock.calls[0][1].incident.priority).toEqual('Medium');
|
||||||
|
expect(editAction.mock.calls[1][1].incident.priority).toEqual(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,14 +64,27 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
|
||||||
});
|
});
|
||||||
const editSubActionProperty = useCallback(
|
const editSubActionProperty = useCallback(
|
||||||
(key: string, value: any) => {
|
(key: string, value: any) => {
|
||||||
const newProps =
|
if (key === 'issueType') {
|
||||||
key !== 'comments'
|
return editAction(
|
||||||
? {
|
'subActionParams',
|
||||||
incident: { ...incident, [key]: value },
|
{
|
||||||
comments,
|
incident: { issueType: value },
|
||||||
}
|
comments,
|
||||||
: { incident, [key]: value };
|
},
|
||||||
editAction('subActionParams', newProps, index);
|
index
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (key === 'comments') {
|
||||||
|
return editAction('subActionParams', { incident, comments: value }, index);
|
||||||
|
}
|
||||||
|
return editAction(
|
||||||
|
'subActionParams',
|
||||||
|
{
|
||||||
|
incident: { ...incident, [key]: value },
|
||||||
|
comments,
|
||||||
|
},
|
||||||
|
index
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[comments, editAction, incident, index]
|
[comments, editAction, incident, index]
|
||||||
);
|
);
|
||||||
|
@ -114,6 +127,7 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
|
||||||
if (incident.issueType != null && fields != null) {
|
if (incident.issueType != null && fields != null) {
|
||||||
const priorities = fields.priority != null ? fields.priority.allowedValues : [];
|
const priorities = fields.priority != null ? fields.priority.allowedValues : [];
|
||||||
const doesPriorityExist = priorities.some((p) => p.name === incident.priority);
|
const doesPriorityExist = priorities.some((p) => p.name === incident.priority);
|
||||||
|
|
||||||
if ((!incident.priority || !doesPriorityExist) && priorities.length > 0) {
|
if ((!incident.priority || !doesPriorityExist) && priorities.length > 0) {
|
||||||
editSubActionProperty('priority', priorities[0].name ?? '');
|
editSubActionProperty('priority', priorities[0].name ?? '');
|
||||||
}
|
}
|
||||||
|
@ -126,6 +140,12 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}, [editSubActionProperty, fields, incident.issueType, incident.priority]);
|
}, [editSubActionProperty, fields, incident.issueType, incident.priority]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!hasPriority && incident.priority != null) {
|
||||||
|
editSubActionProperty('priority', null);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [hasPriority]);
|
||||||
|
|
||||||
const labelOptions = useMemo(
|
const labelOptions = useMemo(
|
||||||
() => (incident.labels ? incident.labels.map((label: string) => ({ label })) : []),
|
() => (incident.labels ? incident.labels.map((label: string) => ({ label })) : []),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue