From 3c9226c222ddf4c55f6bae5e0321d4c6e9cb8a78 Mon Sep 17 00:00:00 2001 From: David Sanchez Soler Date: Tue, 8 Jun 2021 15:44:04 +0200 Subject: [PATCH] Blocks save event filter with a white space name --- .../view/components/form/index.test.tsx | 17 +++++++++++++++++ .../view/components/form/index.tsx | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.test.tsx b/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.test.tsx index 0867d0542e4c1..f8d1d086c215f 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.test.tsx @@ -102,6 +102,23 @@ describe('Event filter form', () => { expect(store.getState()!.management!.eventFilters!.form!.hasNameError).toBeFalsy(); }); + it('should change name with a white space still shows an error', async () => { + component = renderComponentWithdata(); + + const nameInput = component.getByPlaceholderText(NAME_PLACEHOLDER); + + act(() => { + fireEvent.change(nameInput, { + target: { + value: ' ', + }, + }); + }); + + expect(store.getState()!.management!.eventFilters!.form!.entry!.name).toBe(''); + expect(store.getState()!.management!.eventFilters!.form!.hasNameError).toBeTruthy(); + }); + it('should change comments', async () => { component = renderComponentWithdata(); diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx b/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx index 83fd6ff1a366d..c9f55d4ff3699 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx @@ -90,11 +90,12 @@ export const EventFiltersForm: React.FC = memo( const handleOnChangeName = useCallback( (e: React.ChangeEvent) => { if (!exception) return; + const name = e.target.value.toString().trim(); dispatch({ type: 'eventFiltersChangeForm', payload: { - entry: { ...exception, name: e.target.value.toString() }, - hasNameError: !e.target.value, + entry: { ...exception, name }, + hasNameError: !name, }, }); },