From 9195c7e84112b613a27d0899761364b10230eb9d Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 13 Jan 2021 13:08:06 -0600 Subject: [PATCH 01/13] Add type Our code allows for an array but the type did not. --- .../public/applications/workplace_search/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts index ed4946a019bb0..16ca141d91f47 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts @@ -181,7 +181,7 @@ export interface CustomSource { } export interface Result { - [key: string]: string; + [key: string]: string | string[]; } export interface OptionValue { From d294b05b9dd22b367ea7a8c70bdb80b6815965ce Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 13 Jan 2021 13:08:32 -0600 Subject: [PATCH 02/13] Add exampleResult mock --- .../__mocks__/content_sources.mock.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts index a3042f2df7ac7..c16741c2fc3b8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts @@ -226,3 +226,22 @@ export const sourceConfigData = { consumerKey: 'elastic_enterprise_search_123', }, }; + +export const exampleResult = { + sourceName: 'source', + searchResultConfig: { + titleField: 'otherTitle', + urlField: 'myLink', + color: '#e3e3e3', + descriptionField: 'about', + detailFields: [{ fieldName: 'cats', labal: 'Felines' }], + }, + titleFieldHover: false, + urlFieldHover: false, + exampleDocuments: [ + { + myLink: 'http://foo', + otherTitle: 'foo', + }, + ], +}; From 74bad0a43e98094216f6b2c832f8e662c972e28e Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 13 Jan 2021 17:00:41 -0600 Subject: [PATCH 03/13] Add test-subj attrs --- .../display_settings/example_result_detail_card.tsx | 12 +++++++++--- .../display_settings/example_search_result_group.tsx | 9 +++++++-- .../display_settings/example_standout_result.tsx | 9 +++++++-- .../components/display_settings/result_detail.tsx | 8 ++++++-- .../components/display_settings/subtitle_field.tsx | 5 ++++- .../components/display_settings/title_field.tsx | 9 +++++++-- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx index 468f7d2f7ad05..3278140a2dfe6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.tsx @@ -28,7 +28,7 @@ export const ExampleResultDetailCard: React.FC = () => { const result = exampleDocuments[0]; return ( -
+
@@ -49,7 +49,9 @@ export const ExampleResultDetailCard: React.FC = () => { {urlField ? (
{result[urlField]}
) : ( - URL + + URL + )}
@@ -57,7 +59,11 @@ export const ExampleResultDetailCard: React.FC = () => {
{detailFields.length > 0 ? ( detailFields.map(({ fieldName, label }, index) => ( -
+

{label}

diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.tsx index 14239b1654308..aa7bc4d917886 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.tsx @@ -27,7 +27,7 @@ export const ExampleSearchResultGroup: React.FC = () => { } = useValues(DisplaySettingsLogic); return ( -
+
{ {descriptionField ? (
{result[descriptionField]}
) : ( - Description + + Description + )}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.tsx index 4ef3b1fe14b93..a80680d219aef 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.tsx @@ -30,7 +30,7 @@ export const ExampleStandoutResult: React.FC = () => { const result = exampleDocuments[0]; return ( -
+
{ {descriptionField ? ( {result[descriptionField]} ) : ( - Description + + Description + )}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.tsx index cb65d8ef671e6..5ee484250ca62 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.tsx @@ -80,7 +80,7 @@ export const ResultDetail: React.FC = () => { <> {detailFields.map(({ fieldName, label }, index) => ( {
openEditDetailField(index)} /> removeDetailField(index)} @@ -125,7 +127,9 @@ export const ResultDetail: React.FC = () => { ) : ( -

Add fields and move them into the order you want them to appear.

+

+ Add fields and move them into the order you want them to appear. +

)} diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.tsx index e27052ddffc04..d2f26cd6726df 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.tsx @@ -22,6 +22,7 @@ export const SubtitleField: React.FC = ({ subtitleFieldHover, }) => (
= ({ {subtitleField ? (
{result[subtitleField]}
) : ( - Subtitle + + Subtitle + )}
); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.tsx index a54c0977b464f..fa975c8b11ce0 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.tsx @@ -21,14 +21,19 @@ export const TitleField: React.FC = ({ result, titleField, titl const titleDisplay = Array.isArray(title) ? title.join(', ') : title; return (
{titleField ? ( -
{titleDisplay}
+
+ {titleDisplay} +
) : ( - Title + + Title + )}
); From 694ff04de643b0341eeff7d05c48b4771c9c347f Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 13 Jan 2021 17:07:21 -0600 Subject: [PATCH 04/13] Remove FIXMEs for linter errors The linter was complaining when these were initially migrated, stating that a11y required all mouse events to have focus and blur events. This commit uses the hover events for those. EuiColorPicker was added in error and removing them does not disrupt the linter. --- .../display_settings/search_results.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.tsx index 96b7a6fbe14b5..c1a65d1c52b65 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.tsx @@ -59,8 +59,8 @@ export const SearchResults: React.FC = () => { label="Title" onMouseOver={toggleTitleFieldHover} onMouseOut={toggleTitleFieldHover} - onFocus={() => null} // FIXME - onBlur={() => null} // FIXME + onFocus={toggleTitleFieldHover} + onBlur={toggleTitleFieldHover} > { /> - null} // FIXME - onBlur={() => null} // FIXME - /> + null} // FIXME - onBlur={() => null} // FIXME + onFocus={toggleSubtitleFieldHover} + onBlur={toggleSubtitleFieldHover} > { helpText="This area is optional" onMouseOver={toggleDescriptionFieldHover} onMouseOut={toggleDescriptionFieldHover} - onFocus={() => null} // FIXME - onBlur={() => null} // FIXME + onFocus={toggleDescriptionFieldHover} + onBlur={toggleDescriptionFieldHover} > Date: Wed, 13 Jan 2021 17:09:13 -0600 Subject: [PATCH 05/13] Add tests for components --- .../custom_source_icon.test.tsx | 18 +++ .../example_result_detail_card.test.tsx | 39 ++++++ .../example_search_result_group.test.tsx | 45 +++++++ .../example_standout_result.test.tsx | 45 +++++++ .../field_editor_modal.test.tsx | 103 +++++++++++++++ .../display_settings/result_detail.test.tsx | 111 ++++++++++++++++ .../display_settings/search_results.test.tsx | 124 ++++++++++++++++++ .../display_settings/subtitle_field.test.tsx | 35 +++++ .../display_settings/title_field.test.tsx | 46 +++++++ 9 files changed, 566 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/custom_source_icon.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/custom_source_icon.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/custom_source_icon.test.tsx new file mode 100644 index 0000000000000..9d82ca9c1df19 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/custom_source_icon.test.tsx @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { CustomSourceIcon } from './custom_source_icon'; + +describe('CustomSourceIcon', () => { + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find('svg')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx new file mode 100644 index 0000000000000..0677c835a7021 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues } from '../../../../../__mocks__'; +import { shallow } from 'enzyme'; + +import React from 'react'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { ExampleResultDetailCard } from './example_result_detail_card'; + +describe('ExampleResultDetailCard', () => { + beforeEach(() => { + setMockValues({ ...exampleResult }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="ExampleResultDetailCard"]')).toHaveLength(1); + expect(wrapper.find('[data-test-subj="DetailField"]')).toHaveLength( + exampleResult.searchResultConfig.detailFields.length + ); + }); + + it('shows fallback URL label when no override set', () => { + setMockValues({ ...exampleResult, searchResultConfig: { detailFields: [] } }); + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="DefaultUrlLabel"]')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx new file mode 100644 index 0000000000000..93a8fa564798f --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues } from '../../../../../__mocks__'; +import { shallow } from 'enzyme'; + +import React from 'react'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { CustomSourceIcon } from './custom_source_icon'; + +import { ExampleSearchResultGroup } from './example_search_result_group'; + +describe('ExampleSearchResultGroup', () => { + beforeEach(() => { + setMockValues({ ...exampleResult }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="ExampleSearchResultGroup"]')).toHaveLength(1); + }); + + it('sets correct color prop when dark', () => { + setMockValues({ ...exampleResult, searchResultConfig: { color: '#000', detailFields: [] } }); + const wrapper = shallow(); + + expect(wrapper.find(CustomSourceIcon).prop('color')).toEqual('white'); + }); + + it('shows fallback URL label when no override set', () => { + setMockValues({ ...exampleResult, searchResultConfig: { detailFields: [], color: '#111' } }); + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="DefaultDescriptionLabel"]')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx new file mode 100644 index 0000000000000..60d939eeb888a --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues } from '../../../../../__mocks__'; +import { shallow } from 'enzyme'; + +import React from 'react'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { CustomSourceIcon } from './custom_source_icon'; + +import { ExampleStandoutResult } from './example_standout_result'; + +describe('ExampleStandoutResult', () => { + beforeEach(() => { + setMockValues({ ...exampleResult }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="ExampleStandoutResult"]')).toHaveLength(1); + }); + + it('sets correct color prop when dark', () => { + setMockValues({ ...exampleResult, searchResultConfig: { color: '#000', detailFields: [] } }); + const wrapper = shallow(); + + expect(wrapper.find(CustomSourceIcon).prop('color')).toEqual('white'); + }); + + it('shows fallback URL label when no override set', () => { + setMockValues({ ...exampleResult, searchResultConfig: { detailFields: [], color: '#111' } }); + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="DefaultDescriptionLabel"]')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx new file mode 100644 index 0000000000000..3fd5cb20e5259 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx @@ -0,0 +1,103 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues, setMockActions } from '../../../../../__mocks__'; +import { shallow } from 'enzyme'; + +import React from 'react'; + +import { EuiModal, EuiSelect, EuiFieldText } from '@elastic/eui'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { FieldEditorModal } from './field_editor_modal'; + +describe('FieldEditorModal', () => { + const { searchResultConfig } = exampleResult; + const fieldOptions = [ + { + value: 'foo', + text: 'Foo', + }, + ]; + const availableFieldOptions = [ + { + value: 'bar', + text: 'Bar', + }, + ]; + const toggleFieldEditorModal = jest.fn(); + const addDetailField = jest.fn(); + const updateDetailField = jest.fn(); + + beforeEach(() => { + setMockActions({ + toggleFieldEditorModal, + addDetailField, + updateDetailField, + }); + setMockValues({ + searchResultConfig, + fieldOptions, + availableFieldOptions, + editFieldIndex: 0, + }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiModal)).toHaveLength(1); + }); + + it('sets value on select change', () => { + const wrapper = shallow(); + const select = wrapper.find(EuiSelect); + + select.simulate('change', { target: { value: 'cats' } }); + + expect(select.prop('value')).toEqual('cats'); + }); + + it('sets value on input change', () => { + const wrapper = shallow(); + const input = wrapper.find(EuiFieldText); + + input.simulate('change', { target: { value: '' } }); + + expect(input.prop('value')).toEqual(''); + }); + + it('handles form submission when creating', () => { + setMockValues({ + searchResultConfig, + fieldOptions, + availableFieldOptions, + editFieldIndex: null, + }); + + const wrapper = shallow(); + + const preventDefault = jest.fn(); + wrapper.find('form').simulate('submit', { preventDefault }); + + expect(preventDefault).toHaveBeenCalled(); + expect(addDetailField).toHaveBeenCalled(); + }); + + it('handles form submission when editing', () => { + const wrapper = shallow(); + + const preventDefault = jest.fn(); + wrapper.find('form').simulate('submit', { preventDefault }); + + expect(preventDefault).toHaveBeenCalled(); + expect(updateDetailField).toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx new file mode 100644 index 0000000000000..dd202a3f8ad0d --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx @@ -0,0 +1,111 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues, setMockActions } from '../../../../../__mocks__'; +import { shallow, mount } from 'enzyme'; + +/** + * Mocking necessary due to console warnings from react d-n-d, which EUI uses + * https://stackoverflow.com/a/56674119/1949235 + */ +jest.mock('react-beautiful-dnd', () => ({ + Droppable: ({ children }: { children: any }) => + children( + { + draggableProps: { + style: {}, + }, + innerRef: jest.fn(), + }, + {} + ), + Draggable: ({ children }: { children: any }) => + children( + { + draggableProps: { + style: {}, + }, + innerRef: jest.fn(), + }, + {} + ), + DragDropContext: ({ children }: { children: any }) => children, +})); + +import React from 'react'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { ExampleResultDetailCard } from './example_result_detail_card'; + +import { ResultDetail } from './result_detail'; + +describe('ResultDetail', () => { + const { searchResultConfig, exampleDocuments } = exampleResult; + const availableFieldOptions = [ + { + value: 'foo', + text: 'Foo', + }, + ]; + const toggleFieldEditorModal = jest.fn(); + const setDetailFields = jest.fn(); + const openEditDetailField = jest.fn(); + const removeDetailField = jest.fn(); + + beforeEach(() => { + setMockActions({ + toggleFieldEditorModal, + setDetailFields, + openEditDetailField, + removeDetailField, + }); + setMockValues({ + searchResultConfig, + availableFieldOptions, + exampleDocuments, + }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(ExampleResultDetailCard)).toHaveLength(1); + }); + + it('calls setTitleField on change', () => { + const wrapper = shallow(); + wrapper.find('[data-test-subj="AddFieldButton"]').simulate('click'); + + expect(toggleFieldEditorModal).toHaveBeenCalled(); + }); + + it('handles empty detailFields', () => { + setMockValues({ + searchResultConfig: { + ...searchResultConfig, + detailFields: [], + }, + availableFieldOptions, + exampleDocuments, + }); + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="EmptyFieldsDescription"]')).toHaveLength(1); + }); + + it('handles drag and drop', () => { + const wrapper = mount(); + wrapper.find('[data-test-subj="EditFieldButton"]').first().simulate('click'); + wrapper.find('[data-test-subj="RemoveFieldButton"]').first().simulate('click'); + + expect(openEditDetailField).toHaveBeenCalled(); + expect(removeDetailField).toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx new file mode 100644 index 0000000000000..9e6064f633902 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx @@ -0,0 +1,124 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues, setMockActions } from '../../../../../__mocks__'; +import { shallow } from 'enzyme'; + +import React from 'react'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { ExampleSearchResultGroup } from './example_search_result_group'; +import { ExampleStandoutResult } from './example_standout_result'; + +import { SearchResults } from './search_results'; + +describe('SearchResults', () => { + const { searchResultConfig } = exampleResult; + const fieldOptions = [ + { + value: 'foo', + text: 'Foo', + }, + ]; + const optionalFieldOptions = [ + { + value: 'bar', + text: 'Bar', + }, + ]; + const toggleTitleFieldHover = jest.fn(); + const toggleSubtitleFieldHover = jest.fn(); + const toggleDescriptionFieldHover = jest.fn(); + const setTitleField = jest.fn(); + const setSubtitleField = jest.fn(); + const setDescriptionField = jest.fn(); + const setUrlField = jest.fn(); + const setColorField = jest.fn(); + + beforeEach(() => { + setMockActions({ + toggleTitleFieldHover, + toggleSubtitleFieldHover, + toggleDescriptionFieldHover, + setTitleField, + setSubtitleField, + setDescriptionField, + setUrlField, + setColorField, + }); + setMockValues({ + searchResultConfig, + fieldOptions, + optionalFieldOptions, + }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(ExampleSearchResultGroup)).toHaveLength(1); + expect(wrapper.find(ExampleStandoutResult)).toHaveLength(1); + }); + + it('calls setTitleField on change', () => { + const wrapper = shallow(); + wrapper + .find('[data-test-subj="TitleFieldSelect"]') + .simulate('change', { target: { value: searchResultConfig.titleField } }); + + expect(setTitleField).toHaveBeenCalled(); + }); + + it('calls setUrlField on change', () => { + const wrapper = shallow(); + wrapper + .find('[data-test-subj="UrlFieldSelect"]') + .simulate('change', { target: { value: searchResultConfig.urlField } }); + + expect(setUrlField).toHaveBeenCalled(); + }); + + it('calls setSubtitleField on change', () => { + const wrapper = shallow(); + wrapper + .find('[data-test-subj="SubtitleFieldSelect"]') + .simulate('change', { target: { value: searchResultConfig.titleField } }); + + expect(setSubtitleField).toHaveBeenCalledWith(searchResultConfig.titleField); + }); + + it('calls setDescriptionField on change', () => { + const wrapper = shallow(); + wrapper + .find('[data-test-subj="DescriptionFieldSelect"]') + .simulate('change', { target: { value: searchResultConfig.descriptionField } }); + + expect(setDescriptionField).toHaveBeenCalledWith(searchResultConfig.descriptionField); + }); + + it('handles blank fallbacks', () => { + setMockValues({ + searchResultConfig: { detailFields: [] }, + fieldOptions, + optionalFieldOptions, + }); + const wrapper = shallow(); + wrapper + .find('[data-test-subj="SubtitleFieldSelect"]') + .simulate('change', { target: { value: '' } }); + wrapper + .find('[data-test-subj="DescriptionFieldSelect"]') + .simulate('change', { target: { value: '' } }); + + expect(wrapper.find('[data-test-subj="UrlFieldSelect"]').prop('value')).toEqual(''); + expect(setSubtitleField).toHaveBeenCalledWith(null); + expect(setDescriptionField).toHaveBeenCalledWith(null); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.test.tsx new file mode 100644 index 0000000000000..e577fbae26bd8 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/subtitle_field.test.tsx @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { SubtitleField } from './subtitle_field'; + +describe('SubtitleField', () => { + const result = { foo: 'bar' }; + it('renders', () => { + const props = { + result, + subtitleField: 'foo', + subtitleFieldHover: false, + }; + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="SubtitleField"]')).toHaveLength(1); + }); + + it('shows fallback URL label when no override set', () => { + const props = { + result, + subtitleField: null, + subtitleFieldHover: false, + }; + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="DefaultSubtitleLabel"]')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.test.tsx new file mode 100644 index 0000000000000..558fd7aa8c86a --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/title_field.test.tsx @@ -0,0 +1,46 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { TitleField } from './title_field'; + +describe('TitleField', () => { + const result = { foo: 'bar' }; + it('renders', () => { + const props = { + result, + titleField: 'foo', + titleFieldHover: false, + }; + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="TitleField"]')).toHaveLength(1); + }); + + it('handles title when array', () => { + const props = { + result: { foo: ['baz', 'bar'] }, + titleField: 'foo', + titleFieldHover: false, + }; + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="CustomTitleLabel"]').text()).toEqual('baz, bar'); + }); + + it('shows fallback URL label when no override set', () => { + const props = { + result, + titleField: null, + titleFieldHover: false, + }; + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="DefaultTitleLabel"]')).toHaveLength(1); + }); +}); From 2e0dd86478ed8f9cbbdd096a6c05f4a512824a16 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 13 Jan 2021 17:15:59 -0600 Subject: [PATCH 06/13] Add test for router Also updates routes to use consistent syntax and remove the render prop --- .../display_settings_router.test.tsx | 30 +++++++++++++++++++ .../display_settings_router.tsx | 16 ++++------ 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx new file mode 100644 index 0000000000000..b52887f74bd8f --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues } from '../../../../../__mocks__'; + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { Route, Switch } from 'react-router-dom'; + +import { DisplaySettings } from './display_settings'; + +import { DisplaySettingsRouter } from './display_settings_router'; + +describe('DisplaySettingsRouter', () => { + it('renders', () => { + setMockValues({ isOrganization: true }); + const wrapper = shallow(); + + expect(wrapper.find(DisplaySettings)).toHaveLength(2); + expect(wrapper.find(Switch)).toHaveLength(1); + expect(wrapper.find(Route)).toHaveLength(2); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.tsx index 01ac93735b8a8..2155d8358daed 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.tsx @@ -23,16 +23,12 @@ export const DisplaySettingsRouter: React.FC = () => { const { isOrganization } = useValues(AppLogic); return ( - } - /> - } - /> + + + + + + ); }; From 129715fa12222496a6e66d7a89ca3d7411ee5fa3 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Thu, 14 Jan 2021 13:31:59 -0600 Subject: [PATCH 07/13] Use helper instead of history.push --- .../components/display_settings/display_settings.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx index e34728beef5e5..6972334fc3e58 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx @@ -6,9 +6,7 @@ import React, { FormEvent, useEffect } from 'react'; -import { History } from 'history'; import { useActions, useValues } from 'kea'; -import { useHistory } from 'react-router-dom'; import './display_settings.scss'; @@ -26,6 +24,7 @@ import { getContentSourcePath, } from '../../../../routes'; +import { KibanaLogic } from '../../../../../shared/kibana'; import { AppLogic } from '../../../../app_logic'; import { Loading } from '../../../../../shared/loading'; @@ -45,7 +44,6 @@ interface DisplaySettingsProps { } export const DisplaySettings: React.FC = ({ tabId }) => { - const history = useHistory() as History; const { initializeDisplaySettings, setServerData, resetDisplaySettingsState } = useActions( DisplaySettingsLogic ); @@ -95,7 +93,7 @@ export const DisplaySettings: React.FC = ({ tabId }) => { ? getContentSourcePath(DISPLAY_SETTINGS_RESULT_DETAIL_PATH, sourceId, isOrganization) : getContentSourcePath(DISPLAY_SETTINGS_SEARCH_RESULT_PATH, sourceId, isOrganization); - history.push(path); + KibanaLogic.values.navigateToUrl(path); }; const handleFormSubmit = (e: FormEvent) => { From fda5dec97e7d7c6066e3d7f67bba75ddad17be05 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Thu, 14 Jan 2021 13:37:11 -0600 Subject: [PATCH 08/13] Remove redundant resetDisplaySettingsState method Since all this does is wrap the clearFlashMessages function, we can just call it directly. Also use the new clearFlashMessages helper instead of using FlashMessageLogic directly insideof toggleFieldEditorModal --- .../components/display_settings/display_settings.tsx | 8 ++++---- .../display_settings/display_settings_logic.ts | 9 ++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx index 6972334fc3e58..cf066f3157e39 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.tsx @@ -24,6 +24,8 @@ import { getContentSourcePath, } from '../../../../routes'; +import { clearFlashMessages } from '../../../../../shared/flash_messages'; + import { KibanaLogic } from '../../../../../shared/kibana'; import { AppLogic } from '../../../../app_logic'; @@ -44,9 +46,7 @@ interface DisplaySettingsProps { } export const DisplaySettings: React.FC = ({ tabId }) => { - const { initializeDisplaySettings, setServerData, resetDisplaySettingsState } = useActions( - DisplaySettingsLogic - ); + const { initializeDisplaySettings, setServerData } = useActions(DisplaySettingsLogic); const { dataLoading, @@ -62,7 +62,7 @@ export const DisplaySettings: React.FC = ({ tabId }) => { useEffect(() => { initializeDisplaySettings(); - return resetDisplaySettingsState; + return clearFlashMessages; }, []); useEffect(() => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts index a8636b4a34da1..970d6554b5664 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts @@ -13,7 +13,7 @@ import { HttpLogic } from '../../../../../shared/http'; import { setSuccessMessage, - FlashMessagesLogic, + clearFlashMessages, flashAPIErrors, } from '../../../../../shared/flash_messages'; @@ -61,7 +61,6 @@ interface DisplaySettingsActions { toggleSubtitleFieldHover(): void; toggleDescriptionFieldHover(): void; toggleUrlFieldHover(): void; - resetDisplaySettingsState(): void; } interface DisplaySettingsValues { @@ -117,7 +116,6 @@ export const DisplaySettingsLogic = kea< toggleSubtitleFieldHover: () => true, toggleDescriptionFieldHover: () => true, toggleUrlFieldHover: () => true, - resetDisplaySettingsState: () => true, initializeDisplaySettings: () => true, setServerData: () => true, }, @@ -330,10 +328,7 @@ export const DisplaySettingsLogic = kea< setSuccessMessage(SUCCESS_MESSAGE); }, toggleFieldEditorModal: () => { - FlashMessagesLogic.actions.clearFlashMessages(); - }, - resetDisplaySettingsState: () => { - FlashMessagesLogic.actions.clearFlashMessages(); + clearFlashMessages(); }, }), }); From 6d0e1b4fc3c8934ac41589939de1c70563daac43 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Fri, 15 Jan 2021 10:49:18 -0600 Subject: [PATCH 09/13] Add tests for DisplaySettings container --- .../display_settings.test.tsx | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx new file mode 100644 index 0000000000000..c7d757adcb659 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx @@ -0,0 +1,168 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../../__mocks__/kea.mock'; +import '../../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockValues, setMockActions } from '../../../../../__mocks__'; +import { unmountHandler } from '../../../../../__mocks__/shallow_useeffect.mock'; + +import { shallow } from 'enzyme'; + +jest.mock('../../../../../shared/flash_messages', () => ({ + FlashMessagesLogic: { actions: { clearFlashMessages: jest.fn() } }, +})); + +jest.mock('../../../../../shared/kibana', () => ({ + KibanaLogic: { values: { navigateToUrl: jest.fn() } }, +})); +import { KibanaLogic } from '../../../../../shared/kibana'; + +import React from 'react'; + +import { EuiButton, EuiTabbedContent } from '@elastic/eui'; + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; + +import { Loading } from '../../../../../shared/loading'; +import { ViewContentHeader } from '../../../../components/shared/view_content_header'; + +import { FieldEditorModal } from './field_editor_modal'; + +import { DisplaySettings } from './display_settings'; + +describe('DisplaySettings', () => { + const { exampleDocuments, searchResultConfig } = exampleResult; + const initializeDisplaySettings = jest.fn(); + const setServerData = jest.fn(); + const setColorField = jest.fn(); + + const values = { + isOrganization: true, + dataLoading: false, + sourceId: '123', + addFieldModalVisible: false, + unsavedChanges: false, + exampleDocuments, + searchResultConfig, + }; + + beforeEach(() => { + setMockActions({ + initializeDisplaySettings, + setServerData, + setColorField, + }); + setMockValues({ ...values }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find('form')).toHaveLength(1); + }); + + it('returns loading when loading', () => { + setMockValues({ ...values, dataLoading: true }); + const wrapper = shallow(); + + expect(wrapper.find(Loading)).toHaveLength(1); + }); + + it('handles window.onbeforeunload change', () => { + setMockValues({ ...values, unsavedChanges: true }); + shallow(); + + unmountHandler(); + + expect(window.onbeforeunload).toEqual(null); + }); + + it('handles window.onbeforeunload unmount', () => { + setMockValues({ ...values, unsavedChanges: true }); + shallow(); + + expect(window.onbeforeunload!({} as any)).toEqual( + 'Your display settings have not been saved. Are you sure you want to leave?' + ); + }); + + describe('tabbed content', () => { + const tabs = [ + { + id: 'search_results', + name: 'Search Results', + content: <>, + }, + { + id: 'result_detail', + name: 'Result Detail', + content: <>, + }, + ]; + + it('handles first tab click', () => { + const wrapper = shallow(); + const tabsEl = wrapper.find(EuiTabbedContent); + tabsEl.prop('onTabClick')!(tabs[0]); + + expect(KibanaLogic.values.navigateToUrl).toHaveBeenCalledWith( + '/sources/123/display_settings/' + ); + }); + + it('handles second tab click', () => { + const wrapper = shallow(); + const tabsEl = wrapper.find(EuiTabbedContent); + tabsEl.prop('onTabClick')!(tabs[1]); + + expect(KibanaLogic.values.navigateToUrl).toHaveBeenCalledWith( + '/sources/123/display_settings/result_detail' + ); + }); + }); + + describe('header action', () => { + it('renders button when hasDocuments', () => { + const wrapper = shallow(); + const button = ( + + Save + + ); + + expect(wrapper.find(ViewContentHeader).prop('action')).toStrictEqual(button); + }); + + it('renders null when no documents', () => { + setMockValues({ ...values, exampleDocuments: [] }); + const wrapper = shallow(); + + expect(wrapper.find(ViewContentHeader).prop('action')).toBeNull(); + }); + }); + + it('submits the form', () => { + const wrapper = shallow(); + const simulatedEvent = { + form: 0, + target: { getAttribute: () => '_self' }, + preventDefault: jest.fn(), + }; + + const form = wrapper.find('form'); + form.simulate('submit', simulatedEvent); + expect(simulatedEvent.preventDefault).toHaveBeenCalled(); + expect(setServerData).toHaveBeenCalled(); + }); + + it('renders FieldEditorModal', () => { + setMockValues({ ...values, addFieldModalVisible: true }); + const wrapper = shallow(); + + expect(wrapper.find(FieldEditorModal)).toHaveLength(1); + }); +}); From 13bea548c4474e45fc9b977743c45f176eed945a Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Fri, 15 Jan 2021 15:48:20 -0600 Subject: [PATCH 10/13] Fix a typo and associated tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also adds ‘subtitleField’ that is needed in a future test --- .../__mocks__/content_sources.mock.ts | 3 ++- .../field_editor_modal.test.tsx | 4 ++-- .../display_settings/result_detail.test.tsx | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts index c16741c2fc3b8..49f31f764565f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts @@ -231,10 +231,11 @@ export const exampleResult = { sourceName: 'source', searchResultConfig: { titleField: 'otherTitle', + subtitleField: 'otherSubtitle', urlField: 'myLink', color: '#e3e3e3', descriptionField: 'about', - detailFields: [{ fieldName: 'cats', labal: 'Felines' }], + detailFields: [{ fieldName: 'cats', label: 'Felines' }], }, titleFieldHover: false, urlFieldHover: false, diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx index 3fd5cb20e5259..1f6c6552d9114 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx @@ -69,9 +69,9 @@ describe('FieldEditorModal', () => { const wrapper = shallow(); const input = wrapper.find(EuiFieldText); - input.simulate('change', { target: { value: '' } }); + input.simulate('change', { target: { value: 'Felines' } }); - expect(input.prop('value')).toEqual(''); + expect(input.prop('value')).toEqual('Felines'); }); it('handles form submission when creating', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx index dd202a3f8ad0d..4433c6f799f96 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx @@ -40,6 +40,8 @@ jest.mock('react-beautiful-dnd', () => ({ import React from 'react'; +import { EuiTextColor } from '@elastic/eui'; + import { exampleResult } from '../../../../__mocks__/content_sources.mock'; import { ExampleResultDetailCard } from './example_result_detail_card'; @@ -107,5 +109,24 @@ describe('ResultDetail', () => { expect(openEditDetailField).toHaveBeenCalled(); expect(removeDetailField).toHaveBeenCalled(); + expect(wrapper.find(EuiTextColor).first().text()).toEqual('“Felines”'); + }); + + it('handles empty label fallback', () => { + setMockValues({ + searchResultConfig: { + ...searchResultConfig, + detailFields: [ + { + fieldName: 'foo', + }, + ], + }, + availableFieldOptions, + exampleDocuments, + }); + const wrapper = mount(); + + expect(wrapper.find(EuiTextColor).first().text()).toEqual('“”'); }); }); From 1c6e0d490474989cdfb2bffc09f1e546aba56be3 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Fri, 15 Jan 2021 16:09:11 -0600 Subject: [PATCH 11/13] Add constants from PR to test https://github.com/elastic/kibana/pull/88477 --- .../components/display_settings/search_results.test.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx index 9e6064f633902..02d0b5470972b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx @@ -17,6 +17,7 @@ import { exampleResult } from '../../../../__mocks__/content_sources.mock'; import { ExampleSearchResultGroup } from './example_search_result_group'; import { ExampleStandoutResult } from './example_standout_result'; +import { LEAVE_UNASSIGNED_FIELD } from './constants'; import { SearchResults } from './search_results'; describe('SearchResults', () => { @@ -112,10 +113,10 @@ describe('SearchResults', () => { const wrapper = shallow(); wrapper .find('[data-test-subj="SubtitleFieldSelect"]') - .simulate('change', { target: { value: '' } }); + .simulate('change', { target: { value: LEAVE_UNASSIGNED_FIELD } }); wrapper .find('[data-test-subj="DescriptionFieldSelect"]') - .simulate('change', { target: { value: '' } }); + .simulate('change', { target: { value: LEAVE_UNASSIGNED_FIELD } }); expect(wrapper.find('[data-test-subj="UrlFieldSelect"]').prop('value')).toEqual(''); expect(setSubtitleField).toHaveBeenCalledWith(null); From 3ba0ba21d779b3510b96ef1ea08fbc66f3e9f630 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Fri, 15 Jan 2021 17:25:01 -0600 Subject: [PATCH 12/13] Add tests for DisplaySettingsLogic --- .../__mocks__/content_sources.mock.ts | 5 +- .../display_settings_logic.test.ts | 389 ++++++++++++++++++ .../display_settings_logic.ts | 2 +- 3 files changed, 394 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts index 49f31f764565f..edd69fa626b1d 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts @@ -235,7 +235,10 @@ export const exampleResult = { urlField: 'myLink', color: '#e3e3e3', descriptionField: 'about', - detailFields: [{ fieldName: 'cats', label: 'Felines' }], + detailFields: [ + { fieldName: 'cats', label: 'Felines' }, + { fieldName: 'dogs', label: 'Canines' }, + ], }, titleFieldHover: false, urlFieldHover: false, diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts new file mode 100644 index 0000000000000..aed99bdd950c5 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts @@ -0,0 +1,389 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { LogicMounter } from '../../../../../__mocks__/kea.mock'; + +import { + mockFlashMessageHelpers, + mockHttpValues, + expectedAsyncError, +} from '../../../../../__mocks__'; + +const contentSource = { id: 'source123' }; +jest.mock('../../source_logic', () => ({ + SourceLogic: { values: { contentSource } }, +})); + +import { AppLogic } from '../../../../app_logic'; +jest.mock('../../../../app_logic', () => ({ + AppLogic: { values: { isOrganization: true } }, +})); + +import { exampleResult } from '../../../../__mocks__/content_sources.mock'; +import { LEAVE_UNASSIGNED_FIELD } from './constants'; + +import { DisplaySettingsLogic, defaultSearchResultConfig } from './display_settings_logic'; + +describe('DisplaySettingsLogic', () => { + const { http } = mockHttpValues; + const { clearFlashMessages, flashAPIErrors, setSuccessMessage } = mockFlashMessageHelpers; + const { mount } = new LogicMounter(DisplaySettingsLogic); + + const { searchResultConfig, exampleDocuments } = exampleResult; + + const defaultValues = { + sourceName: '', + sourceId: '', + schemaFields: {}, + exampleDocuments: [], + serverSearchResultConfig: defaultSearchResultConfig, + searchResultConfig: defaultSearchResultConfig, + serverRoute: '', + editFieldIndex: null, + dataLoading: true, + addFieldModalVisible: false, + titleFieldHover: false, + urlFieldHover: false, + subtitleFieldHover: false, + descriptionFieldHover: false, + fieldOptions: [], + optionalFieldOptions: [ + { + value: LEAVE_UNASSIGNED_FIELD, + text: LEAVE_UNASSIGNED_FIELD, + }, + ], + availableFieldOptions: [], + unsavedChanges: false, + }; + + const serverProps = { + sourceName: 'foo', + sourceId: '123', + serverRoute: '/foo', + searchResultConfig, + exampleDocuments, + schemaFields: {}, + }; + + beforeEach(() => { + jest.clearAllMocks(); + mount(); + }); + + it('has expected default values', () => { + expect(DisplaySettingsLogic.values).toEqual(defaultValues); + }); + + describe('actions', () => { + it('onInitializeDisplaySettings', () => { + DisplaySettingsLogic.actions.onInitializeDisplaySettings(serverProps); + + expect(DisplaySettingsLogic.values.sourceName).toEqual(serverProps.sourceName); + expect(DisplaySettingsLogic.values.sourceId).toEqual(serverProps.sourceId); + expect(DisplaySettingsLogic.values.schemaFields).toEqual(serverProps.schemaFields); + expect(DisplaySettingsLogic.values.exampleDocuments).toEqual(serverProps.exampleDocuments); + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual( + serverProps.searchResultConfig + ); + expect(DisplaySettingsLogic.values.serverRoute).toEqual(serverProps.serverRoute); + expect(DisplaySettingsLogic.values.dataLoading).toEqual(false); + }); + + it('setServerResponseData', () => { + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + + expect(DisplaySettingsLogic.values.serverSearchResultConfig).toEqual( + serverProps.searchResultConfig + ); + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual( + serverProps.searchResultConfig + ); + + expect(setSuccessMessage).toHaveBeenCalled(); + }); + + it('handles empty color', () => { + const propsWithoutColor = { + ...serverProps, + searchResultConfig: { + ...serverProps.searchResultConfig, + color: '', + }, + }; + const configWithDefaultColor = { + ...serverProps.searchResultConfig, + color: '#000000', + }; + DisplaySettingsLogic.actions.onInitializeDisplaySettings(propsWithoutColor); + + expect(DisplaySettingsLogic.values.serverSearchResultConfig).toEqual(configWithDefaultColor); + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual(configWithDefaultColor); + }); + + it('setTitleField', () => { + const TITLE = 'newTitle'; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.setTitleField(TITLE); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + titleField: TITLE, + }); + }); + + it('setUrlField', () => { + const URL = 'http://new.url'; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.setUrlField(URL); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + urlField: URL, + }); + }); + + it('setSubtitleField', () => { + const SUBTITLE = 'new sub title'; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.setSubtitleField(SUBTITLE); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + subtitleField: SUBTITLE, + }); + }); + + it('setDescriptionField', () => { + const DESCRIPTION = 'new description'; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.setDescriptionField(DESCRIPTION); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + descriptionField: DESCRIPTION, + }); + }); + + it('setColorField', () => { + const HEX = '#e3e3e3'; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.setColorField(HEX); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + color: HEX, + }); + }); + + it('setDetailFields', () => { + const result = { + destination: { + index: 0, + }, + source: { + index: 1, + }, + }; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.setDetailFields(result as any); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + detailFields: [searchResultConfig.detailFields[1], searchResultConfig.detailFields[0]], + }); + }); + + it('removeDetailField', () => { + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.removeDetailField(0); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + detailFields: [searchResultConfig.detailFields[1]], + }); + }); + + it('addDetailField', () => { + const newField = { label: 'Monkey', fieldName: 'primate' }; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.addDetailField(newField); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + detailFields: [ + searchResultConfig.detailFields[0], + searchResultConfig.detailFields[1], + newField, + ], + }); + }); + + it('updateDetailField', () => { + const updatedField = { label: 'Monkey', fieldName: 'primate' }; + DisplaySettingsLogic.actions.setServerResponseData(serverProps); + DisplaySettingsLogic.actions.updateDetailField(updatedField, 0); + + expect(DisplaySettingsLogic.values.searchResultConfig).toEqual({ + ...searchResultConfig, + detailFields: [updatedField, searchResultConfig.detailFields[1]], + }); + }); + + it('openEditDetailField', () => { + const INDEX = 2; + DisplaySettingsLogic.actions.openEditDetailField(INDEX); + + expect(DisplaySettingsLogic.values.editFieldIndex).toEqual(INDEX); + }); + + it('toggleFieldEditorModal', () => { + DisplaySettingsLogic.actions.toggleFieldEditorModal(); + + expect(DisplaySettingsLogic.values.editFieldIndex).toEqual(null); + expect(DisplaySettingsLogic.values.addFieldModalVisible).toEqual( + !defaultValues.addFieldModalVisible + ); + expect(clearFlashMessages).toHaveBeenCalled(); + }); + + it('toggleTitleFieldHover', () => { + DisplaySettingsLogic.actions.toggleTitleFieldHover(); + + expect(DisplaySettingsLogic.values.titleFieldHover).toEqual(!defaultValues.titleFieldHover); + }); + + it('toggleSubtitleFieldHover', () => { + DisplaySettingsLogic.actions.toggleSubtitleFieldHover(); + + expect(DisplaySettingsLogic.values.subtitleFieldHover).toEqual( + !defaultValues.subtitleFieldHover + ); + }); + + it('toggleDescriptionFieldHover', () => { + DisplaySettingsLogic.actions.toggleDescriptionFieldHover(); + + expect(DisplaySettingsLogic.values.descriptionFieldHover).toEqual( + !defaultValues.descriptionFieldHover + ); + }); + + it('toggleUrlFieldHover', () => { + DisplaySettingsLogic.actions.toggleUrlFieldHover(); + + expect(DisplaySettingsLogic.values.urlFieldHover).toEqual(!defaultValues.urlFieldHover); + }); + }); + + describe('listeners', () => { + describe('initializeDisplaySettings', () => { + it('calls API and sets values (org)', async () => { + const onInitializeDisplaySettingsSpy = jest.spyOn( + DisplaySettingsLogic.actions, + 'onInitializeDisplaySettings' + ); + const promise = Promise.resolve(serverProps); + http.get.mockReturnValue(promise); + DisplaySettingsLogic.actions.initializeDisplaySettings(); + + expect(http.get).toHaveBeenCalledWith( + '/api/workplace_search/org/sources/source123/display_settings/config' + ); + await promise; + expect(onInitializeDisplaySettingsSpy).toHaveBeenCalledWith({ + ...serverProps, + isOrganization: true, + }); + }); + + it('calls API and sets values (account)', async () => { + AppLogic.values.isOrganization = false; + + const onInitializeDisplaySettingsSpy = jest.spyOn( + DisplaySettingsLogic.actions, + 'onInitializeDisplaySettings' + ); + const promise = Promise.resolve(serverProps); + http.get.mockReturnValue(promise); + DisplaySettingsLogic.actions.initializeDisplaySettings(); + + expect(http.get).toHaveBeenCalledWith( + '/api/workplace_search/account/sources/source123/display_settings/config' + ); + await promise; + expect(onInitializeDisplaySettingsSpy).toHaveBeenCalledWith({ + ...serverProps, + isOrganization: false, + }); + }); + + it('handles error', async () => { + const promise = Promise.reject('this is an error'); + http.get.mockReturnValue(promise); + DisplaySettingsLogic.actions.initializeDisplaySettings(); + await expectedAsyncError(promise); + + expect(flashAPIErrors).toHaveBeenCalledWith('this is an error'); + }); + }); + + describe('setServerData', () => { + it('calls API and sets values', async () => { + const setServerResponseDataSpy = jest.spyOn( + DisplaySettingsLogic.actions, + 'setServerResponseData' + ); + const promise = Promise.resolve(serverProps); + http.post.mockReturnValue(promise); + DisplaySettingsLogic.actions.onInitializeDisplaySettings(serverProps); + DisplaySettingsLogic.actions.setServerData(); + + expect(http.post).toHaveBeenCalledWith(serverProps.serverRoute, { + body: JSON.stringify({ ...searchResultConfig }), + }); + await promise; + expect(setServerResponseDataSpy).toHaveBeenCalledWith({ + ...serverProps, + }); + }); + + it('handles error', async () => { + const promise = Promise.reject('this is an error'); + http.post.mockReturnValue(promise); + DisplaySettingsLogic.actions.setServerData(); + await expectedAsyncError(promise); + + expect(flashAPIErrors).toHaveBeenCalledWith('this is an error'); + }); + }); + }); + + describe('selectors', () => { + describe('availableFieldOptions', () => { + it('should handle duplicate', () => { + const propsWithDuplicates = { + ...serverProps, + schemaFields: { + cats: 'string', + dogs: 'string', + monkeys: 'string', + }, + searchResultConfig: { + ...searchResultConfig, + detailsFields: [searchResultConfig.detailFields[0], searchResultConfig.detailFields[1]], + }, + }; + + DisplaySettingsLogic.actions.onInitializeDisplaySettings(propsWithDuplicates); + + expect(DisplaySettingsLogic.values.availableFieldOptions).toEqual([ + { text: 'monkeys', value: 'monkeys' }, + ]); + }); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts index 970d6554b5664..0e85e2ec57937 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts @@ -84,7 +84,7 @@ interface DisplaySettingsValues { unsavedChanges: boolean; } -const defaultSearchResultConfig = { +export const defaultSearchResultConfig = { titleField: '', subtitleField: '', descriptionField: '', From e05599d3d27ef4700d43a95029fcb01587d6cb15 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Fri, 15 Jan 2021 17:36:32 -0600 Subject: [PATCH 13/13] Remove unused imports and use new mocks --- .../display_settings.test.tsx | 21 +++++-------------- .../display_settings_router.test.tsx | 1 - .../example_result_detail_card.test.tsx | 1 - .../example_search_result_group.test.tsx | 1 - .../example_standout_result.test.tsx | 1 - .../field_editor_modal.test.tsx | 1 - .../display_settings/result_detail.test.tsx | 1 - .../display_settings/search_results.test.tsx | 1 - 8 files changed, 5 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx index c7d757adcb659..73e40eec7774d 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings.test.tsx @@ -4,23 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; +import { mockKibanaValues } from '../../../../../__mocks__'; + import { setMockValues, setMockActions } from '../../../../../__mocks__'; import { unmountHandler } from '../../../../../__mocks__/shallow_useeffect.mock'; import { shallow } from 'enzyme'; -jest.mock('../../../../../shared/flash_messages', () => ({ - FlashMessagesLogic: { actions: { clearFlashMessages: jest.fn() } }, -})); - -jest.mock('../../../../../shared/kibana', () => ({ - KibanaLogic: { values: { navigateToUrl: jest.fn() } }, -})); -import { KibanaLogic } from '../../../../../shared/kibana'; - import React from 'react'; import { EuiButton, EuiTabbedContent } from '@elastic/eui'; @@ -35,6 +27,7 @@ import { FieldEditorModal } from './field_editor_modal'; import { DisplaySettings } from './display_settings'; describe('DisplaySettings', () => { + const { navigateToUrl } = mockKibanaValues; const { exampleDocuments, searchResultConfig } = exampleResult; const initializeDisplaySettings = jest.fn(); const setServerData = jest.fn(); @@ -109,9 +102,7 @@ describe('DisplaySettings', () => { const tabsEl = wrapper.find(EuiTabbedContent); tabsEl.prop('onTabClick')!(tabs[0]); - expect(KibanaLogic.values.navigateToUrl).toHaveBeenCalledWith( - '/sources/123/display_settings/' - ); + expect(navigateToUrl).toHaveBeenCalledWith('/sources/123/display_settings/'); }); it('handles second tab click', () => { @@ -119,9 +110,7 @@ describe('DisplaySettings', () => { const tabsEl = wrapper.find(EuiTabbedContent); tabsEl.prop('onTabClick')!(tabs[1]); - expect(KibanaLogic.values.navigateToUrl).toHaveBeenCalledWith( - '/sources/123/display_settings/result_detail' - ); + expect(navigateToUrl).toHaveBeenCalledWith('/sources/123/display_settings/result_detail'); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx index b52887f74bd8f..726bccb201c68 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_router.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues } from '../../../../../__mocks__'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx index 0677c835a7021..30fcb0f6b1ac8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_result_detail_card.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues } from '../../../../../__mocks__'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx index 93a8fa564798f..375e436b6a8a2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_search_result_group.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues } from '../../../../../__mocks__'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx index 60d939eeb888a..4e56753bfa7e2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/example_standout_result.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues } from '../../../../../__mocks__'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx index 1f6c6552d9114..5471df9a6f0be 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/field_editor_modal.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues, setMockActions } from '../../../../../__mocks__'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx index 4433c6f799f96..6d9d60351f3db 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/result_detail.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues, setMockActions } from '../../../../../__mocks__'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx index 02d0b5470972b..776bf012aa895 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/search_results.test.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../../../__mocks__/kea.mock'; import '../../../../../__mocks__/shallow_useeffect.mock'; import { setMockValues, setMockActions } from '../../../../../__mocks__';