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

This ensures we do not leak buttons in acceptance tests
This commit is contained in:
Joffrey JAFFEUX
2021-08-05 11:47:49 +10:00
committed by GitHub
parent 354c939656
commit 2ebe900914
3 changed files with 17 additions and 1 deletions
@@ -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);
}
@@ -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];
@@ -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();