Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App Search] Implement various Relevance Tuning states and form actions #92644

Merged
merged 20 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('BoostItemContent', () => {
expect(actions.updateBoostFactor).toHaveBeenCalledWith('foo', 3, 2);
});

it("will delete the current boost if the 'Delete Boost' button is clicked", () => {
it("will delete the current boost if the 'Delete boost' button is clicked", () => {
const boost = {
factor: 8,
type: 'proximity' as BoostType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const BoostItemContent: React.FC<Props> = ({ boost, index, name }) => {
{i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.boosts.deleteBoostButtonLabel',
{
defaultMessage: 'Delete Boost',
defaultMessage: 'Delete boost',
}
)}
</EuiButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ValueBoostForm: React.FC<Props> = ({ boost, index, name }) => {
{i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.boosts.value.addValueButtonLabel',
{
defaultMessage: 'Add Value',
defaultMessage: 'Add value',
}
)}
</EuiButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,150 @@
* 2.0.
*/
import '../../../__mocks__/shallow_useeffect.mock';
import { setMockActions } from '../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../__mocks__/kea.mock';

// We mock this because otherwise we will get an EngineLogic not mounted error
jest.mock('../engine', () => ({
generateEnginePath: jest.fn(),
}));
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved

import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiEmptyPrompt, EuiPageHeader } from '@elastic/eui';

import { RelevanceTuning } from './relevance_tuning';
import { RelevanceTuningForm } from './relevance_tuning_form';

describe('RelevanceTuning', () => {
let wrapper: ShallowWrapper;
const values = {
engineHasSchemaFields: true,
engine: {
invalidBoosts: false,
unsearchedUnconfirmedFields: false,
},
schemaFieldsWithConflicts: [],
};

const actions = {
initializeRelevanceTuning: jest.fn(),
updateSearchSettings: jest.fn(),
resetSearchSettings: jest.fn(),
};

const subject = () => shallow(<RelevanceTuning engineBreadcrumb={['test']} />);

beforeEach(() => {
jest.clearAllMocks();
setMockValues(values);
setMockActions(actions);
wrapper = shallow(<RelevanceTuning engineBreadcrumb={['test']} />);
});

it('renders', () => {
const wrapper = subject();
expect(wrapper.find(RelevanceTuningForm).exists()).toBe(true);
expect(wrapper.find('[data-test-subj="RelevanceTuningInvalidBoostsCallout"]').exists()).toBe(
false
);
expect(wrapper.find('[data-test-subj="RelevanceTuningUnsearchedFieldsCallout"]').exists()).toBe(
false
);
expect(subject().find('[data-test-subj="SchemaConflictsCallout"]').exists()).toBe(false);
});

it('initializes relevance tuning data', () => {
subject();
expect(actions.initializeRelevanceTuning).toHaveBeenCalled();
});

it('renders a Save button that will save the current changes', () => {
const buttons = subject().find(EuiPageHeader).prop('rightSideItems') as React.ReactElement[];
expect(buttons.length).toBe(2);
const saveButton = shallow(buttons[0]);
saveButton.simulate('click');
expect(actions.updateSearchSettings).toHaveBeenCalled();
});

it('renders a Reset button that will remove all weights and boosts', () => {
const buttons = subject().find(EuiPageHeader).prop('rightSideItems') as React.ReactElement[];
expect(buttons.length).toBe(2);
const resetButton = shallow(buttons[1]);
resetButton.simulate('click');
expect(actions.resetSearchSettings).toHaveBeenCalled();
});

describe('when the engine has no schema', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
// An eninge would have no schema if it is newly created, and no documents have been indexed
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
// yet.
setMockValues({
...values,
engineHasSchemaFields: false,
});
wrapper = subject();
});

it('will not render buttons if the engine has no schema', () => {
setMockValues({
...values,
engineHasSchemaFields: false,
});
const buttons = wrapper.find(EuiPageHeader).prop('rightSideItems') as React.ReactElement[];
expect(buttons.length).toBe(0);
});

it('will render an empty message', () => {
setMockValues({
...values,
engineHasSchemaFields: false,
});
expect(wrapper.find(EuiEmptyPrompt).exists()).toBe(true);
expect(wrapper.find(RelevanceTuningForm).exists()).toBe(false);
});
});

it('shows a message when there are invalid boosts', () => {
// An invalid boost would be if a user creats a functional boost on a number field, then that
// field later changes to text. At this point, the boost still exists but is invalid for
// a text field.
setMockValues({
...values,
engine: {
invalidBoosts: true,
unsearchedUnconfirmedFields: false,
},
});
expect(subject().find('[data-test-subj="RelevanceTuningInvalidBoostsCallout"]').exists()).toBe(
true
);
});

it('shows a message when there are unconfirmed fields', () => {
// An invalid boost would be if a user creats a functional boost on a number field, then that
// field later changes to text. At this point, the boost still exists but is invalid for
// a text field.
setMockValues({
...values,
engine: {
invalidBoosts: false,
unsearchedUnconfirmedFields: true,
},
});
expect(
subject().find('[data-test-subj="RelevanceTuningUnsearchedFieldsCallout"]').exists()
).toBe(true);
});

it('shows a message when there are schema field conflicts', () => {
// Schema conflicts occur when a meta engine has fields in source engines with have differing types,
// hence relevance tuning cannot be applied as we don't know the actual type
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
setMockValues({
...values,
schemaFieldsWithConflicts: ['fe', 'fi', 'fo'],
});
expect(subject().find('[data-test-subj="SchemaConflictsCallout"]').exists()).toBe(true);
});
});
Loading