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 Solution][Exceptions] - Update UI exceptions builder nested logic #72490

Merged
merged 23 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
952a105
making estypes and subtype available in indexPatterns
yctercero Jul 17, 2020
4448734
updating graphql types
yctercero Jul 17, 2020
c56a96d
Merge branch 'master' of github.com:yctercero/kibana into index_es_types
yctercero Jul 17, 2020
f059d70
update source graphql type to match expected
yctercero Jul 17, 2020
42de990
cleanup
yctercero Jul 17, 2020
ebcb6d3
tests
yctercero Jul 19, 2020
2861cfa
cleanup
yctercero Jul 19, 2020
760ed31
updated tests, reverted changes to modals, to make sure they were sti…
yctercero Jul 20, 2020
548ead4
Merge branch 'master' of github.com:yctercero/kibana into index_es_types
yctercero Jul 20, 2020
41ea682
wip - adding nested to builder
yctercero Jul 20, 2020
a813031
Merge branch 'master' of github.com:yctercero/kibana into builder_nested
yctercero Jul 20, 2020
67829d3
wip - updating unit tests
yctercero Jul 20, 2020
4f00202
Merge branch 'master' of github.com:yctercero/kibana into builder_nested
yctercero Jul 20, 2020
37cebb5
updated unit tests
yctercero Jul 21, 2020
767d083
cleanup types
yctercero Jul 21, 2020
b62375c
Merge branch 'master' of github.com:yctercero/kibana into builder_nested
yctercero Jul 22, 2020
8b1daca
cleanup
yctercero Jul 22, 2020
f1e577b
updated types
yctercero Jul 22, 2020
2f92856
update unit test
yctercero Jul 22, 2020
bf91b6f
cleanup, cleanup!
yctercero Jul 22, 2020
06864b7
Merge branch 'master' of github.com:yctercero/kibana into builder_nested
yctercero Jul 22, 2020
456b590
minor fix
yctercero Jul 22, 2020
1b4fbac
Merge branch 'master' of github.com:yctercero/kibana into builder_nested
yctercero Jul 22, 2020
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 @@ -52,50 +52,46 @@ describe('AutocompleteFieldListsComponent', () => {
selectedField={getField('ip')}
selectedValue="some-list-id"
isLoading={false}
isClearable={false}
isDisabled={true}
isClearable={true}
isDisabled
onChange={jest.fn()}
/>
</ThemeProvider>
);

await waitFor(() => {
expect(
wrapper
.find(`[data-test-subj="valuesAutocompleteComboBox listsComboxBox"] input`)
.prop('disabled')
).toBeTruthy();
});
expect(
wrapper
.find(`[data-test-subj="valuesAutocompleteComboBox listsComboxBox"] input`)
.prop('disabled')
).toBeTruthy();
});

test('it renders loading if "isLoading" is true', async () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<AutocompleteFieldListsComponent
placeholder="Placeholder text"
selectedField={getField('ip')}
selectedValue="some-list-id"
isLoading={true}
selectedField={getField('@tags')}
selectedValue=""
isLoading
isClearable={false}
isDisabled={false}
onChange={jest.fn()}
/>
</ThemeProvider>
);

await waitFor(() => {
wrapper
.find(`[data-test-subj="valuesAutocompleteComboBox listsComboxBox"] button`)
.at(0)
.simulate('click');
expect(
wrapper
.find(`[data-test-subj="valuesAutocompleteComboBox listsComboxBox"] button`)
.at(0)
.simulate('click');
expect(
wrapper
.find(
`EuiComboBoxOptionsList[data-test-subj="valuesAutocompleteComboBox listsComboxBox-optionsList"]`
)
.prop('isLoading')
).toBeTruthy();
});
.find(
`EuiComboBoxOptionsList[data-test-subj="valuesAutocompleteComboBox listsComboxBox-optionsList"]`
)
.prop('isLoading')
).toBeTruthy();
});

test('it allows user to clear values if "isClearable" is true', async () => {
Expand All @@ -104,19 +100,19 @@ describe('AutocompleteFieldListsComponent', () => {
<AutocompleteFieldListsComponent
placeholder="Placeholder text"
selectedField={getField('ip')}
selectedValue="some-list-id"
selectedValue=""
isLoading={false}
isClearable={true}
isClearable={false}
isDisabled={false}
onChange={jest.fn()}
/>
</ThemeProvider>
);
expect(
wrapper
.find(`[data-test-subj="comboBoxInput"]`)
.hasClass('euiComboBox__inputWrap-isClearable')
).toBeTruthy();
.find('EuiComboBox[data-test-subj="valuesAutocompleteComboBox listsComboxBox"]')
.prop('options')
).toEqual([{ label: 'some name' }]);
});

