-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Secutiy Solution] Timeline kpis #89210
Merged
kqualters-elastic
merged 21 commits into
elastic:master
from
kqualters-elastic:siem-timeline-kpis
Feb 2, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
201c344
Stub kpi component
kqualters-elastic 5b24e9c
search strategy scheleton timeline KPI
XavierM 298addc
search strategy scheleton timeline KPI
XavierM d372ff2
Merge branch 'siem-timeline-kpis' of github.com:kqualters-elastic/kib…
XavierM f69aca5
Add timeline kpis component and search strategy container
kqualters-elastic 66aed05
Merge branch 'master' into siem-timeline-kpis
kqualters-elastic 5a82ae6
Use getEmptyValue in timeline kpis
kqualters-elastic 88bbf7b
Prevent request from being made for blank timeline properly
kqualters-elastic d4173ee
Add kpi search strategy api integration test
kqualters-elastic bd1e9cf
Add jest tests for timeline kpis
kqualters-elastic f3e34fd
Clear mocks in afterAll
kqualters-elastic e4dd6a2
Decouple some tests from EUI structure
kqualters-elastic c884e25
Merge remote-tracking branch 'upstream/master' into siem-timeline-kpis
kqualters-elastic 5f53d96
Combine some selector calls, change types to be more appropriate
kqualters-elastic 48e8842
Simplify hook logic
kqualters-elastic 09f8c8e
Merge branch 'master' into siem-timeline-kpis
kqualters-elastic ded4eda
Merge branch 'master' into siem-timeline-kpis
kibanamachine 6de598e
Set loading and response on blank timeline
kqualters-elastic bf60d6c
Merge remote-tracking branch 'upstream/master' into siem-timeline-kpis
kqualters-elastic b21625b
Only render kpi component when query is active tab
kqualters-elastic bff5c8e
Use TimelineTabs enum for query tab string
kqualters-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
117 changes: 117 additions & 0 deletions
117
x-pack/plugins/security_solution/public/timelines/components/flyout/header/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,117 @@ | ||
/* | ||
* 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 { useKibana } from '../../../../common/lib/kibana'; | ||
import { TestProviders, mockIndexNames, mockIndexPattern } from '../../../../common/mock'; | ||
import { useTimelineKpis } from '../../../containers/kpis'; | ||
import { FlyoutHeader } from '.'; | ||
import { useSourcererScope } from '../../../../common/containers/sourcerer'; | ||
import { mockBrowserFields, mockDocValueFields } from '../../../../common/containers/source/mock'; | ||
import { useMountAppended } from '../../../../common/utils/use_mount_appended'; | ||
import { getEmptyValue } from '../../../../common/components/empty_value'; | ||
|
||
const mockUseSourcererScope: jest.Mock = useSourcererScope as jest.Mock; | ||
jest.mock('../../../../common/containers/sourcerer'); | ||
|
||
const mockUseTimelineKpis: jest.Mock = useTimelineKpis as jest.Mock; | ||
jest.mock('../../../containers/kpis', () => ({ | ||
useTimelineKpis: jest.fn(), | ||
})); | ||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>; | ||
jest.mock('../../../../common/lib/kibana'); | ||
|
||
const mockUseTimelineKpiResponse = { | ||
processCount: 1, | ||
userCount: 1, | ||
sourceIpCount: 1, | ||
hostCount: 1, | ||
destinationIpCount: 1, | ||
}; | ||
const defaultMocks = { | ||
browserFields: mockBrowserFields, | ||
docValueFields: mockDocValueFields, | ||
indexPattern: mockIndexPattern, | ||
loading: false, | ||
selectedPatterns: mockIndexNames, | ||
}; | ||
describe('Timeline KPIs', () => { | ||
const mount = useMountAppended(); | ||
|
||
beforeEach(() => { | ||
// Mocking these services is required for the header component to render. | ||
mockUseSourcererScope.mockImplementation(() => defaultMocks); | ||
useKibanaMock().services.application.capabilities = { | ||
navLinks: {}, | ||
management: {}, | ||
catalogue: {}, | ||
actions: { show: true, crud: true }, | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('when the data is not loading and the response contains data', () => { | ||
beforeEach(() => { | ||
mockUseTimelineKpis.mockReturnValue([false, mockUseTimelineKpiResponse]); | ||
}); | ||
it('renders the component, labels and values succesfully', async () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<FlyoutHeader timelineId={'timeline-1'} /> | ||
</TestProviders> | ||
); | ||
expect(wrapper.find('[data-test-subj="siem-timeline-kpis"]').exists()).toEqual(true); | ||
// label | ||
expect(wrapper.find('[data-test-subj="siem-timeline-process-kpi"]').first().text()).toEqual( | ||
expect.stringContaining('Processes') | ||
); | ||
// value | ||
expect(wrapper.find('[data-test-subj="siem-timeline-process-kpi"]').first().text()).toEqual( | ||
expect.stringContaining('1') | ||
); | ||
}); | ||
}); | ||
|
||
describe('when the data is loading', () => { | ||
beforeEach(() => { | ||
mockUseTimelineKpis.mockReturnValue([true, mockUseTimelineKpiResponse]); | ||
}); | ||
it('renders a loading indicator for values', async () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<FlyoutHeader timelineId={'timeline-1'} /> | ||
</TestProviders> | ||
); | ||
expect(wrapper.find('[data-test-subj="siem-timeline-process-kpi"]').first().text()).toEqual( | ||
expect.stringContaining('--') | ||
); | ||
}); | ||
}); | ||
|
||
describe('when the response is null and timeline is blank', () => { | ||
beforeEach(() => { | ||
mockUseTimelineKpis.mockReturnValue([false, null]); | ||
}); | ||
it('renders labels and the default empty string', async () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<FlyoutHeader timelineId={'timeline-1'} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(wrapper.find('[data-test-subj="siem-timeline-process-kpi"]').first().text()).toEqual( | ||
expect.stringContaining('Processes') | ||
); | ||
expect(wrapper.find('[data-test-subj="siem-timeline-process-kpi"]').first().text()).toEqual( | ||
expect.stringContaining(getEmptyValue()) | ||
); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment explaining what these are and why their needed?