-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Relevance Tuning logic - actions and selectors only, no listeners #89313
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
716ab23
Implemented actions and selectors
JasonStoltz 074190a
Targeted renaming of SearchSettings
JasonStoltz 2ff1eef
Renamed Iboost
JasonStoltz 62e9598
Updated comment
JasonStoltz 8fab3dd
Merge branch 'master' into relevance-tuning-2
JasonStoltz f2db188
Use Record type
JasonStoltz 2eb1d37
Move destructured constant
JasonStoltz 021aea4
Updated test descriptions
JasonStoltz 55dfa70
Updated license
JasonStoltz c69b184
Reorganized logic
JasonStoltz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
296 changes: 296 additions & 0 deletions
296
...public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,296 @@ | ||
/* | ||
* 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__'; | ||
|
||
import { BoostType } from './types'; | ||
|
||
import { RelevanceTuningLogic } from './relevance_tuning_logic'; | ||
|
||
describe('RelevanceTuningLogic', () => { | ||
const searchSettings = { | ||
boosts: { | ||
foo: [ | ||
{ | ||
type: 'value' as BoostType, | ||
factor: 5, | ||
}, | ||
], | ||
}, | ||
search_fields: {}, | ||
}; | ||
const schema = {}; | ||
const schemaConflicts = {}; | ||
const relevanceTuningProps = { | ||
searchSettings, | ||
schema, | ||
schemaConflicts, | ||
}; | ||
const searchResults = [{}, {}]; | ||
|
||
const { mount } = new LogicMounter(RelevanceTuningLogic); | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const DEFAULT_VALUES = { | ||
dataLoading: true, | ||
schema: {}, | ||
schemaConflicts: {}, | ||
searchSettings: {}, | ||
unsavedChanges: false, | ||
filterInputValue: '', | ||
query: '', | ||
resultsLoading: false, | ||
searchResults: null, | ||
showSchemaConflictCallout: true, | ||
engineHasSchemaFields: false, | ||
schemaFields: [], | ||
schemaFieldsWithConflicts: [], | ||
filteredSchemaFields: [], | ||
filteredSchemaFieldsWithConflicts: [], | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('has expected default values', () => { | ||
mount(); | ||
expect(RelevanceTuningLogic.values).toEqual(DEFAULT_VALUES); | ||
}); | ||
|
||
describe('actions', () => { | ||
describe('onInitializeRelevanceTuning', () => { | ||
it('should set state', () => { | ||
mount({ | ||
dataLoading: true, | ||
}); | ||
RelevanceTuningLogic.actions.onInitializeRelevanceTuning(relevanceTuningProps); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
searchSettings, | ||
schema, | ||
dataLoading: false, | ||
schemaConflicts, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setSearchSettings', () => { | ||
it('should set state', () => { | ||
mount({ | ||
unsavedChanges: false, | ||
}); | ||
RelevanceTuningLogic.actions.setSearchSettings(searchSettings); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
searchSettings, | ||
unsavedChanges: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setFilterValue', () => { | ||
it('should set state', () => { | ||
mount(); | ||
RelevanceTuningLogic.actions.setFilterValue('foo'); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
filterInputValue: 'foo', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setSearchQuery', () => { | ||
it('should set state', () => { | ||
mount(); | ||
RelevanceTuningLogic.actions.setSearchQuery('foo'); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
query: 'foo', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setSearchResults', () => { | ||
it('should set state', () => { | ||
mount({ | ||
resultsLoading: true, | ||
}); | ||
RelevanceTuningLogic.actions.setSearchResults(searchResults); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
searchResults, | ||
resultsLoading: false, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setResultsLoading', () => { | ||
it('should set state', () => { | ||
mount({ | ||
resultsLoading: false, | ||
}); | ||
RelevanceTuningLogic.actions.setResultsLoading(true); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
resultsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('clearSearchResults', () => { | ||
it('should set state', () => { | ||
mount({ | ||
searchResults: [{}], | ||
}); | ||
RelevanceTuningLogic.actions.clearSearchResults(); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
searchResults: null, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('resetSearchSettingsState', () => { | ||
it('should set state', () => { | ||
mount({ | ||
dataLoading: false, | ||
}); | ||
RelevanceTuningLogic.actions.resetSearchSettingsState(); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
dataLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('dismissSchemaConflictCallout', () => { | ||
it('should set state', () => { | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mount({ | ||
showSchemaConflictCallout: true, | ||
}); | ||
RelevanceTuningLogic.actions.dismissSchemaConflictCallout(); | ||
|
||
expect(RelevanceTuningLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
showSchemaConflictCallout: false, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('selectors', () => { | ||
describe('engineHasSchemaFields', () => { | ||
it('should return false if there is only a single field in a schema', () => { | ||
// This is because if a schema only has a single field, it is "id", which we do not | ||
// consider a tunable field. | ||
Comment on lines
+196
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 thanks for the explanation! |
||
mount({ | ||
schema: { | ||
id: 'foo', | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.engineHasSchemaFields).toEqual(false); | ||
}); | ||
|
||
it('should return true otherwise', () => { | ||
mount({ | ||
schema: { | ||
id: 'foo', | ||
bar: 'bar', | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.engineHasSchemaFields).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('schemaFields', () => { | ||
it('should return the list of field names from the schema', () => { | ||
mount({ | ||
schema: { | ||
id: 'foo', | ||
bar: 'bar', | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.schemaFields).toEqual(['id', 'bar']); | ||
}); | ||
}); | ||
|
||
describe('schemaFieldsWithConflicts', () => { | ||
it('should return the list of field names that have schema conflicts', () => { | ||
mount({ | ||
schemaConflicts: { | ||
foo: { | ||
text: ['source_engine_1'], | ||
number: ['source_engine_2'], | ||
}, | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.schemaFieldsWithConflicts).toEqual(['foo']); | ||
}); | ||
}); | ||
|
||
describe('filteredSchemaFields', () => { | ||
it('should return a list of schema field names that contain the text from filterInputValue ', () => { | ||
mount({ | ||
filterInputValue: 'ba', | ||
schema: { | ||
id: 'string', | ||
foo: 'string', | ||
bar: 'string', | ||
baz: 'string', | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.filteredSchemaFields).toEqual(['bar', 'baz']); | ||
}); | ||
|
||
it('should return all schema fields if there is no filter applied', () => { | ||
mount({ | ||
filterTerm: '', | ||
schema: { | ||
id: 'string', | ||
foo: 'string', | ||
bar: 'string', | ||
baz: 'string', | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.filteredSchemaFields).toEqual([ | ||
'id', | ||
'foo', | ||
'bar', | ||
'baz', | ||
]); | ||
}); | ||
}); | ||
|
||
describe('filteredSchemaFieldsWithConflicts', () => { | ||
it('should return a list of schema field names that contain the text from filterInputValue, and if that field has a schema conflict', () => { | ||
mount({ | ||
filterInputValue: 'ba', | ||
schema: { | ||
id: 'string', | ||
foo: 'string', | ||
bar: 'string', | ||
baz: 'string', | ||
}, | ||
schemaConflicts: { | ||
bar: { | ||
text: ['source_engine_1'], | ||
number: ['source_engine_2'], | ||
}, | ||
}, | ||
}); | ||
expect(RelevanceTuningLogic.values.filteredSchemaFieldsWithConflicts).toEqual(['bar']); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, I changed the name and overall theme of this file to match its place it the web application, which is "Relevance Tuning", not "Search Settings".
The underlying model that gets updated and persisted is still named
SearchSettings
to match what we call it on the server. So you will still see the "Search Settings" name used in this file.