Skip to content
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

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

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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