Skip to content

Commit

Permalink
fix bug when clicking on start a new case (elastic#74092) (elastic#74123
Browse files Browse the repository at this point in the history
)
  • Loading branch information
XavierM committed Aug 3, 2020
1 parent 78a4824 commit da11dfc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { mount } from 'enzyme';

import { useKibana } from '../../../../common/lib/kibana';
import '../../../../common/mock/match_media';
import { createUseKibanaMock, TestProviders } from '../../../../common/mock';
import { NoCases } from '.';

jest.mock('../../../../common/lib/kibana');

const useKibanaMock = useKibana as jest.Mock;

let navigateToApp: jest.Mock;

describe('RecentCases', () => {
beforeEach(() => {
jest.resetAllMocks();
navigateToApp = jest.fn();
const kibanaMock = createUseKibanaMock()();
useKibanaMock.mockReturnValue({
...kibanaMock,
services: {
application: {
navigateToApp,
getUrlForApp: jest.fn(),
},
},
});
});

it('if no cases, you should be able to create a case by clicking on the link "start a new case"', () => {
const wrapper = mount(
<TestProviders>
<NoCases />
</TestProviders>
);
wrapper.find(`[data-test-subj="no-cases-create-case"]`).first().simulate('click');
expect(navigateToApp).toHaveBeenCalledWith('securitySolution:case', {
path:
"/create?timerange=(global:(linkTo:!(timeline),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now-24h,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now)),timeline:(linkTo:!(global),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now-24h,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now)))",
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const NoCasesComponent = () => {
const goToCreateCase = useCallback(
(ev) => {
ev.preventDefault();
navigateToApp(`${APP_ID}:${SecurityPageName.hosts}`, {
navigateToApp(`${APP_ID}:${SecurityPageName.case}`, {
path: getCreateCaseUrl(search),
});
},
Expand All @@ -30,6 +30,7 @@ const NoCasesComponent = () => {
const newCaseLink = useMemo(
() => (
<LinkAnchor
data-test-subj="no-cases-create-case"
onClick={goToCreateCase}
href={formatUrl(getCreateCaseUrl())}
>{` ${i18n.START_A_NEW_CASE}`}</LinkAnchor>
Expand Down

0 comments on commit da11dfc

Please sign in to comment.