From f6677044f8713af6a4027a1328bb2fb12dfef971 Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Mon, 20 Jul 2020 16:10:25 -0400 Subject: [PATCH] applying feedback --- .../autocomplete/field_value_lists.test.tsx | 93 ++++++++++--------- .../components/autocomplete/helpers.test.ts | 12 --- .../common/components/autocomplete/helpers.ts | 8 +- 3 files changed, 49 insertions(+), 64 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx b/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx index 51a7fd6abf513..1ff5d770521f3 100644 --- a/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx @@ -8,21 +8,26 @@ import { ThemeProvider } from 'styled-components'; import { mount } from 'enzyme'; import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui'; -import { act } from 'react-dom/test-utils'; +// we don't have the types for waitFor just yet, so using "as waitFor" until when we do +import { wait as waitFor } from '@testing-library/react'; import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts'; -import { AutocompleteFieldListsComponent } from './field_value_lists'; +import { ListSchema } from '../../../lists_plugin_deps'; import { getFoundListSchemaMock } from '../../../../../lists/common/schemas/response/found_list_schema.mock'; import { getListResponseMock } from '../../../../../lists/common/schemas/response/list_schema.mock'; -import { wait } from '../../../common/lib/helpers'; +import { DATE_NOW } from '../../../../../lists/common/constants.mock'; + +import { AutocompleteFieldListsComponent } from './field_value_lists'; jest.mock('../../../common/lib/kibana'); const mockStart = jest.fn(); -const mockKeywordList = getListResponseMock(); -mockKeywordList.id = 'keyword_list'; -mockKeywordList.type = 'keyword'; -mockKeywordList.name = 'keyword list'; -const mockResult = getFoundListSchemaMock(); +const mockKeywordList: ListSchema = { + ...getListResponseMock(), + id: 'keyword_list', + type: 'keyword', + name: 'keyword list', +}; +const mockResult = { ...getFoundListSchemaMock() }; mockResult.data = [...mockResult.data, mockKeywordList]; jest.mock('../../../lists_plugin_deps', () => { const originalModule = jest.requireActual('../../../lists_plugin_deps'); @@ -40,21 +45,21 @@ jest.mock('../../../lists_plugin_deps', () => { describe('AutocompleteFieldListsComponent', () => { test('it renders disabled if "isDisabled" is true', async () => { - await act(async () => { - const wrapper = mount( - ({ eui: euiLightVars, darkMode: false })}> - - - ); - await wait(); + const wrapper = mount( + ({ eui: euiLightVars, darkMode: false })}> + + + ); + + await waitFor(() => { expect( wrapper .find(`[data-test-subj="valuesAutocompleteComboBox listsComboxBox"] input`) @@ -64,21 +69,21 @@ describe('AutocompleteFieldListsComponent', () => { }); test('it renders loading if "isLoading" is true', async () => { - await act(async () => { - const wrapper = mount( - ({ eui: euiLightVars, darkMode: false })}> - - - ); - await wait(); + const wrapper = mount( + ({ eui: euiLightVars, darkMode: false })}> + + + ); + + await waitFor(() => { wrapper .find(`[data-test-subj="valuesAutocompleteComboBox listsComboxBox"] button`) .at(0) @@ -201,14 +206,12 @@ describe('AutocompleteFieldListsComponent', () => { ); - await act(async () => { - ((wrapper.find(EuiComboBox).props() as unknown) as { - onChange: (a: EuiComboBoxOptionOption[]) => void; - }).onChange([{ label: 'some name' }]); - }); + ((wrapper.find(EuiComboBox).props() as unknown) as { + onChange: (a: EuiComboBoxOptionOption[]) => void; + }).onChange([{ label: 'some name' }]); expect(mockOnChange).toHaveBeenCalledWith({ - created_at: '2020-04-20T15:25:31.830Z', + created_at: DATE_NOW, created_by: 'some user', description: 'some description', id: 'some-list-id', @@ -216,7 +219,7 @@ describe('AutocompleteFieldListsComponent', () => { name: 'some name', tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e', type: 'ip', - updated_at: '2020-04-20T15:25:31.830Z', + updated_at: DATE_NOW, updated_by: 'some user', }); }); diff --git a/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.test.ts b/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.test.ts index c7e6e22d4ce71..cb07d99913107 100644 --- a/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.test.ts @@ -77,18 +77,6 @@ describe('helpers', () => { expect(isValid).toBeFalsy(); }); - - test('returns true if type is "ip" and value is valid', () => { - const isValid = validateParams('126.45.211.34', getField('ip')); - - expect(isValid).toBeTruthy(); - }); - - test('returns false if type is "ip" and value is not valid', () => { - const isValid = validateParams('hellooo', getField('ip')); - - expect(isValid).toBeFalsy(); - }); }); describe('#getGenericComboBoxProps', () => { diff --git a/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts b/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts index 3363f49ed750b..16659593784db 100644 --- a/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts @@ -7,7 +7,7 @@ import dateMath from '@elastic/datemath'; import { EuiComboBoxOptionOption } from '@elastic/eui'; -import { IFieldType, Ipv4Address } from '../../../../../../../src/plugins/data/common'; +import { IFieldType } from '../../../../../../../src/plugins/data/common'; import { EXCEPTION_OPERATORS, @@ -46,12 +46,6 @@ export const validateParams = ( case 'date': const moment = dateMath.parse(params); return Boolean(moment && moment.isValid()); - case 'ip': - try { - return Boolean(new Ipv4Address(params)); - } catch (e) { - return false; - } default: return acc; }