import { click, render } from "@ember/test-helpers"; import hbs from "htmlbars-inline-precompile"; import { module, test } from "qunit"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { query } from "discourse/tests/helpers/qunit-helpers"; import I18n from "discourse-i18n"; 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: true, voters: 3, isStaff: true, isMe: false, topicArchived: false, groupableUserFields: [], isAutomaticallyClosed: false, dropDownClick: () => {}, }); await render(hbs``); await click(".widget-dropdown-header"); assert.dom("li.dropdown-menu__item").exists({ count: 2 }); assert.strictEqual( query("li.dropdown-menu__item span").textContent.trim(), I18n.t("poll.export-results.label"), "displays the poll Export action" ); }); test("Renders a show-tally button when poll is a bar chart", async function (assert) { this.setProperties({ closed: false, voters: 2, isStaff: false, isMe: false, topicArchived: false, groupableUserFields: ["stuff"], isAutomaticallyClosed: false, dropDownClick: () => {}, availableDisplayMode: "showTally", }); await render(hbs``); await click(".widget-dropdown-header"); assert.dom("li.dropdown-menu__item").exists({ count: 2 }); assert .dom(query("li.dropdown-menu__item span")) .hasText( I18n.t("poll.show-tally.label"), "displays the show absolute button" ); }); 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.dom(".widget-dropdown-header").doesNotExist(); assert.dom("button.widget-button").exists({ count: 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.dom(".widget-dropdown-header").doesNotExist(); assert.dom("button.widget-button").doesNotExist(); }); });