Skip to content

Commit

Permalink
fix bug to add timeline to case
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Jun 30, 2020
1 parent 7c9db86 commit afeaf78
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('../../../../common/lib/kibana', () => {
useKibana: jest.fn().mockReturnValue({
services: {
application: {
navigateToApp: jest.fn(),
navigateToApp: () => Promise.resolve(),
capabilities: {
siem: {
crud: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,21 @@ export const NewCase = React.memo<NewCaseProps>(

const handleClick = useCallback(() => {
onClosePopover();
dispatch(
setInsertTimeline({
graphEventId,
timelineId,
timelineSavedObjectId: savedObjectId,
timelineTitle: timelineTitle.length > 0 ? timelineTitle : i18n.UNTITLED_TIMELINE,
})
);

dispatch(showTimeline({ id: TimelineId.active, show: false }));

navigateToApp(`${APP_ID}:${SecurityPageName.case}`, {
path: getCreateCaseUrl(),
});
}).then(() =>
dispatch(
setInsertTimeline({
graphEventId,
timelineId,
timelineSavedObjectId: savedObjectId,
timelineTitle: timelineTitle.length > 0 ? timelineTitle : i18n.UNTITLED_TIMELINE,
})
)
);
}, [
dispatch,
graphEventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { act } from 'react-dom/test-utils';

jest.mock('../../../../common/components/link_to');

const mockNavigateToApp = jest.fn();
const mockNavigateToApp = jest.fn().mockImplementation(() => Promise.resolve());
jest.mock('../../../../common/lib/kibana', () => {
const original = jest.requireActual('../../../../common/lib/kibana');

Expand Down Expand Up @@ -369,6 +369,11 @@ describe('Properties', () => {
);
wrapper.find('[data-test-subj="settings-gear"]').at(0).simulate('click');
wrapper.find('[data-test-subj="attach-timeline-case"]').first().simulate('click');

await act(async () => {
await Promise.resolve({});
});

expect(mockNavigateToApp).toBeCalledWith('securitySolution:case', { path: '/create' });
expect(mockDispatch).toBeCalledWith(
setInsertTimeline({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ export const Properties = React.memo<Props>(
(id: string) => {
onCloseCaseModal();

dispatch(
setInsertTimeline({
graphEventId,
timelineId,
timelineSavedObjectId: currentTimeline.savedObjectId,
timelineTitle: title.length > 0 ? title : i18n.UNTITLED_TIMELINE,
})
);

navigateToApp(`${APP_ID}:${SecurityPageName.case}`, {
path: getCaseDetailsUrl({ id }),
});
}).then(() =>
dispatch(
setInsertTimeline({
graphEventId,
timelineId,
timelineSavedObjectId: currentTimeline.savedObjectId,
timelineTitle: title.length > 0 ? title : i18n.UNTITLED_TIMELINE,
})
)
);
},
[currentTimeline, dispatch, graphEventId, navigateToApp, onCloseCaseModal, timelineId, title]
);
Expand Down

0 comments on commit afeaf78

Please sign in to comment.