diff --git a/plugins/poll/assets/javascripts/discourse/components/poll-buttons-dropdown.gjs b/plugins/poll/assets/javascripts/discourse/components/poll-buttons-dropdown.gjs index 774bae7cfaf..6228df3f972 100644 --- a/plugins/poll/assets/javascripts/discourse/components/poll-buttons-dropdown.gjs +++ b/plugins/poll/assets/javascripts/discourse/components/poll-buttons-dropdown.gjs @@ -1,6 +1,6 @@ import Component from "@glimmer/component"; import { fn } from "@ember/helper"; -import { action } from "@ember/object"; +import { action, get } from "@ember/object"; import { inject as service } from "@ember/service"; import DButton from "discourse/components/d-button"; import DropdownMenu from "discourse/components/dropdown-menu"; @@ -107,26 +107,38 @@ export default class PollButtonsDropdownComponent extends Component { } diff --git a/plugins/poll/test/javascripts/component/poll-buttons-dropdown-test.js b/plugins/poll/test/javascripts/component/poll-buttons-dropdown-test.js index 132be51f5ac..3660c15b027 100644 --- a/plugins/poll/test/javascripts/component/poll-buttons-dropdown-test.js +++ b/plugins/poll/test/javascripts/component/poll-buttons-dropdown-test.js @@ -9,9 +9,13 @@ module("Poll | Component | poll-buttons-dropdown", function (hooks) { setupRenderingTest(hooks); test("Renders a clickable dropdown menu with a close option", async function (assert) { + this.siteSettings.data_explorer_enabled = true; + this.siteSettings.poll_export_data_explorer_query_id = 18; + this.currentUser.setProperties({ admin: true }); + this.setProperties({ - closed: false, - voters: [], + closed: true, + voters: 3, isStaff: true, isMe: false, topicArchived: false, @@ -33,12 +37,74 @@ module("Poll | Component | poll-buttons-dropdown", function (hooks) { await click(".widget-dropdown-header"); - assert.strictEqual(count("li.dropdown-menu__item"), 1); + assert.strictEqual(count("li.dropdown-menu__item"), 2); assert.strictEqual( query("li.dropdown-menu__item span").textContent.trim(), - I18n.t("poll.close.label"), + I18n.t("poll.export-results.label"), + "displays the poll Export action" + ); + }); + + test("Renders a single button when there is only one authorised action", async function (assert) { + this.setProperties({ + closed: false, + voters: 2, + isStaff: false, + isMe: false, + topicArchived: false, + groupableUserFields: ["stuff"], + isAutomaticallyClosed: false, + dropDownClick: () => {}, + }); + + await render(hbs``); + + assert.strictEqual(count(".widget-dropdown-header"), 0); + + assert.strictEqual(count("button.widget-button"), 1); + + assert.strictEqual( + query("button.widget-button span.d-button-label").textContent.trim(), + I18n.t("poll.breakdown.breakdown"), "displays the poll Close action" ); }); + + test("Doesn't render a button when user has no authorised actions", async function (assert) { + this.setProperties({ + closed: false, + voters: 0, + isStaff: false, + isMe: false, + topicArchived: false, + groupableUserFields: [], + isAutomaticallyClosed: false, + dropDownClick: () => {}, + }); + + await render(hbs``); + + assert.strictEqual(count(".widget-dropdown-header"), 0); + + assert.strictEqual(count("button.widget-button"), 0); + }); });