[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>
This commit is contained in:
Constance 2021-01-04 10:34:40 -08:00 committed by GitHub
parent d6eda39cec
commit b66bf2b2db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 27 deletions

View file

@ -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;
}, {}),
},
};
};

View file

@ -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);
}
};

View file

@ -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(<SchemaAddFieldModal {...props} {...errors} />);
const wrapper = mount(<SchemaAddFieldModal {...props} />);
wrapper.setProps({ ...errors });
const input = wrapper.find(EuiFieldText);
expect(input.prop('isLoading')).toEqual(false);

View file

@ -24,4 +24,10 @@ describe('SourceIcon', () => {
expect(wrapper.find('.wrapped-icon')).toHaveLength(1);
});
it('renders a full bleed icon', () => {
const wrapper = shallow(<SourceIcon name="foo" fullBleed serviceType="custom" />);
expect(wrapper.find(EuiIcon).prop('type')).toEqual('test-file-stub');
});
});