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

[7.x] [App Search] Relevance Tuning: Fix unsaved changes bug (#104951) #105092

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -10,7 +10,7 @@ import '../../../__mocks__/shallow_useeffect.mock';

import React from 'react';

import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';

import { rerender } from '../../../test_helpers';

Expand Down Expand Up @@ -162,10 +162,18 @@ describe('MultiInputRows', () => {
});

describe('onChange', () => {
let wrapper: ShallowWrapper;
const onChange = jest.fn();

beforeEach(() => {
wrapper = shallow(<MultiInputRows {...props} onChange={onChange} />);
});

it('does not call on change on mount', () => {
expect(onChange).not.toHaveBeenCalled();
});

it('returns the current values dynamically on change', () => {
const wrapper = shallow(<MultiInputRows {...props} onChange={onChange} />);
setMockValues({ ...values, values: ['updated'] });
rerender(wrapper);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* 2.0.
*/

import React, { useEffect } from 'react';
import React from 'react';

import { useValues, useActions } from 'kea';
import useUpdateEffect from 'react-use/lib/useUpdateEffect';

import { EuiForm, EuiButton, EuiButtonEmpty, EuiSpacer } from '@elastic/eui';

Expand Down Expand Up @@ -49,7 +50,7 @@ export const MultiInputRows: React.FC<Props> = ({
const { values, addedNewRow, hasEmptyValues, hasOnlyOneValue } = useValues(logic);
const { addValue, editValue, deleteValue } = useActions(logic);

useEffect(() => {
useUpdateEffect(() => {
if (onChange) {
onChange(filterEmptyValues(values));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('RelevanceTuningLogic', () => {
});

describe('updatePrecision', () => {
it('should set precision inside search settings', () => {
it('should set precision inside search settings and set unsavedChanges to true', () => {
mount();
RelevanceTuningLogic.actions.updatePrecision(9);

Expand All @@ -239,6 +239,7 @@ describe('RelevanceTuningLogic', () => {
...DEFAULT_VALUES.searchSettings,
precision: 9,
},
unsavedChanges: true,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const RelevanceTuningLogic = kea<
unsavedChanges: [
false,
{
updatePrecision: () => true,
setSearchSettings: () => true,
setSearchSettingsResponse: () => false,
},
Expand Down