From da11dfc6a42bac3c9f5381ccd9df5dae2b7465e4 Mon Sep 17 00:00:00 2001
From: Xavier Mouligneau <189600+XavierM@users.noreply.github.com>
Date: Mon, 3 Aug 2020 15:18:46 -0400
Subject: [PATCH] fix bug when clicking on start a new case (#74092) (#74123)
---
.../recent_cases/no_cases/index.test.tsx | 49 +++++++++++++++++++
.../recent_cases/no_cases/index.tsx | 3 +-
2 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx
diff --git a/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx
new file mode 100644
index 00000000000000..99902a31975d0d
--- /dev/null
+++ b/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx
@@ -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(
+
+
+
+ );
+ 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)))",
+ });
+ });
+});
diff --git a/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.tsx b/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.tsx
index 40969a6e1df4a6..875a678f322266 100644
--- a/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.tsx
+++ b/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.tsx
@@ -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),
});
},
@@ -30,6 +30,7 @@ const NoCasesComponent = () => {
const newCaseLink = useMemo(
() => (
{` ${i18n.START_A_NEW_CASE}`}