fix: show correct alert actions based on the alert's status (#121203) (#121267)

Co-authored-by: Jan Monschke <jan.monschke@elastic.co>
This commit is contained in:
Kibana Machine 2021-12-15 05:34:48 -05:00 committed by GitHub
parent 474d83d2bb
commit 49be0438f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 2 deletions

View file

@ -13,7 +13,18 @@ import React from 'react';
import { Ecs } from '../../../../../common/ecs';
import { mockTimelines } from '../../../../common/mock/mock_timelines_plugin';
const ecsRowData: Ecs = { _id: '1', agent: { type: ['blah'] } };
const ecsRowData: Ecs = {
_id: '1',
agent: { type: ['blah'] },
kibana: {
alert: {
workflow_status: ['open'],
rule: {
uuid: ['testId'],
},
},
},
};
const props = {
ariaLabel:
@ -47,9 +58,19 @@ jest.mock('../../../../common/lib/kibana', () => ({
}),
}));
jest.mock(
'../../../../detections/containers/detection_engine/alerts/use_alerts_privileges',
() => ({
useAlertsPrivileges: jest.fn().mockReturnValue({ hasIndexWrite: true, hasKibanaCRUD: true }),
})
);
const actionMenuButton = '[data-test-subj="timeline-context-menu-button"] button';
const addToExistingCaseButton = '[data-test-subj="add-to-existing-case-action"]';
const addToNewCaseButton = '[data-test-subj="add-to-new-case-action"]';
const markAsOpenButton = '[data-test-subj="open-alert-status"]';
const markAsAcknowledgedButton = '[data-test-subj="acknowledged-alert-status"]';
const markAsClosedButton = '[data-test-subj="close-alert-status"]';
describe('InvestigateInResolverAction', () => {
test('it render AddToCase context menu item if timelineId === TimelineId.detectionsPage', () => {
@ -98,4 +119,16 @@ describe('InvestigateInResolverAction', () => {
expect(wrapper.find(addToExistingCaseButton).first().exists()).toEqual(false);
expect(wrapper.find(addToNewCaseButton).first().exists()).toEqual(false);
});
test('it renders the correct status action buttons', () => {
const wrapper = mount(<AlertContextMenu {...props} timelineId={TimelineId.active} />, {
wrappingComponent: TestProviders,
});
wrapper.find(actionMenuButton).simulate('click');
expect(wrapper.find(markAsOpenButton).first().exists()).toEqual(false);
expect(wrapper.find(markAsAcknowledgedButton).first().exists()).toEqual(true);
expect(wrapper.find(markAsClosedButton).first().exists()).toEqual(true);
});
});

View file

@ -79,7 +79,7 @@ const AlertContextMenuComponent: React.FC<AlertContextMenuProps & PropsFromRedux
ariaLabel: ATTACH_ALERT_TO_CASE_FOR_ROW({ ariaRowindex, columnValues }),
});
const alertStatus = get(0, ecsRowData?.['kibana.alert.workflow_status']) as Status;
const alertStatus = get(0, ecsRowData?.kibana?.alert?.workflow_status) as Status | undefined;
const isEvent = useMemo(() => indexOf(ecsRowData.event?.kind, 'event') !== -1, [ecsRowData]);