FIX: make poll voter list expansion persistent (#28352)

* FIX: voter list expansion

* naming improvement

* extend and refine test
This commit is contained in:
Robert 2024-08-19 06:55:22 +01:00 committed by GitHub
parent e1c4cf2566
commit 0679e6eb7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 83 additions and 7 deletions

View File

@ -45,6 +45,7 @@ export default class PollComponent extends Component {
@tracked vote = this.args.attrs.vote || []; @tracked vote = this.args.attrs.vote || [];
@tracked poll = this.args.attrs.poll; @tracked poll = this.args.attrs.poll;
@tracked preloadedVoters = this.defaultPreloadedVoters(); @tracked preloadedVoters = this.defaultPreloadedVoters();
@tracked voterListExpanded = false;
@tracked hasSavedVote = this.args.attrs.hasSavedVote; @tracked hasSavedVote = this.args.attrs.hasSavedVote;
@tracked @tracked
@ -473,8 +474,10 @@ export default class PollComponent extends Component {
@action @action
updatedVoters() { updatedVoters() {
if (!this.voterListExpanded) {
this.preloadedVoters = this.defaultPreloadedVoters(); this.preloadedVoters = this.defaultPreloadedVoters();
} }
}
@action @action
fetchVoters(optionId) { fetchVoters(optionId) {
@ -501,6 +504,7 @@ export default class PollComponent extends Component {
}, },
}) })
.then((result) => { .then((result) => {
this.voterListExpanded = true;
const voters = optionId const voters = optionId
? this.preloadedVoters[optionId].voters ? this.preloadedVoters[optionId].voters
: this.preloadedVoters; : this.preloadedVoters;

View File

@ -551,7 +551,7 @@ acceptance("Poll results", function (needs) {
readers_count: 1, readers_count: 1,
score: 0, score: 0,
yours: true, yours: true,
topic_id: 134, topic_id: 135,
topic_slug: "load-more-poll-voters-ranked-choice", topic_slug: "load-more-poll-voters-ranked-choice",
display_username: null, display_username: null,
primary_group_name: null, primary_group_name: null,
@ -610,7 +610,7 @@ acceptance("Poll results", function (needs) {
votes: 0, votes: 0,
}, },
], ],
voters: 1, voters: 2,
preloaded_voters: { preloaded_voters: {
def034c6770c6fd3754c054ef9ec4721: [ def034c6770c6fd3754c054ef9ec4721: [
{ {
@ -654,7 +654,7 @@ acceptance("Poll results", function (needs) {
votes: 2, votes: 2,
}, },
{ {
digest: "def034c6770c6fd3754c054ef9ec4721", digest: "d8c22ff912e03740d9bc19e133e581e0",
votes: 0, votes: 0,
}, },
], ],
@ -864,7 +864,7 @@ acceptance("Poll results", function (needs) {
}, },
], ],
tags: [], tags: [],
id: 134, id: 135,
title: "Load more poll voters", title: "Load more poll voters",
fancy_title: "Load more poll voters", fancy_title: "Load more poll voters",
posts_count: 1, posts_count: 1,
@ -890,7 +890,7 @@ acceptance("Poll results", function (needs) {
image_url: null, image_url: null,
slow_mode_seconds: 0, slow_mode_seconds: 0,
draft: null, draft: null,
draft_key: "topic_134", draft_key: "topic_135",
draft_sequence: 7, draft_sequence: 7,
posted: true, posted: true,
unpinned: null, unpinned: null,
@ -898,7 +898,7 @@ acceptance("Poll results", function (needs) {
current_post_number: 1, current_post_number: 1,
highest_post_number: 1, highest_post_number: 1,
last_read_post_number: 1, last_read_post_number: 1,
last_read_post_id: 156, last_read_post_id: 158,
deleted_by: null, deleted_by: null,
has_deleted: false, has_deleted: false,
actions_summary: [ actions_summary: [
@ -1178,6 +1178,78 @@ acceptance("Poll results", function (needs) {
2, 2,
"after clicking fetch voters button, two voters shown on first option" "after clicking fetch voters button, two voters shown on first option"
); );
await publishToMessageBus("/polls/135", {
post_id: "158",
polls: [
{
name: "poll",
type: "ranked_choice",
status: "open",
public: true,
results: "always",
options: [
{
id: "def034c6770c6fd3754c054ef9ec4721",
html: "This",
votes: 3,
},
{
id: "d8c22ff912e03740d9bc19e133e581e0",
html: "That",
votes: 0,
},
],
voters: 3,
preloaded_voters: {
def034c6770c6fd3754c054ef9ec4721: [
{
rank: 1,
user: {
id: 1,
username: "bianca",
name: null,
avatar_template:
"/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
},
},
{
rank: 1,
user: {
id: 7,
username: "foo",
name: null,
avatar_template:
"/letter_avatar_proxy/v4/letter/f/b19c9b/{size}.png",
title: null,
},
},
{
rank: 1,
user: {
id: 11,
username: "bar",
name: null,
avatar_template:
"/letter_avatar_proxy/v4/letter/f/f33bef/{size}.png",
title: null,
},
},
],
},
chart_type: "bar",
title: null,
},
],
});
assert.strictEqual(
count(
".poll-container .discourse-poll-ranked_choice-results .results li:nth-child(1) .poll-voters li"
),
2,
"after incoming message containing 3 voters, only 2 voters shown on first option as bus updates are not supported once voters are expanded"
);
}); });
test("can unvote", async function (assert) { test("can unvote", async function (assert) {