Skip to content

Commit

Permalink
fix bug allowing user to type in custom field option for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Mar 2, 2023
1 parent 2ceaa64 commit 6429323
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ describe('BuilderEntryItem', () => {
expect(wrapper.find('.euiFormHelpText.euiFormRow__text').at(0).text()).toEqual(
i18n.CUSTOM_COMBOBOX_OPTION_TEXT
);
expect(wrapper.find('[data-test-subj="exceptionBuilderEntryField"]').at(0).props()).toEqual(
expect.objectContaining({ acceptsCustomOptions: true })
);
});

test('it does not render custom option text when "allowCustomOptions" is "true" and it is a nested entry', () => {
Expand Down Expand Up @@ -154,6 +157,44 @@ describe('BuilderEntryItem', () => {
);

expect(wrapper.find('.euiFormHelpText.euiFormRow__text').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="exceptionBuilderEntryField"]').at(0).props()).toEqual(
expect.objectContaining({ acceptsCustomOptions: false })
);
});

test('it does not render custom option text when "allowCustomOptions" is "false"', () => {
wrapper = mount(
<BuilderEntryItem
autocompleteService={autocompleteStartMock}
entry={{
correspondingKeywordField: undefined,
entryIndex: 0,
field: getField('ip'),
id: '123',
nested: undefined,
operator: isOperator,
parent: undefined,
value: '1234',
}}
httpService={mockKibanaHttpService}
indexPattern={{
fields,
id: '1234',
title: 'logstash-*',
}}
listType="detection"
onChange={jest.fn()}
setErrorsExist={jest.fn()}
setWarningsExist={jest.fn()}
showLabel
allowCustomOptions={false}
/>
);

expect(wrapper.find('.euiFormHelpText.euiFormRow__text').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="exceptionBuilderEntryField"]').at(0).props()).toEqual(
expect.objectContaining({ acceptsCustomOptions: false })
);
});

test('it render mapping issues warning text when field has mapping conflicts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
isLoading={false}
isDisabled={isDisabled || indexPattern == null}
onChange={handleFieldChange}
acceptsCustomOptions={entry.nested == null}
acceptsCustomOptions={entry.nested == null && allowCustomOptions}
data-test-subj="exceptionBuilderEntryField"
showMappingConflicts={true}
/>
Expand Down

0 comments on commit 6429323

Please sign in to comment.