2024-07-04 19:34:48 +08:00
|
|
|
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";
|
2024-11-10 09:06:03 +08:00
|
|
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from 'discourse-i18n';
|
2024-07-04 19:34:48 +08:00
|
|
|
|
|
|
|
module("Poll | Component | poll-buttons-dropdown", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
test("Renders a clickable dropdown menu with a close option", async function (assert) {
|
2024-07-11 11:19:04 +08:00
|
|
|
this.siteSettings.data_explorer_enabled = true;
|
|
|
|
this.siteSettings.poll_export_data_explorer_query_id = 18;
|
|
|
|
this.currentUser.setProperties({ admin: true });
|
|
|
|
|
2024-07-04 19:34:48 +08:00
|
|
|
this.setProperties({
|
2024-07-11 11:19:04 +08:00
|
|
|
closed: true,
|
|
|
|
voters: 3,
|
2024-07-04 19:34:48 +08:00
|
|
|
isStaff: true,
|
|
|
|
isMe: false,
|
|
|
|
topicArchived: false,
|
|
|
|
groupableUserFields: [],
|
|
|
|
isAutomaticallyClosed: false,
|
|
|
|
dropDownClick: () => {},
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<PollButtonsDropdown
|
|
|
|
@closed={{this.closed}}
|
|
|
|
@voters={{this.voters}}
|
|
|
|
@isStaff={{this.isStaff}}
|
|
|
|
@isMe={{this.isMe}}
|
|
|
|
@topicArchived={{this.topicArchived}}
|
|
|
|
@groupableUserFields={{this.groupableUserFields}}
|
|
|
|
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
|
|
|
|
@dropDownClick={{this.dropDownClick}}
|
|
|
|
/>`);
|
|
|
|
|
|
|
|
await click(".widget-dropdown-header");
|
|
|
|
|
2024-08-07 17:46:29 +08:00
|
|
|
assert.dom("li.dropdown-menu__item").exists({ count: 2 });
|
2024-07-04 19:34:48 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
query("li.dropdown-menu__item span").textContent.trim(),
|
2024-11-20 04:45:18 +08:00
|
|
|
i18n("poll.export-results.label"),
|
2024-07-11 11:19:04 +08:00
|
|
|
"displays the poll Export action"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-08-07 17:46:29 +08:00
|
|
|
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`<PollButtonsDropdown
|
|
|
|
@closed={{this.closed}}
|
|
|
|
@voters={{this.voters}}
|
|
|
|
@isStaff={{this.isStaff}}
|
|
|
|
@isMe={{this.isMe}}
|
|
|
|
@topicArchived={{this.topicArchived}}
|
|
|
|
@groupableUserFields={{this.groupableUserFields}}
|
|
|
|
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
|
|
|
|
@dropDownClick={{this.dropDownClick}}
|
|
|
|
@availableDisplayMode={{this.availableDisplayMode}}
|
|
|
|
/>`);
|
|
|
|
|
|
|
|
await click(".widget-dropdown-header");
|
|
|
|
|
2024-11-10 09:06:03 +08:00
|
|
|
assert.dom("li.dropdown-menu__item").exists({ count: 2 });
|
2024-08-07 17:46:29 +08:00
|
|
|
assert
|
|
|
|
.dom(query("li.dropdown-menu__item span"))
|
|
|
|
.hasText(
|
2024-11-20 04:45:18 +08:00
|
|
|
i18n("poll.show-tally.label"),
|
2024-08-07 17:46:29 +08:00
|
|
|
"displays the show absolute button"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-07-11 11:19:04 +08:00
|
|
|
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`<PollButtonsDropdown
|
|
|
|
@closed={{this.closed}}
|
|
|
|
@voters={{this.voters}}
|
|
|
|
@isStaff={{this.isStaff}}
|
|
|
|
@isMe={{this.isMe}}
|
|
|
|
@topicArchived={{this.topicArchived}}
|
|
|
|
@groupableUserFields={{this.groupableUserFields}}
|
|
|
|
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
|
|
|
|
@dropDownClick={{this.dropDownClick}}
|
|
|
|
/>`);
|
|
|
|
|
2024-11-10 09:06:03 +08:00
|
|
|
assert.dom(".widget-dropdown-header").doesNotExist();
|
|
|
|
assert.dom("button.widget-button").exists({ count: 1 });
|
2024-07-11 11:19:04 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
query("button.widget-button span.d-button-label").textContent.trim(),
|
2024-11-20 04:45:18 +08:00
|
|
|
i18n("poll.breakdown.breakdown"),
|
2024-07-04 19:34:48 +08:00
|
|
|
"displays the poll Close action"
|
|
|
|
);
|
|
|
|
});
|
2024-07-11 11:19:04 +08:00
|
|
|
|
|
|
|
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`<PollButtonsDropdown
|
|
|
|
@closed={{this.closed}}
|
|
|
|
@voters={{this.voters}}
|
|
|
|
@isStaff={{this.isStaff}}
|
|
|
|
@isMe={{this.isMe}}
|
|
|
|
@topicArchived={{this.topicArchived}}
|
|
|
|
@groupableUserFields={{this.groupableUserFields}}
|
|
|
|
@isAutomaticallyClosed={{this.isAutomaticallyClosed}}
|
|
|
|
@dropDownClick={{this.dropDownClick}}
|
|
|
|
/>`);
|
|
|
|
|
2024-11-10 09:06:03 +08:00
|
|
|
assert.dom(".widget-dropdown-header").doesNotExist();
|
|
|
|
assert.dom("button.widget-button").doesNotExist();
|
2024-07-11 11:19:04 +08:00
|
|
|
});
|
2024-07-04 19:34:48 +08:00
|
|
|
});
|