test('it correctly displays lists that match the selected "keyword" field esType', () => {
Expand Down Expand Up @@ -210,19 +206,24 @@ describe('AutocompleteFieldListsComponent', () => {
onChange: (a: EuiComboBoxOptionOption[]) => void;
}).onChange([{ label: 'some name' }]);

expect(mockOnChange).toHaveBeenCalledWith({
created_at: DATE_NOW,
created_by: 'some user',
description: 'some description',
id: 'some-list-id',
meta: {},
name: 'some name',
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
type: 'ip',
updated_at: DATE_NOW,
updated_by: 'some user',
version: VERSION,
immutable: IMMUTABLE,
await waitFor(() => {
expect(mockOnChange).toHaveBeenCalledWith({
created_at: DATE_NOW,
created_by: 'some user',
description: 'some description',
id: 'some-list-id',
meta: {},
name: 'some name',
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
type: 'ip',
updated_at: DATE_NOW,
updated_by: 'some user',
_version: undefined,
version: VERSION,
deserializer: undefined,
serializer: undefined,
immutable: IMMUTABLE,
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('OperatorComponent', () => {
expect(wrapper.find(`button[data-test-subj="comboBoxClearButton"]`).exists()).toBeTruthy();
});

test('it displays "operatorOptions" if param is passed in', () => {
test('it displays "operatorOptions" if param is passed in with items', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<OperatorComponent
Expand All @@ -95,6 +95,52 @@ describe('OperatorComponent', () => {
).toEqual([{ label: 'is not' }]);
});

test('it does not display "operatorOptions" if param is passed in with no items', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<OperatorComponent
placeholder="Placeholder text"
selectedField={getField('machine.os.raw')}
operator={isOperator}
isDisabled={false}
isLoading={false}
isClearable={false}
onChange={jest.fn()}
operatorOptions={[]}
/>
</ThemeProvider>
);

expect(
wrapper.find(`[data-test-subj="operatorAutocompleteComboBox"]`).at(0).prop('options')
).toEqual([
{
label: 'is',
},
{
label: 'is not',
},
{
label: 'is one of',
},
{
label: 'is not one of',
},
{
label: 'exists',
},
{
label: 'does not exist',
},
{
label: 'is in list',
},
{
label: 'is not in list',
},
]);
});

test('it correctly displays selected operator', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const OperatorComponent: React.FC<OperatorState> = ({
}): JSX.Element => {
const getLabel = useCallback(({ message }): string => message, []);
const optionsMemo = useMemo(
(): OperatorOption[] => (operatorOptions ? operatorOptions : getOperators(selectedField)),
(): OperatorOption[] =>
operatorOptions != null && operatorOptions.length > 0
? operatorOptions
: getOperators(selectedField),
[operatorOptions, selectedField]
);
const selectedOptionsMemo = useMemo((): OperatorOption[] => (operator ? [operator] : []), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export const AddExceptionModal = memo(function AddExceptionModal({
indexPatterns={indexPatterns}
isOrDisabled={false}
isAndDisabled={false}
isNestedDisabled={false}
data-test-subj="alert-exception-builder"
id-aria="alert-exception-builder"
onChange={handleBuilderOnChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,43 @@ storiesOf('Components|Exceptions|BuilderButtonOptions', module)
<BuilderButtonOptions
isAndDisabled={false}
isOrDisabled={false}
isNestedDisabled={false}
isNested={false}
showNestedButton={false}
onOrClicked={action('onClick')}
onAndClicked={action('onClick')}
onNestedClicked={action('onClick')}
onAddClickWhenNested={action('onClick')}
/>
);
})
.add('nested button', () => {
.add('nested button - isNested false', () => {
return (
<BuilderButtonOptions
isAndDisabled={false}
isOrDisabled={false}
isNestedDisabled={false}
isNested={false}
showNestedButton
onOrClicked={action('onClick')}
onAndClicked={action('onClick')}
onNestedClicked={action('onClick')}
onAddClickWhenNested={action('onClick')}
/>
);
})
.add('nested button - isNested true', () => {
return (
<BuilderButtonOptions
isAndDisabled={false}
isOrDisabled={false}
isNestedDisabled={false}
isNested
showNestedButton
onOrClicked={action('onClick')}
onAndClicked={action('onClick')}
onNestedClicked={action('onClick')}
onAddClickWhenNested={action('onClick')}
/>
);
})
Expand All @@ -45,10 +66,13 @@ storiesOf('Components|Exceptions|BuilderButtonOptions', module)
<BuilderButtonOptions
isAndDisabled
isOrDisabled={false}
isNestedDisabled={false}
isNested={false}
showNestedButton={false}
onOrClicked={action('onClick')}
onAndClicked={action('onClick')}
onNestedClicked={action('onClick')}
onAddClickWhenNested={action('onClick')}
/>
);
})
Expand All @@ -57,10 +81,28 @@ storiesOf('Components|Exceptions|BuilderButtonOptions', module)
<BuilderButtonOptions
isAndDisabled={false}
isOrDisabled
isNestedDisabled={false}
isNested={false}
showNestedButton={false}
onOrClicked={action('onClick')}
onAndClicked={action('onClick')}
onNestedClicked={action('onClick')}
onAddClickWhenNested={action('onClick')}
/>
);
})
.add('nested disabled', () => {
return (
<BuilderButtonOptions
isAndDisabled={false}
isOrDisabled={false}
isNestedDisabled
isNested={false}
showNestedButton
onOrClicked={action('onClick')}
onAndClicked={action('onClick')}
onNestedClicked={action('onClick')}
onAddClickWhenNested={action('onClick')}
/>
);
});
Loading