0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/plugins/poll/test/javascripts/component/poll-info-test.gjs
Régis Hanol 72091d161c
FEATURE: Record who closed a poll (#40989)
Previously, there was no way to tell who closed (or reopened) a poll —
neither the staff action log nor the poll itself recorded it, as raised
in [meta](https://meta.discourse.org/t/who-closed-the-poll/405495).

This change logs `poll_closed`/`poll_opened` staff actions (auto-close
attributed to the system user) and stores `closed_by`/`closed_at` on the
poll, surfacing "Closed by @user" in the poll UI and making the closer
queryable.

---

Also includes a small fix: the poll buttons dropdown rendered a
`<dropdown.divider />` after every item, leaving a stray trailing border
below the last option; it now renders dividers only between items.

**Screenshot**

<img width="1400" height="1200" alt="image"
src="https://github.com/user-attachments/assets/fd04353a-eac6-448d-904e-47b8e5f8f14f"
/>
2026-06-29 12:22:43 +02:00

158 lines
4.3 KiB
Text
Vendored

import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { i18n } from "discourse-i18n";
import PollInfo from "discourse/plugins/poll/discourse/components/poll-info";
const OPTIONS = [
{ id: "1ddc47be0d2315b9711ee8526ca9d83f", html: "This", votes: 2, rank: 0 },
{ id: "70e743697dac09483d7b824eaadb91e1", html: "That", votes: 3, rank: 0 },
{ id: "6c986ebcde3d5822a6e91a695c388094", html: "Other", votes: 5, rank: 0 },
];
module("Component | PollInfo", function (hooks) {
setupRenderingTest(hooks);
test("public multiple poll with results anytime", async function (assert) {
this.setProperties({
isMultiple: true,
min: 1,
max: 2,
options: OPTIONS,
close: null,
closed: false,
results: [],
showResults: false,
postUserId: 59,
isPublic: true,
hasVoted: true,
voters: [],
});
await render(
<template>
<PollInfo
@options={{this.options}}
@min={{this.min}}
@max={{this.max}}
@isMultiple={{this.isMultiple}}
@close={{this.close}}
@closed={{this.closed}}
@results={{this.results}}
@showResults={{this.showResults}}
@postUserId={{this.postUserId}}
@isPublic={{this.isPublic}}
@hasVoted={{this.hasVoted}}
@voters={{this.voters}}
/>
</template>
);
assert.dom(".poll-info_instructions li.multiple-help-text").hasText(
i18n("poll.multiple.help.up_to_max_options", {
count: this.max,
}).replace(/<\/?[^>]+(>|$)/g, ""),
"displays the multiple help text"
);
assert
.dom(".poll-info_instructions li.is-public")
.hasText(
i18n("poll.public.title").replace(/<\/?[^>]+(>|$)/g, ""),
"displays the public label"
);
});
test("public multiple poll with results only shown on vote", async function (assert) {
this.setProperties({
isMultiple: true,
min: 1,
max: 2,
options: OPTIONS,
close: null,
closed: false,
results: "on_vote",
showResults: false,
postUserId: 59,
isPublic: true,
hasVoted: false,
voters: [],
});
await render(
<template>
<PollInfo
@options={{this.options}}
@min={{this.min}}
@max={{this.max}}
@isMultiple={{this.isMultiple}}
@close={{this.close}}
@closed={{this.closed}}
@results={{this.results}}
@showResults={{this.showResults}}
@postUserId={{this.postUserId}}
@isPublic={{this.isPublic}}
@hasVoted={{this.hasVoted}}
@voters={{this.voters}}
/>
</template>
);
assert.dom(".poll-info_instructions li.multiple-help-text").hasText(
i18n("poll.multiple.help.up_to_max_options", {
count: this.max,
}).replace(/<\/?[^>]+(>|$)/g, ""),
"displays the multiple help text"
);
assert
.dom(".poll-info_instructions li.results-on-vote span")
.hasText(
i18n("poll.results.vote.title").replace(/<\/?[^>]+(>|$)/g, ""),
"displays the results on vote label"
);
assert
.dom(".poll-info_instructions li.is-public")
.hasText(
i18n("poll.public.title").replace(/<\/?[^>]+(>|$)/g, ""),
"displays the public label"
);
});
test("displays who closed the poll", async function (assert) {
this.setProperties({
options: OPTIONS,
close: null,
closed: true,
closedBy: { username: "jane" },
results: [],
showResults: false,
postUserId: 59,
isPublic: false,
hasVoted: false,
voters: [],
});
await render(
<template>
<PollInfo
@options={{this.options}}
@close={{this.close}}
@closed={{this.closed}}
@closedBy={{this.closedBy}}
@results={{this.results}}
@showResults={{this.showResults}}
@postUserId={{this.postUserId}}
@isPublic={{this.isPublic}}
@hasVoted={{this.hasVoted}}
@voters={{this.voters}}
/>
</template>
);
assert
.dom(".poll-info_instructions li.poll-info_closed-by span")
.hasText(i18n("poll.closed_by", { username: "jane" }));
});
});