forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Secutiy Solution] Timeline kpis (elastic#89210) (elastic#90105)
* Stub kpi component * search strategy scheleton timeline KPI * search strategy scheleton timeline KPI * Add timeline kpis component and search strategy container * Use getEmptyValue in timeline kpis * Prevent request from being made for blank timeline properly * Add kpi search strategy api integration test * Add jest tests for timeline kpis * Clear mocks in afterAll * Decouple some tests from EUI structure * Combine some selector calls, change types to be more appropriate * Simplify hook logic * Set loading and response on blank timeline * Only render kpi component when query is active tab * Use TimelineTabs enum for query tab string Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
b186524
commit fbd503c
Showing
12 changed files
with
631 additions
and
34 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
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.