From b66bf2b2db16dc68f8270969a6d4dd51d45c7a62 Mon Sep 17 00:00:00 2001 From: Constance Date: Mon, 4 Jan 2021 10:34:40 -0800 Subject: [PATCH] [Enterprise Search] Misc test branch coverage (#86847) * Remove unnecessary || {} branch schema is always required / should never be undefined * Cover if (addFieldFormErrors) branch * Increase coverage of determineTooltipContent by simplifying branching - most of these checks aren't necessary due to early returns * Cover branch in WS source_icon Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../build_search_ui_config.ts | 23 ++++++++----------- .../messaging/determine_tooltip_content.ts | 15 +++--------- .../schema/schema_add_field_modal.test.tsx | 4 ++-- .../shared/source_icon/source_icon.test.tsx | 6 +++++ 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/build_search_ui_config.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/build_search_ui_config.ts index 533adbaf5bab9..78e1fa9e7f3a2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/build_search_ui_config.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/build_search_ui_config.ts @@ -16,19 +16,16 @@ export const buildSearchUIConfig = (apiConnector: object, schema: Schema) => { sortField: 'id', }, searchQuery: { - result_fields: Object.keys(schema || {}).reduce( - (acc: { [key: string]: object }, key: string) => { - acc[key] = { - snippet: { - size: 300, - fallback: true, - }, - raw: {}, - }; - return acc; - }, - {} - ), + result_fields: Object.keys(schema).reduce((acc: { [key: string]: object }, key: string) => { + acc[key] = { + snippet: { + size: 300, + fallback: true, + }, + raw: {}, + }; + return acc; + }, {}), }, }; }; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts index 385831dc511da..b1476dbd171ad 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts @@ -26,21 +26,12 @@ export const determineTooltipContent = ( if (!logRetentionSettings.enabled) { return renderOrReturnMessage(messages.noLogging); } - if (logRetentionSettings.enabled && !ilmEnabled) { + if (!ilmEnabled) { return renderOrReturnMessage(messages.ilmDisabled); } - if ( - logRetentionSettings.enabled && - ilmEnabled && - !logRetentionSettings.retentionPolicy?.isDefault - ) { + if (!logRetentionSettings.retentionPolicy?.isDefault) { return renderOrReturnMessage(messages.customPolicy); - } - if ( - logRetentionSettings.enabled && - ilmEnabled && - logRetentionSettings.retentionPolicy?.isDefault - ) { + } else { return renderOrReturnMessage(messages.defaultPolicy); } }; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx index e10d56ddc09b0..67add0ca94520 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx @@ -41,10 +41,10 @@ describe('SchemaAddFieldModal', () => { expect(wrapper.find(EuiModal)).toHaveLength(1); }); - // No matter what I try I can't get this to actually achieve coverage. it('sets loading state in useEffect', () => { setState(true); - const wrapper = mount(); + const wrapper = mount(); + wrapper.setProps({ ...errors }); const input = wrapper.find(EuiFieldText); expect(input.prop('isLoading')).toEqual(false); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx index 4007f7a69f77a..b411d749b8a25 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx @@ -24,4 +24,10 @@ describe('SourceIcon', () => { expect(wrapper.find('.wrapped-icon')).toHaveLength(1); }); + + it('renders a full bleed icon', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiIcon).prop('type')).toEqual('test-file-stub'); + }); });