-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(searchFunction): make search function provide a better API
* feat(searchFunction): Offer full helper support in search function This implementation offers: - a full helper to modify the parameters before sending the request - all the other search function (searchOnce, searchForFacetValues) - compatibility with async code (no oops effect) * fix(slider): Make sure the slider doesn't update the state twice This commit adds constraints to make sure that a refine call doesn't trigger a new state update and search. It also adds undefined as a value that can be passed as "no boundary selected" for min and max in the refine function (slider connector). * fix(searchFunction): rm unnecessary state update in internals * chore(naming): change name of search helper function * chore(test): test searchFunction in a less altered env The previous setup was not compatible with the kind of manipulation done for implementing the `searchFunction`.
- Loading branch information
Showing
5 changed files
with
75 additions
and
35 deletions.
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
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
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
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,38 @@ | ||
import sinon from 'sinon'; | ||
|
||
// import algoliaSearchHelper from 'algoliasearch-helper'; | ||
import InstantSearch from '../InstantSearch'; | ||
|
||
const appId = 'appId'; | ||
const apiKey = 'apiKey'; | ||
const indexName = 'lifecycle'; | ||
|
||
describe.only('InstantSearch lifecycle', () => { | ||
it('calls the provided searchFunction when used', () => { | ||
const searchFunctionSpy = sinon.spy(h => { | ||
h.setQuery('test').search(); | ||
}); | ||
|
||
const fakeClient = { | ||
search: sinon.spy(), | ||
addAlgoliaAgent: () => {}, | ||
}; | ||
|
||
const search = new InstantSearch({ | ||
appId, | ||
apiKey, | ||
indexName, | ||
searchFunction: searchFunctionSpy, | ||
createAlgoliaClient: () => fakeClient, | ||
}); | ||
|
||
expect(searchFunctionSpy.callCount).toBe(0); | ||
expect(fakeClient.search.callCount).toBe(0); | ||
|
||
search.start(); | ||
|
||
expect(searchFunctionSpy.callCount).toBe(1); | ||
expect(search.helper.state.query).toBe('test'); | ||
expect(fakeClient.search.callCount).toBe(1); | ||
}); | ||
}); |
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