Need an event which fires when there are no more pending search queries #6461
Replies: 2 comments
-
We don't have tests of that type, but couldn't you check that the query of the response is the same as the query you're setting in the state? then all searches are done. |
Beta Was this translation helpful? Give feedback.
-
All Algolia searches pass through the search client returned by the algoliasearch function. You can extend that object with a queueing system as follows: const algoliaClient = algoliasearch(appId, appKey)
let searchQueue = []
const searchClient = {
...algoliaClient,
queue(...promises) {
promises.map(promise => {
if (searchQueue.length === 0) {
document.dispatchEvent(new CustomEvent("algolia-search-queue-start"));
}
searchQueue.push(promise);
promise.then(() => {
searchQueue = searchQueue.filter(p => p !== promise);
if (searchQueue.length === 0) {
document.dispatchEvent(new CustomEvent("algolia-search-queue-resolve"));
}
});
});
return searchQueue
},
search(requests) {
const query = algoliaClient.search(filtered)
this.queue(query)
return query
}
}
export default searchClient This allows you to fetch the query with A second option is to use event listeners against the two events I have the queue system set to dispatch off the document. This way you can listen for the definite start of the query cycle and then listen for the next time the queue empties out. A third option is to use a Performance Observer as outlined in this discussion: #6425 |
Beta Was this translation helpful? Give feedback.
-
I'm trying to write a test in which the test types something in the algolia search box, waits for the results to come back, and then checks if the first result we got was correct or not.
The test case flow looks like this:
However, what ends up happening is that as the test case runs, it types: "B", and the first result that comes up is "Bottom". now, even though there are other characters in the search box by now, and it should have pending queries, there is sometimes a race condition, where it considers that both of the waiting conditions have been fulfilled, so it checks the first result, which is not "Base", it's "bottom" or something else.
Is there something, which I can use to know that all the searches have really already been completed?
Beta Was this translation helpful? Give feedback.
All reactions