-
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
[Security solution] [RAC] Add row renderer popover to alert table "reason" field #108054
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
148 changes: 148 additions & 0 deletions
148
...ution/public/timelines/components/timeline/body/renderers/reason_column_renderer.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,148 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for adding tests! |
||
* 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 React from 'react'; | ||
|
||
import { mockTimelineData } from '../../../../../common/mock'; | ||
import { defaultColumnHeaderType } from '../column_headers/default_headers'; | ||
import { REASON_FIELD_NAME } from './constants'; | ||
import { reasonColumnRenderer } from './reason_column_renderer'; | ||
import { plainColumnRenderer } from './plain_column_renderer'; | ||
|
||
import { | ||
BrowserFields, | ||
ColumnHeaderOptions, | ||
RowRenderer, | ||
RowRendererId, | ||
} from '../../../../../../common'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { TestProviders } from '../../../../../../../timelines/public/mock'; | ||
import { useDraggableKeyboardWrapper as mockUseDraggableKeyboardWrapper } from '../../../../../../../timelines/public/components'; | ||
import { cloneDeep } from 'lodash'; | ||
jest.mock('./plain_column_renderer'); | ||
|
||
jest.mock('../../../../../common/lib/kibana', () => { | ||
const originalModule = jest.requireActual('../../../../../common/lib/kibana'); | ||
return { | ||
...originalModule, | ||
useKibana: () => ({ | ||
services: { | ||
timelines: { | ||
getUseDraggableKeyboardWrapper: () => mockUseDraggableKeyboardWrapper, | ||
}, | ||
}, | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../../../common/components/link_to', () => { | ||
const original = jest.requireActual('../../../../../common/components/link_to'); | ||
return { | ||
...original, | ||
useFormatUrl: () => ({ | ||
formatUrl: () => '', | ||
}), | ||
}; | ||
}); | ||
|
||
const invalidEcs = cloneDeep(mockTimelineData[0].ecs); | ||
const validEcs = cloneDeep(mockTimelineData[28].ecs); | ||
|
||
const field: ColumnHeaderOptions = { | ||
id: 'test-field-id', | ||
columnHeaderType: defaultColumnHeaderType, | ||
}; | ||
|
||
const rowRenderers: RowRenderer[] = [ | ||
{ | ||
id: RowRendererId.alerts, | ||
isInstance: (ecs) => ecs === validEcs, | ||
// eslint-disable-next-line react/display-name | ||
renderRow: () => <span data-test-subj="test-row-render" />, | ||
}, | ||
]; | ||
const browserFields: BrowserFields = {}; | ||
|
||
const defaultProps = { | ||
columnName: REASON_FIELD_NAME, | ||
eventId: 'test-vent-id', | ||
machadoum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
field, | ||
timelineId: 'test-timeline-id', | ||
values: ['test-value'], | ||
}; | ||
|
||
describe('reasonColumnRenderer', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('isIntance', () => { | ||
it('returns true when columnName is `signal.reason`', () => { | ||
expect(reasonColumnRenderer.isInstance(REASON_FIELD_NAME, [])).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('renderColumn', () => { | ||
it('calls `plainColumnRenderer.renderColumn` when ecsData, rowRenderers or browserFields is empty', () => { | ||
reasonColumnRenderer.renderColumn(defaultProps); | ||
|
||
expect(plainColumnRenderer.renderColumn).toBeCalledTimes(1); | ||
}); | ||
|
||
it("doesn't call `plainColumnRenderer.renderColumn` when ecsData, rowRenderers or browserFields fields are not empty", () => { | ||
reasonColumnRenderer.renderColumn({ | ||
...defaultProps, | ||
ecsData: invalidEcs, | ||
rowRenderers, | ||
browserFields, | ||
}); | ||
|
||
expect(plainColumnRenderer.renderColumn).toBeCalledTimes(0); | ||
}); | ||
|
||
it("doesn't render popover button when getRowRenderer doesn't find a rowRenderer", () => { | ||
const renderedColumn = reasonColumnRenderer.renderColumn({ | ||
...defaultProps, | ||
ecsData: invalidEcs, | ||
rowRenderers, | ||
browserFields, | ||
}); | ||
|
||
const wrapper = render(<TestProviders>{renderedColumn}</TestProviders>); | ||
|
||
expect(wrapper.queryByTestId('reson-cell-button')).not.toBeInTheDocument(); | ||
machadoum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('render popover button when getRowRenderer finds a rowRenderer', () => { | ||
const renderedColumn = reasonColumnRenderer.renderColumn({ | ||
...defaultProps, | ||
ecsData: validEcs, | ||
rowRenderers, | ||
browserFields, | ||
}); | ||
|
||
const wrapper = render(<TestProviders>{renderedColumn}</TestProviders>); | ||
|
||
expect(wrapper.queryByTestId('reson-cell-button')).toBeInTheDocument(); | ||
}); | ||
|
||
it('render rowRender inside a popover when reson field button is clicked', () => { | ||
const renderedColumn = reasonColumnRenderer.renderColumn({ | ||
...defaultProps, | ||
ecsData: validEcs, | ||
rowRenderers, | ||
browserFields, | ||
}); | ||
|
||
const wrapper = render(<TestProviders>{renderedColumn}</TestProviders>); | ||
|
||
fireEvent.click(wrapper.getByTestId('reson-cell-button')); | ||
|
||
expect(wrapper.queryByTestId('test-row-render')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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.
Do we want a default name for the plain renderer? We can do that in a follow up PR, but we should find out
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.
I am struggling to find a scenario where we would display the plain RowRenderer. I think that it won't be displayed on the alert page.
When I call
getRowRenderer
and noronRenderer
is found it returns null Instead of returningplainRowRenderer
.I couldn't find any reference to plain_row_renderer.tsx on the code.
Here there is a comment mentioning it but the comment is outdated because
plainRowRenderer
is not included ondefaultRowRenderers
If I am right, we could delete
plain_row_renderer.tsx