-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security solution] Threat hunting test coverage improvements (#73276) (
- Loading branch information
1 parent
6be73e6
commit 8d404fc
Showing
6 changed files
with
308 additions
and
6 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/security_solution/public/common/components/markdown_editor/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,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 { mount } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { MarkdownEditor } from '.'; | ||
import { TestProviders } from '../../mock'; | ||
|
||
describe('Markdown Editor', () => { | ||
const onChange = jest.fn(); | ||
const onCursorPositionUpdate = jest.fn(); | ||
const defaultProps = { | ||
content: 'hello world', | ||
onChange, | ||
onCursorPositionUpdate, | ||
}; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
test('it calls onChange with correct value', () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<MarkdownEditor {...defaultProps} /> | ||
</TestProviders> | ||
); | ||
const newValue = 'a new string'; | ||
wrapper | ||
.find(`[data-test-subj="textAreaInput"]`) | ||
.first() | ||
.simulate('change', { target: { value: newValue } }); | ||
expect(onChange).toBeCalledWith(newValue); | ||
}); | ||
test('it calls onCursorPositionUpdate with correct args', () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<MarkdownEditor {...defaultProps} /> | ||
</TestProviders> | ||
); | ||
wrapper.find(`[data-test-subj="textAreaInput"]`).first().simulate('blur'); | ||
expect(onCursorPositionUpdate).toBeCalledWith({ | ||
start: 0, | ||
end: 0, | ||
}); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/security_solution/public/common/utils/timeline/use_show_timeline.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,33 @@ | ||
/* | ||
* 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 { renderHook, act } from '@testing-library/react-hooks'; | ||
import { useShowTimeline } from './use_show_timeline'; | ||
import { globalNode } from '../../mock'; | ||
|
||
describe('use show timeline', () => { | ||
it('shows timeline for routes on default', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook(() => useShowTimeline()); | ||
await waitForNextUpdate(); | ||
const uninitializedTimeline = result.current; | ||
expect(uninitializedTimeline).toEqual([true]); | ||
}); | ||
}); | ||
it('hides timeline for blacklist routes', async () => { | ||
await act(async () => { | ||
Object.defineProperty(globalNode.window, 'location', { | ||
value: { | ||
pathname: `/cases/configure`, | ||
}, | ||
}); | ||
const { result, waitForNextUpdate } = renderHook(() => useShowTimeline()); | ||
await waitForNextUpdate(); | ||
const uninitializedTimeline = result.current; | ||
expect(uninitializedTimeline).toEqual([false]); | ||
}); | ||
}); | ||
}); |
145 changes: 145 additions & 0 deletions
145
x-pack/plugins/security_solution/public/timelines/components/manage_timeline/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,145 @@ | ||
/* | ||
* 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 { renderHook, act } from '@testing-library/react-hooks'; | ||
import { getTimelineDefaults, useTimelineManager, UseTimelineManager } from './'; | ||
import { FilterManager } from '../../../../../../../src/plugins/data/public/query/filter_manager'; | ||
import { coreMock } from '../../../../../../../src/core/public/mocks'; | ||
import { TimelineRowAction } from '../timeline/body/actions'; | ||
|
||
const isStringifiedComparisonEqual = (a: {}, b: {}): boolean => | ||
JSON.stringify(a) === JSON.stringify(b); | ||
|
||
describe('useTimelineManager', () => { | ||
const setupMock = coreMock.createSetup(); | ||
const testId = 'coolness'; | ||
const timelineDefaults = getTimelineDefaults(testId); | ||
const timelineRowActions = () => []; | ||
const mockFilterManager = new FilterManager(setupMock.uiSettings); | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
it('initilizes an undefined timeline', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
const uninitializedTimeline = result.current.getManageTimelineById(testId); | ||
expect(isStringifiedComparisonEqual(uninitializedTimeline, timelineDefaults)).toBeTruthy(); | ||
}); | ||
}); | ||
it('getIndexToAddById', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
const data = result.current.getIndexToAddById(testId); | ||
expect(data).toEqual(timelineDefaults.indexToAdd); | ||
}); | ||
}); | ||
it('setIndexToAdd', async () => { | ||
await act(async () => { | ||
const indexToAddArgs = { id: testId, indexToAdd: ['example'] }; | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
result.current.initializeTimeline({ | ||
id: testId, | ||
timelineRowActions, | ||
}); | ||
result.current.setIndexToAdd(indexToAddArgs); | ||
const data = result.current.getIndexToAddById(testId); | ||
expect(data).toEqual(indexToAddArgs.indexToAdd); | ||
}); | ||
}); | ||
it('setIsTimelineLoading', async () => { | ||
await act(async () => { | ||
const isLoadingArgs = { id: testId, isLoading: true }; | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
result.current.initializeTimeline({ | ||
id: testId, | ||
timelineRowActions, | ||
}); | ||
let timeline = result.current.getManageTimelineById(testId); | ||
expect(timeline.isLoading).toBeFalsy(); | ||
result.current.setIsTimelineLoading(isLoadingArgs); | ||
timeline = result.current.getManageTimelineById(testId); | ||
expect(timeline.isLoading).toBeTruthy(); | ||
}); | ||
}); | ||
it('setTimelineRowActions', async () => { | ||
await act(async () => { | ||
const timelineRowActionsEx = () => [ | ||
{ id: 'wow', content: 'hey', displayType: 'icon', onClick: () => {} } as TimelineRowAction, | ||
]; | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
result.current.initializeTimeline({ | ||
id: testId, | ||
timelineRowActions, | ||
}); | ||
let timeline = result.current.getManageTimelineById(testId); | ||
expect(timeline.timelineRowActions).toEqual(timelineRowActions); | ||
result.current.setTimelineRowActions({ | ||
id: testId, | ||
timelineRowActions: timelineRowActionsEx, | ||
}); | ||
timeline = result.current.getManageTimelineById(testId); | ||
expect(timeline.timelineRowActions).toEqual(timelineRowActionsEx); | ||
}); | ||
}); | ||
it('getTimelineFilterManager undefined on uninitialized', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
const data = result.current.getTimelineFilterManager(testId); | ||
expect(data).toEqual(undefined); | ||
}); | ||
}); | ||
it('getTimelineFilterManager defined at initialize', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
result.current.initializeTimeline({ | ||
id: testId, | ||
timelineRowActions, | ||
filterManager: mockFilterManager, | ||
}); | ||
const data = result.current.getTimelineFilterManager(testId); | ||
expect(data).toEqual(mockFilterManager); | ||
}); | ||
}); | ||
it('isManagedTimeline returns false when unset and then true when set', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<string, UseTimelineManager>(() => | ||
useTimelineManager() | ||
); | ||
await waitForNextUpdate(); | ||
let data = result.current.isManagedTimeline(testId); | ||
expect(data).toBeFalsy(); | ||
result.current.initializeTimeline({ | ||
id: testId, | ||
timelineRowActions, | ||
filterManager: mockFilterManager, | ||
}); | ||
data = result.current.isManagedTimeline(testId); | ||
expect(data).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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