Skip to content

Commit

Permalink
[Security] [Cases] Manage timeline UI API (#67719) (#68185)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Jun 4, 2020
1 parent e9d4560 commit 681f2d6
Show file tree
Hide file tree
Showing 38 changed files with 1,377 additions and 945 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { mount, ReactWrapper } from 'enzyme';
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';

import { Filter } from '../../../../../../../src/plugins/data/common/es_query';
import { TimelineAction } from '../../../timelines/components/timeline/body/actions';
import { buildAlertsRuleIdFilter, getAlertActions } from './default_config';
import {
CreateTimeline,
SetEventsDeletedProps,
SetEventsLoadingProps,
UpdateTimelineLoading,
} from './types';
import { mockEcsDataWithAlert } from '../../../common/mock/mock_ecs';
import { sendAlertToTimelineAction, updateAlertStatusAction } from './actions';
import * as i18n from './translations';
import { buildAlertsRuleIdFilter } from './default_config';

jest.mock('./actions');

Expand Down Expand Up @@ -47,162 +34,162 @@ describe('alerts default_config', () => {
expect(filters[0]).toEqual(expectedFilter);
});
});

describe('getAlertActions', () => {
let setEventsLoading: ({ eventIds, isLoading }: SetEventsLoadingProps) => void;
let setEventsDeleted: ({ eventIds, isDeleted }: SetEventsDeletedProps) => void;
let createTimeline: CreateTimeline;
let updateTimelineIsLoading: UpdateTimelineLoading;

let onAlertStatusUpdateSuccess: (count: number, status: string) => void;
let onAlertStatusUpdateFailure: (status: string, error: Error) => void;

beforeEach(() => {
setEventsLoading = jest.fn();
setEventsDeleted = jest.fn();
createTimeline = jest.fn();
updateTimelineIsLoading = jest.fn();
onAlertStatusUpdateSuccess = jest.fn();
onAlertStatusUpdateFailure = jest.fn();
});

describe('timeline tooltip', () => {
test('it invokes sendAlertToTimelineAction when button clicked', () => {
const alertsActions = getAlertActions({
canUserCRUD: true,
hasIndexWrite: true,
setEventsLoading,
setEventsDeleted,
createTimeline,
status: 'open',
updateTimelineIsLoading,
onAlertStatusUpdateSuccess,
onAlertStatusUpdateFailure,
});
const timelineAction = alertsActions[0].getAction({
eventId: 'even-id',
ecsData: mockEcsDataWithAlert,
});
const wrapper = mount<React.ReactElement>(timelineAction as React.ReactElement);
wrapper.find(EuiButtonIcon).simulate('click');

expect(sendAlertToTimelineAction).toHaveBeenCalled();
});
});

describe('alert open action', () => {
let alertsActions: TimelineAction[];
let alertOpenAction: JSX.Element;
let wrapper: ReactWrapper<React.ReactElement, unknown>;

beforeEach(() => {
alertsActions = getAlertActions({
canUserCRUD: true,
hasIndexWrite: true,
setEventsLoading,
setEventsDeleted,
createTimeline,
status: 'open',
updateTimelineIsLoading,
onAlertStatusUpdateSuccess,
onAlertStatusUpdateFailure,
});

alertOpenAction = alertsActions[1].getAction({
eventId: 'event-id',
ecsData: mockEcsDataWithAlert,
});

wrapper = mount<React.ReactElement>(alertOpenAction as React.ReactElement);
});

afterEach(() => {
wrapper.unmount();
});

test('it invokes updateAlertStatusAction when button clicked', () => {
wrapper.find(EuiButtonIcon).simulate('click');

expect(updateAlertStatusAction).toHaveBeenCalledWith({
alertIds: ['event-id'],
status: 'open',
setEventsLoading,
setEventsDeleted,
onAlertStatusUpdateSuccess,
onAlertStatusUpdateFailure,
});
});

test('it displays expected text on hover', () => {
const openAlert = wrapper.find(EuiToolTip);
openAlert.simulate('mouseOver');
const tooltip = wrapper.find('.euiToolTipPopover').text();

expect(tooltip).toEqual(i18n.ACTION_OPEN_ALERT);
});

test('it displays expected icon', () => {
const icon = wrapper.find(EuiButtonIcon).props().iconType;

expect(icon).toEqual('securityAlertDetected');
});
});

describe('alert close action', () => {
let alertsActions: TimelineAction[];
let alertCloseAction: JSX.Element;
let wrapper: ReactWrapper<React.ReactElement, unknown>;

beforeEach(() => {
alertsActions = getAlertActions({
canUserCRUD: true,
hasIndexWrite: true,
setEventsLoading,
setEventsDeleted,
createTimeline,
status: 'closed',
updateTimelineIsLoading,
onAlertStatusUpdateSuccess,
onAlertStatusUpdateFailure,
});

alertCloseAction = alertsActions[1].getAction({
eventId: 'event-id',
ecsData: mockEcsDataWithAlert,
});

wrapper = mount<React.ReactElement>(alertCloseAction as React.ReactElement);
});

afterEach(() => {
wrapper.unmount();
});

test('it invokes updateAlertStatusAction when status button clicked', () => {
wrapper.find(EuiButtonIcon).simulate('click');

expect(updateAlertStatusAction).toHaveBeenCalledWith({
alertIds: ['event-id'],
status: 'closed',
setEventsLoading,
setEventsDeleted,
onAlertStatusUpdateSuccess,
onAlertStatusUpdateFailure,
});
});

test('it displays expected text on hover', () => {
const closeAlert = wrapper.find(EuiToolTip);
closeAlert.simulate('mouseOver');
const tooltip = wrapper.find('.euiToolTipPopover').text();
expect(tooltip).toEqual(i18n.ACTION_CLOSE_ALERT);
});

test('it displays expected icon', () => {
const icon = wrapper.find(EuiButtonIcon).props().iconType;

expect(icon).toEqual('securityAlertResolved');
});
});
});
// TODO: move these tests to ../timelines/components/timeline/body/events/event_column_view.tsx
// describe.skip('getAlertActions', () => {
// let setEventsLoading: ({ eventIds, isLoading }: SetEventsLoadingProps) => void;
// let setEventsDeleted: ({ eventIds, isDeleted }: SetEventsDeletedProps) => void;
// let createTimeline: CreateTimeline;
// let updateTimelineIsLoading: UpdateTimelineLoading;
//
// let onAlertStatusUpdateSuccess: (count: number, status: string) => void;
// let onAlertStatusUpdateFailure: (status: string, error: Error) => void;
//
// beforeEach(() => {
// setEventsLoading = jest.fn();
// setEventsDeleted = jest.fn();
// createTimeline = jest.fn();
// updateTimelineIsLoading = jest.fn();
// onAlertStatusUpdateSuccess = jest.fn();
// onAlertStatusUpdateFailure = jest.fn();
// });
//
// describe('timeline tooltip', () => {
// test('it invokes sendAlertToTimelineAction when button clicked', () => {
// const alertsActions = getAlertActions({
// canUserCRUD: true,
// hasIndexWrite: true,
// setEventsLoading,
// setEventsDeleted,
// createTimeline,
// status: 'open',
// updateTimelineIsLoading,
// onAlertStatusUpdateSuccess,
// onAlertStatusUpdateFailure,
// });
// const timelineAction = alertsActions[0].getAction({
// eventId: 'even-id',
// ecsData: mockEcsDataWithAlert,
// });
// const wrapper = mount<React.ReactElement>(timelineAction as React.ReactElement);
// wrapper.find(EuiButtonIcon).simulate('click');
//
// expect(sendAlertToTimelineAction).toHaveBeenCalled();
// });
// });
//
// describe('alert open action', () => {
// let alertsActions: TimelineAction[];
// let alertOpenAction: JSX.Element;
// let wrapper: ReactWrapper<React.ReactElement, unknown>;
//
// beforeEach(() => {
// alertsActions = getAlertActions({
// canUserCRUD: true,
// hasIndexWrite: true,
// setEventsLoading,
// setEventsDeleted,
// createTimeline,
// status: 'open',
// updateTimelineIsLoading,
// onAlertStatusUpdateSuccess,
// onAlertStatusUpdateFailure,
// });
//
// alertOpenAction = alertsActions[1].getAction({
// eventId: 'event-id',
// ecsData: mockEcsDataWithAlert,
// });
//
// wrapper = mount<React.ReactElement>(alertOpenAction as React.ReactElement);
// });
//
// afterEach(() => {
// wrapper.unmount();
// });
//
// test('it invokes updateAlertStatusAction when button clicked', () => {
// wrapper.find(EuiButtonIcon).simulate('click');
//
// expect(updateAlertStatusAction).toHaveBeenCalledWith({
// alertIds: ['event-id'],
// status: 'open',
// setEventsLoading,
// setEventsDeleted,
// onAlertStatusUpdateSuccess,
// onAlertStatusUpdateFailure,
// });
// });
//
// test('it displays expected text on hover', () => {
// const openAlert = wrapper.find(EuiToolTip);
// openAlert.simulate('mouseOver');
// const tooltip = wrapper.find('.euiToolTipPopover').text();
//
// expect(tooltip).toEqual(i18n.ACTION_OPEN_ALERT);
// });
//
// test('it displays expected icon', () => {
// const icon = wrapper.find(EuiButtonIcon).props().iconType;
//
// expect(icon).toEqual('securityAlertDetected');
// });
// });
//
// describe('alert close action', () => {
// let alertsActions: TimelineAction[];
// let alertCloseAction: JSX.Element;
// let wrapper: ReactWrapper<React.ReactElement, unknown>;
//
// beforeEach(() => {
// alertsActions = getAlertActions({
// canUserCRUD: true,
// hasIndexWrite: true,
// setEventsLoading,
// setEventsDeleted,
// createTimeline,
// status: 'closed',
// updateTimelineIsLoading,
// onAlertStatusUpdateSuccess,
// onAlertStatusUpdateFailure,
// });
//
// alertCloseAction = alertsActions[1].getAction({
// eventId: 'event-id',
// ecsData: mockEcsDataWithAlert,
// });
//
// wrapper = mount<React.ReactElement>(alertCloseAction as React.ReactElement);
// });
//
// afterEach(() => {
// wrapper.unmount();
// });
//
// test('it invokes updateAlertStatusAction when status button clicked', () => {
// wrapper.find(EuiButtonIcon).simulate('click');
//
// expect(updateAlertStatusAction).toHaveBeenCalledWith({
// alertIds: ['event-id'],
// status: 'closed',
// setEventsLoading,
// setEventsDeleted,
// onAlertStatusUpdateSuccess,
// onAlertStatusUpdateFailure,
// });
// });
//
// test('it displays expected text on hover', () => {
// const closeAlert = wrapper.find(EuiToolTip);
// closeAlert.simulate('mouseOver');
// const tooltip = wrapper.find('.euiToolTipPopover').text();
// expect(tooltip).toEqual(i18n.ACTION_CLOSE_ALERT);
// });
//
// test('it displays expected icon', () => {
// const icon = wrapper.find(EuiButtonIcon).props().iconType;
//
// expect(icon).toEqual('securityAlertResolved');
// });
// });
// });
});
Loading

0 comments on commit 681f2d6

Please sign in to comment.