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.
[SIEM] Refactor hosts routing (elastic#47459) (elastic#49473)
- Loading branch information
1 parent
23ac9b6
commit 4f4cd8b
Showing
14 changed files
with
581 additions
and
682 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
x-pack/legacy/plugins/siem/public/pages/hosts/details/__snapshots__/body.test.tsx.snap
This file was deleted.
Oops, something went wrong.
99 changes: 0 additions & 99 deletions
99
x-pack/legacy/plugins/siem/public/pages/hosts/details/body.test.tsx
This file was deleted.
Oops, something went wrong.
106 changes: 0 additions & 106 deletions
106
x-pack/legacy/plugins/siem/public/pages/hosts/details/body.tsx
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.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,108 @@ | ||
/* | ||
* 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 { StaticIndexPattern } from 'ui/index_patterns'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import { mockIndexPattern } from '../../../mock/index_pattern'; | ||
import { TestProviders } from '../../../mock/test_providers'; | ||
import { mockUiSettings } from '../../../mock/ui_settings'; | ||
import { HostDetailsTabs } from './details_tabs'; | ||
import { SetAbsoluteRangeDatePicker } from './types'; | ||
import { hostDetailsPagePath } from '../types'; | ||
import { type } from './utils'; | ||
import { useKibanaCore } from '../../../lib/compose/kibana_core'; | ||
|
||
jest.mock('../../../lib/settings/use_kibana_ui_setting'); | ||
|
||
const mockUseKibanaCore = useKibanaCore as jest.Mock; | ||
jest.mock('../../../lib/compose/kibana_core'); | ||
mockUseKibanaCore.mockImplementation(() => ({ | ||
uiSettings: mockUiSettings, | ||
})); | ||
|
||
jest.mock('../../../containers/source', () => ({ | ||
indicesExistOrDataTemporarilyUnavailable: () => true, | ||
WithSource: ({ | ||
children, | ||
}: { | ||
children: (args: { | ||
indicesExist: boolean; | ||
indexPattern: StaticIndexPattern; | ||
}) => React.ReactNode; | ||
}) => children({ indicesExist: true, indexPattern: mockIndexPattern }), | ||
})); | ||
|
||
// Test will fail because we will to need to mock some core services to make the test work | ||
// For now let's forget about SiemSearchBar | ||
jest.mock('../../../components/search_bar', () => ({ | ||
SiemSearchBar: () => null, | ||
})); | ||
|
||
describe('body', () => { | ||
const scenariosMap = { | ||
authentications: 'AuthenticationsQueryTabBody', | ||
allHosts: 'HostsQueryTabBody', | ||
uncommonProcesses: 'UncommonProcessQueryTabBody', | ||
anomalies: 'AnomaliesQueryTabBody', | ||
events: 'EventsQueryTabBody', | ||
}; | ||
|
||
Object.entries(scenariosMap).forEach(([path, componentName]) => | ||
test(`it should pass expected object properties to ${componentName}`, () => { | ||
const wrapper = mount( | ||
<TestProviders> | ||
<MemoryRouter initialEntries={[`/hosts/host-1/${path}`]}> | ||
<HostDetailsTabs | ||
from={0} | ||
isInitializing={false} | ||
detailName={'host-1'} | ||
setQuery={() => {}} | ||
to={0} | ||
setAbsoluteRangeDatePicker={(jest.fn() as unknown) as SetAbsoluteRangeDatePicker} | ||
hostDetailsPagePath={hostDetailsPagePath} | ||
indexPattern={mockIndexPattern} | ||
type={type} | ||
filterQuery='{"bool":{"must":[],"filter":[{"match_all":{}},{"match_phrase":{"host.name":{"query":"host-1"}}}],"should":[],"must_not":[]}}' | ||
/> | ||
</MemoryRouter> | ||
</TestProviders> | ||
); | ||
|
||
// match against everything but the functions to ensure they are there as expected | ||
expect(wrapper.find(componentName).props()).toMatchObject({ | ||
endDate: 0, | ||
filterQuery: | ||
'{"bool":{"must":[],"filter":[{"match_all":{}},{"match_phrase":{"host.name":{"query":"host-1"}}}],"should":[],"must_not":[]}}', | ||
skip: false, | ||
startDate: 0, | ||
type: 'details', | ||
indexPattern: { | ||
fields: [ | ||
{ name: '@timestamp', searchable: true, type: 'date', aggregatable: true }, | ||
{ name: '@version', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.ephemeral_id', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.hostname', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.id', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test1', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test2', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test3', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test4', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test5', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test6', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test7', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'agent.test8', searchable: true, type: 'string', aggregatable: true }, | ||
{ name: 'host.name', searchable: true, type: 'string', aggregatable: true }, | ||
], | ||
title: 'filebeat-*,auditbeat-*,packetbeat-*', | ||
}, | ||
hostName: 'host-1', | ||
}); | ||
}) | ||
); | ||
}); |
Oops, something went wrong.