Skip to content

Commit

Permalink
[Security Solution] [Case] Fix Jira connector test form (#87580) (#87655
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stephmilovic authored Jan 8, 2021
1 parent f20a74f commit 5108bb3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ describe('JiraParamsFields renders', () => {
},
},
};
const useGetFieldsByIssueTypeResponseNoPriority = {
...useGetFieldsByIssueTypeResponse,
fields: {
summary: { allowedValues: [], defaultValue: {} },
labels: { allowedValues: [], defaultValue: {} },
description: { allowedValues: [], defaultValue: {} },
},
};

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -386,5 +394,22 @@ describe('JiraParamsFields renders', () => {
expect(comments.simulate('change', emptyComment));
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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,27 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
});
const editSubActionProperty = useCallback(
(key: string, value: any) => {
const newProps =
key !== 'comments'
? {
incident: { ...incident, [key]: value },
comments,
}
: { incident, [key]: value };
editAction('subActionParams', newProps, index);
if (key === 'issueType') {
return editAction(
'subActionParams',
{
incident: { issueType: value },
comments,
},
index
);
}
if (key === 'comments') {
return editAction('subActionParams', { incident, comments: value }, index);
}
return editAction(
'subActionParams',
{
incident: { ...incident, [key]: value },
comments,
},
index
);
},
[comments, editAction, incident, index]
);
Expand Down Expand Up @@ -114,6 +127,7 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
if (incident.issueType != null && fields != null) {
const priorities = fields.priority != null ? fields.priority.allowedValues : [];
const doesPriorityExist = priorities.some((p) => p.name === incident.priority);

if ((!incident.priority || !doesPriorityExist) && priorities.length > 0) {
editSubActionProperty('priority', priorities[0].name ?? '');
}
Expand All @@ -126,6 +140,12 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
}
return [];
}, [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(
() => (incident.labels ? incident.labels.map((label: string) => ({ label })) : []),
Expand Down

0 comments on commit 5108bb3

Please sign in to comment.