From 47b15f908251ce0b3e70bdd62ed9752850d5f1ea Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 23 Nov 2020 20:52:16 +0200 Subject: [PATCH] Fix tests --- .../components/add_comment/index.test.tsx | 2 +- .../cases/components/all_cases/index.test.tsx | 39 +++++++++++++++- .../use_all_cases_modal/index.test.tsx | 45 ++++++++++++++++--- .../timeline_actions/alert_context_menu.tsx | 4 +- .../components/graph_overlay/index.tsx | 5 ++- .../components/timeline/properties/index.tsx | 1 + 6 files changed, 85 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/security_solution/public/cases/components/add_comment/index.test.tsx b/x-pack/plugins/security_solution/public/cases/components/add_comment/index.test.tsx index 50e139bcd215f93..e656c98d36573e9 100644 --- a/x-pack/plugins/security_solution/public/cases/components/add_comment/index.test.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/add_comment/index.test.tsx @@ -77,7 +77,7 @@ describe('AddComment ', () => { await waitFor(() => { expect(onCommentSaving).toBeCalled(); - expect(postComment).toBeCalledWith(sampleData, onCommentPosted); + expect(postComment).toBeCalledWith(addCommentProps.caseId, sampleData, onCommentPosted); expect(wrapper.find(`[data-test-subj="add-comment"] textarea`).text()).toBe(''); }); }); diff --git a/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx b/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx index e301e80c9561d55..4efb522bd80ef2e 100644 --- a/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx @@ -434,7 +434,44 @@ describe('AllCases', () => { ); await waitFor(() => { wrapper.find('[data-test-subj="cases-table-row-1"]').first().simulate('click'); - expect(onRowClick).toHaveBeenCalledWith('1'); + expect(onRowClick).toHaveBeenCalledWith({ + closedAt: null, + closedBy: null, + comments: [], + connector: { fields: null, id: '123', name: 'My Connector', type: '.none' }, + createdAt: '2020-02-19T23:06:33.798Z', + createdBy: { + email: 'leslie.knope@elastic.co', + fullName: 'Leslie Knope', + username: 'lknope', + }, + description: 'Security banana Issue', + externalService: { + connectorId: '123', + connectorName: 'connector name', + externalId: 'external_id', + externalTitle: 'external title', + externalUrl: 'basicPush.com', + pushedAt: '2020-02-20T15:02:57.995Z', + pushedBy: { + email: 'leslie.knope@elastic.co', + fullName: 'Leslie Knope', + username: 'lknope', + }, + }, + id: '1', + status: 'open', + tags: ['coke', 'pepsi'], + title: 'Another horrible breach!!', + totalComment: 0, + updatedAt: '2020-02-20T15:02:57.995Z', + updatedBy: { + email: 'leslie.knope@elastic.co', + fullName: 'Leslie Knope', + username: 'lknope', + }, + version: 'WzQ3LDFd', + }); }); }); diff --git a/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx b/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx index 64bbd178364667a..90984f691d56bf7 100644 --- a/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx @@ -8,7 +8,8 @@ import React from 'react'; import { renderHook, act } from '@testing-library/react-hooks'; -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { useKibana } from '../../../common/lib/kibana'; import '../../../common/mock/match_media'; @@ -16,6 +17,17 @@ import { useAllCasesModal, UseAllCasesModalProps, UseAllCasesModalReturnedValues import { TestProviders } from '../../../common/mock'; jest.mock('../../../common/lib/kibana'); +jest.mock('../all_cases', () => { + return { + AllCases: ({ onRowClick }: { onRowClick: ({ id }: { id: string }) => void }) => { + return ( + + ); + }, + }; +}); const useKibanaMock = useKibana as jest.Mocked; const onRowClick = jest.fn(); @@ -32,7 +44,7 @@ describe('useAllCasesModal', () => { const { result } = renderHook( () => useAllCasesModal({ onRowClick }), { - wrapper: ({ children }) => {children}, + wrapper: ({ children }) => {children}, } ); @@ -43,7 +55,7 @@ describe('useAllCasesModal', () => { const { result } = renderHook( () => useAllCasesModal({ onRowClick }), { - wrapper: ({ children }) => {children}, + wrapper: ({ children }) => {children}, } ); @@ -58,7 +70,7 @@ describe('useAllCasesModal', () => { const { result } = renderHook( () => useAllCasesModal({ onRowClick }), { - wrapper: ({ children }) => {children}, + wrapper: ({ children }) => {children}, } ); @@ -74,7 +86,7 @@ describe('useAllCasesModal', () => { const { result, rerender } = renderHook( () => useAllCasesModal({ onRowClick }), { - wrapper: ({ children }) => {children}, + wrapper: ({ children }) => {children}, } ); @@ -84,4 +96,27 @@ describe('useAllCasesModal', () => { expect(result1).toBe(result2); }); + + it('closes the modal when clicking a row', async () => { + const { result } = renderHook( + () => useAllCasesModal({ onRowClick }), + { + wrapper: ({ children }) => {children}, + } + ); + + act(() => { + result.current.openModal(); + }); + + const Modal = result.current.Modal; + render(); + + act(() => { + userEvent.click(screen.getByText('case-row')); + }); + + expect(result.current.isModalOpen).toBe(false); + expect(onRowClick).toHaveBeenCalledWith({ id: 'case-id' }); + }); }); diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/alert_context_menu.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/alert_context_menu.tsx index 555d9a56e0c25c4..fd65a8c30707375 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/alert_context_menu.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/alert_context_menu.tsx @@ -103,9 +103,7 @@ const AlertContextMenuComponent: React.FC = ({ alertId: eventId, index: eventIndex ?? '', }, - () => { - displaySuccessToast(i18n.CASE_CREATED_SUCCESS_TOAST(theCase.title), dispatchToaster); - } + () => displaySuccessToast(i18n.CASE_CREATED_SUCCESS_TOAST(theCase.title), dispatchToaster) ); }, [dispatchToaster, eventId, postComment, eventIndex] diff --git a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx index c2f168c8698123c..8e4c6247e7e0951 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/graph_overlay/index.tsx @@ -34,7 +34,10 @@ import { timelineDefaults } from '../../store/timeline/defaults'; import { TimelineModel } from '../../store/timeline/model'; import { isFullScreen } from '../timeline/body/column_headers'; import { NewCase, ExistingCase } from '../timeline/properties/helpers'; -import { updateTimelineGraphEventId } from '../../../timelines/store/timeline/actions'; +import { + setInsertTimeline, + updateTimelineGraphEventId, +} from '../../../timelines/store/timeline/actions'; import { Resolver } from '../../../resolver/view'; import { useAllCasesModal } from '../../../cases/components/use_all_cases_modal'; import { useKibana, useUiSetting$ } from '../../../common/lib/kibana'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.tsx index 4520c51f1529133..8d08a59bfe76aa1 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/properties/index.tsx @@ -23,6 +23,7 @@ import { Case } from '../../../../cases/containers/types'; import { TimelineProperties } from './styles'; import { PropertiesRight } from './properties_right'; import { PropertiesLeft } from './properties_left'; +import { setInsertTimeline } from '../../../store/timeline/actions'; type UpdateIsFavorite = ({ id, isFavorite }: { id: string; isFavorite: boolean }) => void; type UpdateTitle = ({ id, title }: { id: string; title: string }) => void;