Skip to content

Commit f947ffd

Browse files
committed
[Misc] Improve waiting for Tom Select suggestions
* Wait for the actual loading of the remote suggestions instead of hoping to observer the actual loading state (which can easily be missed, leading to flickers).
1 parent be1e519 commit f947ffd

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po

xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/SuggestInputElement.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,20 @@ private void maybeInsertReloadMarker()
263263
private void waitForDropdownReload(boolean remote)
264264
{
265265
if (remote) {
266-
// Wait for remote suggestions to be fetched.
267-
getDriver().waitUntilCondition(driver -> isLoading());
268-
} else {
269-
// Wait for cached suggestions.
270-
getDriver().waitUntilCondition(ExpectedConditions.numberOfElementsToBe(
271-
By.cssSelector(".ts-dropdown.active .xwiki-selectize-dropdown-reload-marker"), 0));
266+
// Wait for the remote suggestions for the current input value to be fetched. We check TomSelect's
267+
// loadedSearches cache (a monotonic signal) rather than observing the transient "loading" CSS class,
268+
// which can be added and removed between two Selenium polls (or skipped entirely for cached queries),
269+
// causing spurious timeouts.
270+
getDriver().waitUntilCondition(driver -> Boolean.TRUE.equals(getDriver().executeScript("""
271+
const selectize = arguments[0].selectize;
272+
return !!selectize && selectize.loadedSearches.hasOwnProperty(selectize.get$('control_input').val());
273+
""", this.originalInput)));
272274
}
275+
// Wait for the dropdown content to be reloaded. The reload marker inserted before typing is removed when the
276+
// content is cleared and re-rendered, even if the new content is identical to the previous one. When no marker
277+
// was inserted (the dropdown wasn't open before typing) the count is already 0 and this passes instantly.
278+
getDriver().waitUntilCondition(ExpectedConditions.numberOfElementsToBe(
279+
By.cssSelector(".ts-dropdown.active .xwiki-selectize-dropdown-reload-marker"), 0));
273280
this.shouldWaitForRemoteSuggestions = false;
274281
}
275282

0 commit comments

Comments
 (0)