FIX: Ensure custom composer button 'condition' is run correctly (#26245)

Previously we were only running the `condition` function once, and then overwriting it with a static boolean value. Future changes to composer attributes would not affect button visibility.

This commit fixes the issue and adds an acceptance test for the behavior.
This commit is contained in:
David Taylor 2024-03-19 17:32:52 +00:00 committed by GitHub
parent ce65a88d6a
commit 5098338a96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 1 deletions

View File

@ -435,7 +435,7 @@ export default class ComposerService extends Service {
return options.concat(
customPopupMenuOptions
.map((option) => this._setupPopupMenuOption(option))
.map((option) => this._setupPopupMenuOption({ ...option }))
.filter((o) => o)
);
}

View File

@ -1394,3 +1394,48 @@ acceptance("Composer - current time", function (needs) {
);
});
});
acceptance("composer buttons API", function (needs) {
needs.user();
needs.settings({
allow_uncategorized_topics: true,
});
test("buttons can be added conditionally", async function (assert) {
withPluginApi("0", (api) => {
api.addComposerToolbarPopupMenuOption({
action: (toolbarEvent) => {
toolbarEvent.applySurround("**", "**");
},
icon: "far-bold",
label: "some_label",
condition: (composer) => {
return composer.model.creatingTopic;
},
});
});
await visit("/t/internationalization-localization/280");
await click(".post-controls button.reply");
assert.dom(".d-editor-input").exists("the composer input is visible");
const expectedName = "[en.some_label]";
const dropdown = selectKit(".toolbar-popup-menu-options");
await dropdown.expand();
assert.false(
dropdown.rowByName(expectedName).exists(),
"custom button is not displayed for reply"
);
await visit("/latest");
await click("#create-topic");
await dropdown.expand();
assert.true(
dropdown.rowByName(expectedName).exists(),
"custom button is displayed for new topic"
);
});
});