-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Endpoint] Adds take action dropdown and tests to alert details flyout #59242
Merged
peluja1012
merged 13 commits into
elastic:master
from
dplumlee:alert-take-action-dropdown
Mar 17, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c81affe
adds dropdown
dplumlee 619e648
changes i18n fields
dplumlee 4290212
switches to buttons
dplumlee 7cbd0e3
adds tests for alert details flyout
dplumlee bc74cd8
updates es archiver data
dplumlee 668f53d
finishes functional and react tests
dplumlee 351abad
cleanup tests for alerts
1dbd1d9
updates alert esarchive data
dplumlee 9d0fc99
replaces es archives and fixes tests
dplumlee 10b8a5a
rebase
dplumlee 9cc7b16
fixes functional tests
dplumlee 4e931e9
suggested changes to take action button
bbfd954
addresses comments
dplumlee 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
81 changes: 81 additions & 0 deletions
81
x-pack/plugins/endpoint/public/applications/endpoint/view/alerts/alert_details.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,81 @@ | ||
/* | ||
* 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 * as reactTestingLibrary from '@testing-library/react'; | ||
import { appStoreFactory } from '../../store'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { MemoryHistory } from 'history'; | ||
import { AppAction } from '../../types'; | ||
import { mockAlertResultList } from '../../store/alerts/mock_alert_result_list'; | ||
import { alertPageTestRender } from './test_helpers/render_alert_page'; | ||
|
||
describe('when the alert details flyout is open', () => { | ||
let render: () => reactTestingLibrary.RenderResult; | ||
let history: MemoryHistory<never>; | ||
let store: ReturnType<typeof appStoreFactory>; | ||
|
||
beforeEach(async () => { | ||
// Creates the render elements for the tests to use | ||
({ render, history, store } = alertPageTestRender); | ||
}); | ||
describe('when the alerts details flyout is open', () => { | ||
beforeEach(() => { | ||
reactTestingLibrary.act(() => { | ||
history.push({ | ||
search: '?selected_alert=1', | ||
}); | ||
}); | ||
}); | ||
describe('when the data loads', () => { | ||
beforeEach(() => { | ||
reactTestingLibrary.act(() => { | ||
const action: AppAction = { | ||
type: 'serverReturnedAlertDetailsData', | ||
payload: mockAlertResultList().alerts[0], | ||
}; | ||
store.dispatch(action); | ||
}); | ||
}); | ||
it('should display take action button', async () => { | ||
await render().findByTestId('alertDetailTakeActionDropdownButton'); | ||
}); | ||
describe('when the user clicks the take action button on the flyout', () => { | ||
let renderResult: reactTestingLibrary.RenderResult; | ||
beforeEach(async () => { | ||
renderResult = render(); | ||
const takeActionButton = await renderResult.findByTestId( | ||
'alertDetailTakeActionDropdownButton' | ||
); | ||
if (takeActionButton) { | ||
fireEvent.click(takeActionButton); | ||
} | ||
}); | ||
it('should display the correct fields in the dropdown', async () => { | ||
await renderResult.findByTestId('alertDetailTakeActionCloseAlertButton'); | ||
await renderResult.findByTestId('alertDetailTakeActionWhitelistButton'); | ||
}); | ||
}); | ||
describe('when the user navigates to the overview tab', () => { | ||
let renderResult: reactTestingLibrary.RenderResult; | ||
beforeEach(async () => { | ||
renderResult = render(); | ||
const overviewTab = await renderResult.findByTestId('overviewMetadata'); | ||
if (overviewTab) { | ||
fireEvent.click(overviewTab); | ||
} | ||
}); | ||
it('should render all accordion panels', async () => { | ||
await renderResult.findAllByTestId('alertDetailsAlertAccordion'); | ||
await renderResult.findAllByTestId('alertDetailsHostAccordion'); | ||
await renderResult.findAllByTestId('alertDetailsFileAccordion'); | ||
await renderResult.findAllByTestId('alertDetailsHashAccordion'); | ||
await renderResult.findAllByTestId('alertDetailsSourceProcessAccordion'); | ||
await renderResult.findAllByTestId('alertDetailsSourceProcessTokenAccordion'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
71 changes: 71 additions & 0 deletions
71
...dpoint/public/applications/endpoint/view/alerts/details/overview/take_action_dropdown.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,71 @@ | ||
/* | ||
* 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, { memo, useState, useCallback } from 'react'; | ||
import { EuiPopover, EuiFormRow, EuiButton, EuiButtonEmpty } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
const TakeActionButton = memo(({ onClick }: { onClick: () => void }) => ( | ||
<EuiButton | ||
iconType="arrowDown" | ||
iconSide="right" | ||
data-test-subj="alertDetailTakeActionDropdownButton" | ||
onClick={onClick} | ||
> | ||
<FormattedMessage | ||
id="xpack.endpoint.application.endpoint.alertDetails.takeAction.title" | ||
defaultMessage="Take Action" | ||
/> | ||
</EuiButton> | ||
)); | ||
|
||
export const TakeActionDropdown = memo(() => { | ||
const [isDropdownOpen, setIsDropdownOpen] = useState(false); | ||
|
||
const onClick = useCallback(() => { | ||
setIsDropdownOpen(!isDropdownOpen); | ||
}, [isDropdownOpen]); | ||
|
||
const closePopover = useCallback(() => { | ||
setIsDropdownOpen(false); | ||
}, []); | ||
|
||
return ( | ||
<EuiPopover | ||
button={<TakeActionButton onClick={onClick} />} | ||
isOpen={isDropdownOpen} | ||
anchorPosition="downRight" | ||
closePopover={closePopover} | ||
data-test-subj="alertListTakeActionDropdownContent" | ||
> | ||
<EuiFormRow> | ||
<EuiButtonEmpty | ||
data-test-subj="alertDetailTakeActionCloseAlertButton" | ||
color="text" | ||
iconType="folderCheck" | ||
> | ||
<FormattedMessage | ||
id="xpack.endpoint.application.endpoint.alertDetails.takeAction.close" | ||
defaultMessage="Close Alert" | ||
/> | ||
</EuiButtonEmpty> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow> | ||
<EuiButtonEmpty | ||
data-test-subj="alertDetailTakeActionWhitelistButton" | ||
color="text" | ||
iconType="listAdd" | ||
> | ||
<FormattedMessage | ||
id="xpack.endpoint.application.endpoint.alertDetails.takeAction.whitelist" | ||
defaultMessage="Whitelist..." | ||
/> | ||
</EuiButtonEmpty> | ||
</EuiFormRow> | ||
</EuiPopover> | ||
); | ||
}); |
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.
This description doesn't match the setup logic. Also, it seems very close to what is here:
https://github.com/elastic/kibana/blob/master/x-pack/plugins/endpoint/public/applications/endpoint/view/alerts/index.test.tsx#L23
I think these specs should be parts of that. The setup logic can be reused that way. Also, the tests are about the same feature set.
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.
abstracted the building render logic out into its own function