From 0679e6eb7a62806e2fbb114461f7a418bcfedd11 Mon Sep 17 00:00:00 2001 From: Robert <35533304+merefield@users.noreply.github.com> Date: Mon, 19 Aug 2024 06:55:22 +0100 Subject: [PATCH] FIX: make poll voter list expansion persistent (#28352) * FIX: voter list expansion * naming improvement * extend and refine test --- .../javascripts/discourse/components/poll.gjs | 6 +- .../acceptance/poll-results-test.js | 84 +++++++++++++++++-- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/plugins/poll/assets/javascripts/discourse/components/poll.gjs b/plugins/poll/assets/javascripts/discourse/components/poll.gjs index 76babde0ebd..e055e823e09 100644 --- a/plugins/poll/assets/javascripts/discourse/components/poll.gjs +++ b/plugins/poll/assets/javascripts/discourse/components/poll.gjs @@ -45,6 +45,7 @@ export default class PollComponent extends Component { @tracked vote = this.args.attrs.vote || []; @tracked poll = this.args.attrs.poll; @tracked preloadedVoters = this.defaultPreloadedVoters(); + @tracked voterListExpanded = false; @tracked hasSavedVote = this.args.attrs.hasSavedVote; @tracked @@ -473,7 +474,9 @@ export default class PollComponent extends Component { @action updatedVoters() { - this.preloadedVoters = this.defaultPreloadedVoters(); + if (!this.voterListExpanded) { + this.preloadedVoters = this.defaultPreloadedVoters(); + } } @action @@ -501,6 +504,7 @@ export default class PollComponent extends Component { }, }) .then((result) => { + this.voterListExpanded = true; const voters = optionId ? this.preloadedVoters[optionId].voters : this.preloadedVoters; diff --git a/plugins/poll/test/javascripts/acceptance/poll-results-test.js b/plugins/poll/test/javascripts/acceptance/poll-results-test.js index 4f4829574b9..e5b3bfd2ae6 100644 --- a/plugins/poll/test/javascripts/acceptance/poll-results-test.js +++ b/plugins/poll/test/javascripts/acceptance/poll-results-test.js @@ -551,7 +551,7 @@ acceptance("Poll results", function (needs) { readers_count: 1, score: 0, yours: true, - topic_id: 134, + topic_id: 135, topic_slug: "load-more-poll-voters-ranked-choice", display_username: null, primary_group_name: null, @@ -610,7 +610,7 @@ acceptance("Poll results", function (needs) { votes: 0, }, ], - voters: 1, + voters: 2, preloaded_voters: { def034c6770c6fd3754c054ef9ec4721: [ { @@ -654,7 +654,7 @@ acceptance("Poll results", function (needs) { votes: 2, }, { - digest: "def034c6770c6fd3754c054ef9ec4721", + digest: "d8c22ff912e03740d9bc19e133e581e0", votes: 0, }, ], @@ -864,7 +864,7 @@ acceptance("Poll results", function (needs) { }, ], tags: [], - id: 134, + id: 135, title: "Load more poll voters", fancy_title: "Load more poll voters", posts_count: 1, @@ -890,7 +890,7 @@ acceptance("Poll results", function (needs) { image_url: null, slow_mode_seconds: 0, draft: null, - draft_key: "topic_134", + draft_key: "topic_135", draft_sequence: 7, posted: true, unpinned: null, @@ -898,7 +898,7 @@ acceptance("Poll results", function (needs) { current_post_number: 1, highest_post_number: 1, last_read_post_number: 1, - last_read_post_id: 156, + last_read_post_id: 158, deleted_by: null, has_deleted: false, actions_summary: [ @@ -1178,6 +1178,78 @@ acceptance("Poll results", function (needs) { 2, "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) {