DEV: resets post menu extra buttons between tests (#13939)

DEV: resets post menu extra buttons between tests (#13939)

This ensures we do not leak buttons in acceptance tests

diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index 8644aca..3e2bf32 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -3,7 +3,11 @@ import ComposerEditor, {
   addComposerUploadMarkdownResolver,
   addComposerUploadProcessor,
 } from "discourse/components/composer-editor";
-import { addButton, removeButton } from "discourse/widgets/post-menu";
+import {
+  addButton,
+  apiExtraButtons,
+  removeButton,
+} from "discourse/widgets/post-menu";
 import {
   addExtraIconRenderer,
   replaceCategoryLinkRenderer,
@@ -428,6 +432,7 @@ class PluginApi {
    * `‍``
    **/
   addPostMenuButton(name, callback) {
+    apiExtraButtons[name] = callback;
     addButton(name, callback);
   }
 
diff --git a/app/assets/javascripts/discourse/app/widgets/post-menu.js b/app/assets/javascripts/discourse/app/widgets/post-menu.js
index 8584170..969bb86 100644
--- a/app/assets/javascripts/discourse/app/widgets/post-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/post-menu.js
@@ -36,11 +36,20 @@ function animateHeart($elem, start, end, complete) {
 
 const _builders = {};
 const _extraButtons = {};
+export let apiExtraButtons = {};
 
 export function addButton(name, builder) {
   _extraButtons[name] = builder;
 }
 
+export function resetPostMenuExtraButtons() {
+  Object.keys(apiExtraButtons).forEach((button) => {
+    removeButton(button);
+  });
+
+  apiExtraButtons = {};
+}
+
 export function removeButton(name) {
   if (_extraButtons[name]) {
     delete _extraButtons[name];
diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
index b92c4dd..4e2b8e3 100644
--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
@@ -24,6 +24,7 @@ import createStore from "discourse/tests/helpers/create-store";
 import deprecated from "discourse-common/lib/deprecated";
 import { flushMap } from "discourse/models/store";
 import { initSearchData } from "discourse/widgets/search-menu";
+import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
 import { isEmpty } from "@ember/utils";
 import { mapRoutes } from "discourse/mapping-router";
 import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";
@@ -275,6 +276,7 @@ export function acceptance(name, optionsOrCallback) {
       resetOneboxCache();
       resetCustomPostMessageCallbacks();
       resetUserSearchCache();
+      resetPostMenuExtraButtons();
       clearNavItems();
       setTopicList(null);
       _clearSnapshots();

GitHub sha: 2ebe900914d07a48344195c1bd5975aa9b35597d

This commit appears in #13939 which was approved by CvX and ZogStriP. It was merged by SamSaffron.