-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Events tab and External alerts tab to the User page and the User …
…details page (#127953) * Add Events tab to the User page and the User details page * Add External alerts tab to the User page and the User details page * Add cypress tests * Add unit test to EventsQueryTabBody * Memoize navTabs on Users page
- Loading branch information
Showing
32 changed files
with
472 additions
and
79 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
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/security_solution/cypress/integration/users/users_events_tab.spec.ts
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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EVENTS_TAB, EVENTS_TAB_CONTENT } from '../../screens/users/user_events'; | ||
import { cleanKibana } from '../../tasks/common'; | ||
|
||
import { loginAndWaitForPage } from '../../tasks/login'; | ||
|
||
import { USERS_URL } from '../../urls/navigation'; | ||
|
||
describe('Users Events tab', () => { | ||
before(() => { | ||
cleanKibana(); | ||
loginAndWaitForPage(USERS_URL); | ||
}); | ||
|
||
it(`renders events tab`, () => { | ||
cy.get(EVENTS_TAB).click(); | ||
|
||
cy.get(EVENTS_TAB_CONTENT).should('exist'); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/security_solution/cypress/integration/users/users_external_alerts_tab.spec.ts
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,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
EXTERNAL_ALERTS_TAB, | ||
EXTERNAL_ALERTS_TAB_CONTENT, | ||
} from '../../screens/users/user_external_alerts'; | ||
import { cleanKibana } from '../../tasks/common'; | ||
|
||
import { loginAndWaitForPage } from '../../tasks/login'; | ||
|
||
import { USERS_URL } from '../../urls/navigation'; | ||
|
||
describe('Users external alerts tab', () => { | ||
before(() => { | ||
cleanKibana(); | ||
loginAndWaitForPage(USERS_URL); | ||
}); | ||
|
||
it(`renders external alerts tab`, () => { | ||
cy.get(EXTERNAL_ALERTS_TAB).click(); | ||
|
||
cy.get(EXTERNAL_ALERTS_TAB_CONTENT).should('exist'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/security_solution/cypress/screens/users/user_events.ts
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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const EVENTS_TAB = '[data-test-subj="navigation-events"]'; | ||
export const EVENTS_TAB_CONTENT = '[data-test-subj="events-viewer-panel"]'; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/security_solution/cypress/screens/users/user_external_alerts.ts
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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const EXTERNAL_ALERTS_TAB = '[data-test-subj="navigation-externalAlerts"]'; | ||
export const EXTERNAL_ALERTS_TAB_CONTENT = '[data-test-subj="events-viewer-panel"]'; |
114 changes: 114 additions & 0 deletions
114
...gins/security_solution/public/common/components/events_tab/events_query_tab_body.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,114 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TimelineId } from '../../../../common/types'; | ||
import { HostsType } from '../../../hosts/store/model'; | ||
import { TestProviders } from '../../mock'; | ||
import { EventsQueryTabBody, EventsQueryTabBodyComponentProps } from './events_query_tab_body'; | ||
import { useGlobalFullScreen } from '../../containers/use_full_screen'; | ||
import * as tGridActions from '../../../../../timelines/public/store/t_grid/actions'; | ||
|
||
jest.mock('../../lib/kibana', () => { | ||
const original = jest.requireActual('../../lib/kibana'); | ||
|
||
return { | ||
...original, | ||
useKibana: () => ({ | ||
services: { | ||
...original.useKibana().services, | ||
cases: { | ||
ui: { | ||
getCasesContext: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
}), | ||
}; | ||
}); | ||
|
||
const FakeStatefulEventsViewer = () => <div>{'MockedStatefulEventsViewer'}</div>; | ||
jest.mock('../events_viewer', () => ({ StatefulEventsViewer: FakeStatefulEventsViewer })); | ||
|
||
jest.mock('../../containers/use_full_screen', () => ({ | ||
useGlobalFullScreen: jest.fn().mockReturnValue({ | ||
globalFullScreen: true, | ||
}), | ||
})); | ||
|
||
describe('EventsQueryTabBody', () => { | ||
const commonProps: EventsQueryTabBodyComponentProps = { | ||
indexNames: ['test-index'], | ||
setQuery: jest.fn(), | ||
timelineId: TimelineId.test, | ||
type: HostsType.page, | ||
endDate: new Date('2000').toISOString(), | ||
startDate: new Date('2000').toISOString(), | ||
}; | ||
|
||
it('renders EventsViewer', () => { | ||
const { queryByText } = render( | ||
<TestProviders> | ||
<EventsQueryTabBody {...commonProps} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(queryByText('MockedStatefulEventsViewer')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the matrix histogram when globalFullScreen is false', () => { | ||
(useGlobalFullScreen as jest.Mock).mockReturnValue({ | ||
globalFullScreen: false, | ||
}); | ||
|
||
const { queryByTestId } = render( | ||
<TestProviders> | ||
<EventsQueryTabBody {...commonProps} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(queryByTestId('eventsHistogramQueryPanel')).toBeInTheDocument(); | ||
}); | ||
|
||
it("doesn't render the matrix histogram when globalFullScreen is true", () => { | ||
(useGlobalFullScreen as jest.Mock).mockReturnValue({ | ||
globalFullScreen: true, | ||
}); | ||
|
||
const { queryByTestId } = render( | ||
<TestProviders> | ||
<EventsQueryTabBody {...commonProps} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(queryByTestId('eventsHistogramQueryPanel')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('deletes query when unmouting', () => { | ||
const mockDeleteQuery = jest.fn(); | ||
const { unmount } = render( | ||
<TestProviders> | ||
<EventsQueryTabBody {...commonProps} deleteQuery={mockDeleteQuery} /> | ||
</TestProviders> | ||
); | ||
unmount(); | ||
|
||
expect(mockDeleteQuery).toHaveBeenCalled(); | ||
}); | ||
|
||
it('initializes t-grid', () => { | ||
const spy = jest.spyOn(tGridActions, 'initializeTGridSettings'); | ||
render( | ||
<TestProviders> | ||
<EventsQueryTabBody {...commonProps} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
}); |
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
Oops, something went wrong.