Skip to content

Commit

Permalink
fix: show correct alert actions based on the alert's status (#121203)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke authored and kibanamachine committed Dec 15, 2021
1 parent 474d83d commit 3650504
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit 3650504

Please sign in to comment.