-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
159 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ns/security_solution/public/timelines/components/flyout/add_to_case_button/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 { useDeepEqualSelector } from '../../../../common/hooks/use_selector'; | ||
import { mockTimelineModel, TestProviders } from '../../../../common/mock'; | ||
import { useAllCasesModal } from '../../../../cases/components/use_all_cases_modal'; | ||
import { AddToCaseButton } from '.'; | ||
|
||
const mockDispatch = jest.fn(); | ||
jest.mock('react-redux', () => { | ||
const original = jest.requireActual('react-redux'); | ||
return { | ||
...original, | ||
useDispatch: () => mockDispatch, | ||
}; | ||
}); | ||
|
||
jest.mock('../../../../common/lib/kibana'); | ||
jest.mock('../../../../common/hooks/use_selector'); | ||
jest.mock('../../../../cases/components/use_all_cases_modal'); | ||
|
||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>; | ||
const useAllCasesModalMock = useAllCasesModal as jest.Mock; | ||
|
||
describe('EventColumnView', () => { | ||
const navigateToApp = jest.fn(); | ||
|
||
beforeEach(() => { | ||
useKibanaMock().services.application.navigateToApp = navigateToApp; | ||
(useDeepEqualSelector as jest.Mock).mockReturnValue(mockTimelineModel); | ||
}); | ||
|
||
it('navigates to the correct path without id', async () => { | ||
useAllCasesModalMock.mockImplementation(({ onRowClick }) => { | ||
onRowClick(); | ||
|
||
return { | ||
modal: <>{'test'}</>, | ||
openModal: jest.fn(), | ||
isModalOpen: true, | ||
closeModal: jest.fn(), | ||
}; | ||
}); | ||
|
||
mount( | ||
<TestProviders> | ||
<AddToCaseButton timelineId={'timeline-1'} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(navigateToApp).toHaveBeenCalledWith('securitySolution:case', { path: '/create' }); | ||
}); | ||
|
||
it('navigates to the correct path with id', async () => { | ||
useAllCasesModalMock.mockImplementation(({ onRowClick }) => { | ||
onRowClick({ id: 'case-id' }); | ||
|
||
return { | ||
modal: <>{'test'}</>, | ||
openModal: jest.fn(), | ||
isModalOpen: true, | ||
closeModal: jest.fn(), | ||
}; | ||
}); | ||
|
||
mount( | ||
<TestProviders> | ||
<AddToCaseButton timelineId={'timeline-1'} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(navigateToApp).toHaveBeenCalledWith('securitySolution:case', { path: '/case-id' }); | ||
}); | ||
}); |