DEV: resets user search cache between tests (#13873)

DEV: resets user search cache between tests (#13873)

The current behaviour was producing random tests failures which where consistently reproducible using seed=32037592518471299633729129648744282271

The cause of this error, is a previous test not giving any topicId or categoryId resulting in a cache key “undefined-undefined”, just like a possibly previous test. Reseting cache between tests, seems the most straightforward and future proof solution

diff --git a/app/assets/javascripts/discourse/app/lib/user-search.js b/app/assets/javascripts/discourse/app/lib/user-search.js
index 79b3c58..7cde342 100644
--- a/app/assets/javascripts/discourse/app/lib/user-search.js
+++ b/app/assets/javascripts/discourse/app/lib/user-search.js
@@ -12,6 +12,14 @@ let cache = {},
   currentTerm,
   oldSearch;
 
+export function resetUserSearchCache() {
+  cache = {};
+  cacheKey = null;
+  cacheTime = null;
+  currentTerm = null;
+  oldSearch = null;
+}
+
 function performSearch(
   term,
   topicId,
diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
index 6c7ae49..b6b4410 100644
--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
@@ -34,6 +34,7 @@ import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/
 import { resetTopicTitleDecorators } from "discourse/components/topic-title";
 import { resetUsernameDecorators } from "discourse/helpers/decorate-username-selector";
 import { resetWidgetCleanCallbacks } from "discourse/components/mount-widget";
+import { resetUserSearchCache } from "discourse/lib/user-search";
 import sessionFixtures from "discourse/tests/fixtures/session-fixtures";
 import { setTopicList } from "discourse/lib/topic-list-tracker";
 import sinon from "sinon";
@@ -272,6 +273,7 @@ export function acceptance(name, optionsOrCallback) {
       resetUsernameDecorators();
       resetOneboxCache();
       resetCustomPostMessageCallbacks();
+      resetUserSearchCache();
       clearCustomNavItemHref();
       setTopicList(null);
       _clearSnapshots();

GitHub sha: b673fee9464e823de3c3423a5f8c45732896b429

This commit appears in #13873 which was approved by CvX and tgxworld. It was merged by jjaffeux.