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

[Security Solutions][Detection Engine] Updates the edit rules page to only have what is selected for editing #79233

Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,4 @@ describe('WrapperPage', () => {

expect(wrapper.find('Memo(WrapperPageComponent)')).toMatchSnapshot();
});

describe('restrict width', () => {
test('default max width when restrictWidth is true', () => {
const wrapper = shallow(
<TestProviders>
<WrapperPage restrictWidth>
<p>{'Test page'}</p>
</WrapperPage>
</TestProviders>
);

expect(wrapper.find('Memo(WrapperPageComponent)')).toMatchSnapshot();
});

test('custom max width when restrictWidth is number', () => {
const wrapper = shallow(
<TestProviders>
<WrapperPage restrictWidth={600}>
<p>{'Test page'}</p>
</WrapperPage>
</TestProviders>
);

expect(wrapper.find('Memo(WrapperPageComponent)')).toMatchSnapshot();
});

test('custom max width when restrictWidth is string', () => {
const wrapper = shallow(
<TestProviders>
<WrapperPage restrictWidth="600px">
<p>{'Test page'}</p>
</WrapperPage>
</TestProviders>
);

expect(wrapper.find('Memo(WrapperPageComponent)')).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ import { AppGlobalStyle } from '../page/index';
const Wrapper = styled.div`
padding: ${(props) => `${props.theme.eui.paddingSizes.l}`};

&.siemWrapperPage--restrictWidthDefault,
&.siemWrapperPage--restrictWidthCustom {
box-sizing: content-box;
margin: 0 auto;
}

&.siemWrapperPage--restrictWidthDefault {
max-width: 1000px;
}

&.siemWrapperPage--fullHeight {
height: 100%;
display: flex;
Expand Down Expand Up @@ -58,7 +48,6 @@ interface WrapperPageProps {
const WrapperPageComponent: React.FC<WrapperPageProps & CommonProps> = ({
children,
className,
restrictWidth,
style,
noPadding,
noTimeline,
Expand All @@ -74,20 +63,10 @@ const WrapperPageComponent: React.FC<WrapperPageProps & CommonProps> = ({
'siemWrapperPage--noPadding': noPadding,
'siemWrapperPage--withTimeline': !noTimeline,
'siemWrapperPage--fullHeight': globalFullScreen,
'siemWrapperPage--restrictWidthDefault':
restrictWidth && typeof restrictWidth === 'boolean' && restrictWidth === true,
'siemWrapperPage--restrictWidthCustom': restrictWidth && typeof restrictWidth !== 'boolean',
});

let customStyle: WrapperPageProps['style'];

if (restrictWidth && typeof restrictWidth !== 'boolean') {
const value = typeof restrictWidth === 'number' ? `${restrictWidth}px` : restrictWidth;
customStyle = { ...style, maxWidth: value };
}

return (
<Wrapper className={classes} style={customStyle || style} {...otherProps}>
<Wrapper className={classes} style={style} {...otherProps}>
{children}
<AppGlobalStyle />
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,235 @@
*/

import React from 'react';
import { shallow } from 'enzyme';
import { mount, shallow } from 'enzyme';

import { SelectRuleType } from './index';
import { useFormFieldMock } from '../../../../common/mock';
import { TestProviders, useFormFieldMock } from '../../../../common/mock';
jest.mock('../../../../common/lib/kibana');

describe('SelectRuleType', () => {
// I do this to avoid the messy warning from happening
// Warning: React does not recognize the `isVisible` prop on a DOM element.
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(jest.fn());
});

afterEach(() => {
jest.spyOn(console, 'error').mockRestore();
});

it('renders correctly', () => {
const Component = () => {
const field = useFormFieldMock();

return <SelectRuleType field={field} />;
return (
<SelectRuleType
field={field}
describedByIds={[]}
isUpdateView={false}
hasValidLicense={true}
isMlAdmin={true}
/>
);
};
const wrapper = shallow(<Component />);

expect(wrapper.dive().find('[data-test-subj="selectRuleType"]')).toHaveLength(1);
});

describe('update mode vs. non-update mode', () => {
it('renders all the cards when not in update mode', () => {
const field = useFormFieldMock<unknown>({ value: 'query' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={false}
hasValidLicense={true}
isMlAdmin={true}
/>
</TestProviders>
);
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeTruthy();
});

it('renders only the card selected when in update mode of "eql"', () => {
const field = useFormFieldMock<unknown>({ value: 'eql' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={true}
hasValidLicense={true}
isMlAdmin={true}
/>
</TestProviders>
);
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeFalsy();
});

it('renders only the card selected when in update mode of "machine_learning', () => {
const field = useFormFieldMock<unknown>({ value: 'machine_learning' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={true}
hasValidLicense={true}
isMlAdmin={true}
/>
</TestProviders>
);
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeFalsy();
});

it('renders only the card selected when in update mode of "query', () => {
const field = useFormFieldMock<unknown>({ value: 'query' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={true}
hasValidLicense={true}
isMlAdmin={true}
/>
</TestProviders>
);
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeFalsy();
});

it('renders only the card selected when in update mode of "threshold"', () => {
const field = useFormFieldMock<unknown>({ value: 'threshold' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={true}
hasValidLicense={true}
isMlAdmin={true}
/>
</TestProviders>
);
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeFalsy();
});

it('renders only the card selected when in update mode of "threat_match', () => {
const field = useFormFieldMock<unknown>({ value: 'threat_match' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={true}
hasValidLicense={true}
isMlAdmin={true}
/>
</TestProviders>
);
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeTruthy();
});
});

describe('permissions', () => {
it('renders machine learning as disabled if "hasValidLicense" is false and it is not selected', () => {
const field = useFormFieldMock<unknown>({ value: 'query' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={false}
hasValidLicense={false}
isMlAdmin={true}
/>
</TestProviders>
);
expect(
wrapper.find('[data-test-subj="machineLearningRuleType"]').first().prop('isDisabled')
).toEqual(true);
});

it('renders machine learning as not disabled if "hasValidLicense" is false and it is selected', () => {
const field = useFormFieldMock<unknown>({ value: 'machine_learning' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={false}
hasValidLicense={false}
isMlAdmin={true}
/>
</TestProviders>
);
expect(
wrapper.find('[data-test-subj="machineLearningRuleType"]').first().prop('isDisabled')
).toEqual(false);
});

it('renders machine learning as disabled if "isMlAdmin" is false and it is not selected', () => {
const field = useFormFieldMock<unknown>({ value: 'query' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={false}
hasValidLicense={true}
isMlAdmin={false}
/>
</TestProviders>
);
expect(
wrapper.find('[data-test-subj="machineLearningRuleType"]').first().prop('isDisabled')
).toEqual(true);
});

it('renders machine learning as not disabled if "isMlAdmin" is false and it is selected', () => {
const field = useFormFieldMock<unknown>({ value: 'machine_learning' });
const wrapper = mount(
<TestProviders>
<SelectRuleType
describedByIds={[]}
field={field}
isUpdateView={false}
hasValidLicense={true}
isMlAdmin={false}
/>
</TestProviders>
);
expect(
wrapper.find('[data-test-subj="machineLearningRuleType"]').first().prop('isDisabled')
).toEqual(false);
});
});
});
Loading