Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8abc0d3
Add severity field to create API and migration
May 3, 2022
c7986b0
Adds integration test for severity field migration
May 3, 2022
8ff9f9b
remove exclusive test
May 3, 2022
04c413e
Change severity levels
May 3, 2022
9d488bc
Update integration tests for post case
May 3, 2022
13f3406
Add more integration tests
May 3, 2022
a749da5
Fix all cases list test
May 3, 2022
f76213a
Fix some server test
May 3, 2022
d62bf70
Fix util server test
May 3, 2022
8906ccd
Fix client util test
May 3, 2022
99923ec
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 3, 2022
ede3328
Merge branch 'main' into feature/cases-severity-field
academo May 3, 2022
70300c2
Convert event log's duration from number to string in Kibana (keep as…
mikecote May 3, 2022
bcb2ab1
filter o11y rule aggregations (#131301)
mgiota May 3, 2022
7caa070
[Cloud Posture] Display and save rules per benchmark (#131412)
JordanSh May 3, 2022
ed7c949
Adding aria-label for discover data grid select document checkbox (#1…
bhavyarm May 3, 2022
e120e56
Update API docs (#130999)
thomasneirynck May 3, 2022
16467d1
[CI] Use GCS buckets for bazel remote caching (#131345)
brianseeders May 3, 2022
1186b3e
[Actionable Observability] Add license modal to rules table (#131232)
mgiota May 3, 2022
0e91bd6
[RAM] Add shareable rule status filter (#130705)
JiaweiWu May 3, 2022
f11b843
[storybook] Watch for changes in packages (#131467)
clintandrewhall May 3, 2022
c574ab6
Improve saved objects migrations failure errors and logs (#131359)
TinaHeiligers May 4, 2022
fed45c9
[Unified observability] Add tour step to guided setup (#131149)
May 4, 2022
9dd98b9
[Lens] Improved interval input (#131372)
flash1293 May 4, 2022
8fa9dc8
[Vega] Adjust vega doc for usage of ems files (#130948)
flash1293 May 4, 2022
e2b8cf4
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 4, 2022
de4a093
Excess intersections
cnasikas May 4, 2022
87f2cd5
Create severity user action
cnasikas May 4, 2022
6958994
Add severity selector to the case vie wpage
May 4, 2022
23417a1
Add test cases for the severity field
May 4, 2022
caa528a
Add severity to create_case user action
cnasikas May 4, 2022
f528955
Fix and add integration tests
cnasikas May 5, 2022
7a7037a
Minor improvements
cnasikas May 5, 2022
76faded
Merge branch 'main' into feature/cases-severity-field
academo May 5, 2022
4ec9ac3
Merge branch 'feature/cases-severity-field' into feature/cases-severi…
May 5, 2022
58eb811
Add severity user action builder
May 5, 2022
54d6c1e
use correct colors for the severity levels
May 5, 2022
83724b1
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 5, 2022
b2890b1
return null if no severydata found
May 5, 2022
248092a
disable super select if not permissions
May 5, 2022
fff645c
Use isDisabled at the superselect level
May 5, 2022
7d01839
Fix broken TS
May 5, 2022
5f44fbe
Add the severity field to the create form
May 5, 2022
5106252
Fix test
May 5, 2022
c7b9223
Add severity field tests
May 5, 2022
e3e0dca
Add test cases for the severity field in the create form
May 5, 2022
da31573
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 5, 2022
4faab1e
Merge branch 'main' into feature/cases-severity-field-ui
academo May 5, 2022
918d56b
Merge branch 'main' into feature/cases-severity-field-ui
academo May 6, 2022
ca68fda
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 6, 2022
012972c
Merge remote-tracking branch 'origin/feature/cases-severity-field-ui'…
May 6, 2022
3ff11a2
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 6, 2022
ec1f3e3
Add a test case for submit case with a selected severity
May 6, 2022
e3e0560
Add severity to the schema
May 6, 2022
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
5 changes: 5 additions & 0 deletions x-pack/plugins/cases/public/components/create/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { CreateCaseOwnerSelector } from './owner_selector';
import { useCasesContext } from '../cases_context/use_cases_context';
import { useAvailableCasesOwners } from '../app/use_available_owners';
import { CaseAttachments } from '../../types';
import { Severity } from './severity';

interface ContainerProps {
big?: boolean;
Expand Down Expand Up @@ -88,6 +89,9 @@ export const CreateCaseFormFields: React.FC<CreateCaseFormFieldsProps> = React.m
<Container>
<Tags isLoading={isSubmitting} />
</Container>
<Container>
<Severity isLoading={isSubmitting} />
</Container>
{canShowCaseSolutionSelection && (
<Container big>
<CreateCaseOwnerSelector
Expand All @@ -99,6 +103,7 @@ export const CreateCaseFormFields: React.FC<CreateCaseFormFieldsProps> = React.m
<Container big>
<Description isLoading={isSubmitting} />
</Container>
<Container />
Comment thread
academo marked this conversation as resolved.
</>
),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { mount, ReactWrapper } from 'enzyme';
import { act, RenderResult, waitFor, within } from '@testing-library/react';
import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';

import { CommentType, ConnectorTypes } from '../../../common/api';
import { CaseSeverity, CommentType, ConnectorTypes } from '../../../common/api';
import { useKibana } from '../../common/lib/kibana';
import { AppMockRenderer, createAppMockRenderer, TestProviders } from '../../common/mock';
import { usePostCase } from '../../containers/use_post_case';
Expand Down Expand Up @@ -182,6 +182,7 @@ describe('Create case', () => {
</FormContext>
);
expect(renderResult.getByTestId('caseTitle')).toBeTruthy();
expect(renderResult.getByTestId('caseSeverity')).toBeTruthy();
expect(renderResult.getByTestId('caseDescription')).toBeTruthy();
expect(renderResult.getByTestId('caseTags')).toBeTruthy();
expect(renderResult.getByTestId('caseConnectors')).toBeTruthy();
Expand All @@ -208,6 +209,34 @@ describe('Create case', () => {
});
});

it('should post a case on submit click with the selected severity', async () => {
useConnectorsMock.mockReturnValue({
...sampleConnectorData,
connectors: connectorsMock,
});

const renderResult = mockedContext.render(
<FormContext onSuccess={onFormSubmitSuccess}>
<CreateCaseFormFields {...defaultCreateCaseForm} />
<SubmitCaseButton />
</FormContext>
);

await fillFormReactTestingLib(renderResult);

userEvent.click(renderResult.getByTestId('case-severity-selection'));
expect(renderResult.getByTestId('case-severity-selection-high')).toBeTruthy();
userEvent.click(renderResult.getByTestId('case-severity-selection-high'));

userEvent.click(renderResult.getByTestId('create-case-submit'));
await waitFor(() => {
expect(postCase).toBeCalledWith({
...sampleData,
severity: CaseSeverity.HIGH,
});
});
});

it('does not submits the title when the length is longer than 64 characters', async () => {
const longTitle =
'This is a title that should not be saved as it is longer than 64 characters.';
Expand Down Expand Up @@ -285,6 +314,18 @@ describe('Create case', () => {
);
});

it('should select LOW as the default severity', async () => {
Comment thread
academo marked this conversation as resolved.
const renderResult = mockedContext.render(
<FormContext onSuccess={onFormSubmitSuccess}>
<CreateCaseFormFields {...defaultCreateCaseForm} />
<SubmitCaseButton />
</FormContext>
);
expect(renderResult.getByTestId('caseSeverity')).toBeTruthy();
// there should be 2 low elements. one for the options popover and one for the displayed one.
expect(renderResult.getAllByTestId('case-severity-selection-low').length).toBe(2);
Comment thread
academo marked this conversation as resolved.
});

it('should select the default connector set in the configuration', async () => {
useCaseConfigureMock.mockImplementation(() => ({
...useCaseConfigureResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { usePostPushToService } from '../../containers/use_post_push_to_service'

import { useConnectors } from '../../containers/configure/use_connectors';
import { Case } from '../../containers/types';
import { NONE_CONNECTOR_ID } from '../../../common/api';
import { CaseSeverity, NONE_CONNECTOR_ID } from '../../../common/api';
import {
UseCreateAttachments,
useCreateAttachments,
Expand All @@ -28,6 +28,7 @@ const initialCaseValue: FormProps = {
description: '',
tags: [],
title: '',
severity: CaseSeverity.LOW,
connectorId: NONE_CONNECTOR_ID,
fields: null,
syncAlerts: true,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/public/components/create/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* 2.0.
*/

import { CasePostRequest, ConnectorTypes } from '../../../common/api';
import { CasePostRequest, CaseSeverity, ConnectorTypes } from '../../../common/api';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { choices } from '../connectors/mock';

export const sampleTags = ['coke', 'pepsi'];
export const sampleData: CasePostRequest = {
description: 'what a great description',
tags: sampleTags,
severity: CaseSeverity.LOW,
title: 'what a cool title',
connector: {
fields: null,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/cases/public/components/create/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import * as i18n from './translations';

import { OptionalFieldLabel } from './optional_field_label';
import { SEVERITY_TITLE } from '../severity/translations';
const { emptyField, maxLengthField } = fieldValidators;

export const schemaTags = {
Expand Down Expand Up @@ -83,6 +84,9 @@ export const schema: FormSchema<FormProps> = {
],
},
tags: schemaTags,
severity: {
label: SEVERITY_TITLE,
},
connectorId: {
type: FIELD_TYPES.SUPER_SELECT,
label: i18n.CONNECTORS,
Expand Down
79 changes: 79 additions & 0 deletions x-pack/plugins/cases/public/components/create/severity.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 { CaseSeverity } from '../../../common/api';
import React from 'react';
import { AppMockRenderer, createAppMockRenderer } from '../../common/mock';
import { Form, FormHook, useForm } from '../../common/shared_imports';
import { Severity } from './severity';
import { FormProps, schema } from './schema';
import userEvent from '@testing-library/user-event';
import { waitFor } from '@testing-library/dom';

let globalForm: FormHook;
const MockHookWrapperComponent: React.FC = ({ children }) => {
const { form } = useForm<FormProps>({
defaultValue: { severity: CaseSeverity.LOW },
schema: {
severity: schema.severity,
},
});

globalForm = form;

return <Form form={form}>{children}</Form>;
};
describe('Severity form field', () => {
let appMockRender: AppMockRenderer;
beforeEach(() => {
appMockRender = createAppMockRenderer();
});
it('renders', () => {
const result = appMockRender.render(
<MockHookWrapperComponent>
<Severity isLoading={false} />
</MockHookWrapperComponent>
);
expect(result.getByTestId('caseSeverity')).toBeTruthy();
expect(result.getByTestId('case-severity-selection')).not.toHaveAttribute('disabled');
});

// default to LOW in this test configuration
it('defaults to the correct value', () => {
const result = appMockRender.render(
<MockHookWrapperComponent>
<Severity isLoading={false} />
</MockHookWrapperComponent>
);
expect(result.getByTestId('caseSeverity')).toBeTruthy();
// two items. one for the popover one for the selected field
expect(result.getAllByTestId('case-severity-selection-low').length).toBe(2);
});

it('selects the correct value when changed', async () => {
const result = appMockRender.render(
<MockHookWrapperComponent>
<Severity isLoading={false} />
</MockHookWrapperComponent>
);
expect(result.getByTestId('caseSeverity')).toBeTruthy();
userEvent.click(result.getByTestId('case-severity-selection'));
userEvent.click(result.getByTestId('case-severity-selection-high'));
await waitFor(() => {
expect(globalForm.getFormData()).toEqual({ severity: 'high' });
});
});

it('disables when loading data', () => {
const result = appMockRender.render(
<MockHookWrapperComponent>
<Severity isLoading={true} />
</MockHookWrapperComponent>
);
expect(result.getByTestId('case-severity-selection')).toHaveAttribute('disabled');
});
});
50 changes: 50 additions & 0 deletions x-pack/plugins/cases/public/components/create/severity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 { EuiFormRow } from '@elastic/eui';
import React, { memo } from 'react';
import { CaseSeverity } from '../../../common/api';
import { UseField, useFormContext, useFormData } from '../../common/shared_imports';
import { SeveritySelector } from '../severity/selector';
import { SEVERITY_TITLE } from '../severity/translations';

interface Props {
isLoading: boolean;
}

const SeverityFieldFormComponent = ({ isLoading }: { isLoading: boolean }) => {
const { setFieldValue } = useFormContext();
const [{ severity }] = useFormData({ watch: ['severity'] });
const onSeverityChange = (newSeverity: CaseSeverity) => {
setFieldValue('severity', newSeverity);
};
return (
<EuiFormRow data-test-subj="caseSeverity" fullWidth={true} label={SEVERITY_TITLE}>
<SeveritySelector
isLoading={isLoading}
isDisabled={isLoading}
selectedSeverity={severity ?? CaseSeverity.LOW}
onSeverityChange={onSeverityChange}
/>
</EuiFormRow>
);
};
SeverityFieldFormComponent.displayName = 'SeverityFieldForm';

const SeverityComponent: React.FC<Props> = ({ isLoading }) => (
<UseField
path={'severity'}
component={SeverityFieldFormComponent}
componentProps={{
isLoading,
}}
/>
);

SeverityComponent.displayName = 'SeverityComponent';

export const Severity = memo(SeverityComponent);