-
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.
[Security solution] [RAC] Add row renderer popover to alert table "re…
…ason" field (#108054) * Add row renderer popover to alert table reason field * Add a title to row renderer popover on alert table * Fix issues found during code review
- Loading branch information
Showing
11 changed files
with
385 additions
and
19 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
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 | ||
* 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-event-id', | ||
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('reason-cell-button')).not.toBeInTheDocument(); | ||
}); | ||
|
||
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('reason-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('reason-cell-button')); | ||
|
||
expect(wrapper.queryByTestId('test-row-render')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.