FIX: Disable Show results if nobody voted (#14528)

FIX: Disable Show results if nobody voted (#14528)

diff --git a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
index a68560d..6b476de 100644
--- a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
+++ b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
@@ -651,6 +651,7 @@ createWidget("discourse-poll-buttons", {
           label: "poll.show-results.label",
           title: "poll.show-results.title",
           icon: "far-eye",
+          disabled: poll.voters === 0,
           action: "toggleResults",
         });
       }
diff --git a/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6
index 185bfc8..ef547c8 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6
@@ -2,6 +2,7 @@ import {
   acceptance,
   count,
   publishToMessageBus,
+  query,
 } from "discourse/tests/helpers/qunit-helpers";
 import { test } from "qunit";
 import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
@@ -660,3 +661,514 @@ acceptance("Poll results", function (needs) {
     assert.equal(count(".poll-container .d-icon-far-circle"), 2);
   });
 });
+
+acceptance("Poll results - no voters", function (needs) {
+  needs.user();
+  needs.settings({ poll_enabled: true });
+  needs.hooks.beforeEach(() => {
+    clearPopupMenuOptionsCallback();
+  });
+
+  needs.pretender((server, helper) => {
+    server.get("/posts/by_number/134/1", () => {
+      return helper.response({
+        id: 156,
+        name: null,
+        username: "bianca",
+        avatar_template: "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
+        created_at: "2021-06-08T21:56:55.166Z",
+        cooked:
+          '\u003cdiv class="poll" data-poll-status="open" data-poll-public="true" data-poll-results="always" data-poll-charttype="bar" data-poll-type="regular" data-poll-name="poll"\u003e\n\u003cdiv\u003e\n\u003cdiv class="poll-container"\u003e\n\u003cul\u003e\n\u003cli data-poll-option-id="db753fe0bc4e72869ac1ad8765341764"\u003eOption \u003cspan class="hashtag"\u003e#1\u003c/span\u003e\n\u003c/li\u003e\n\u003cli data-poll-option-id="d8c22ff912e03740d9bc19e133e581e0"\u003eOption \u003cspan class="hashtag"\u003e#2\u003c/span\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cdiv class="poll-info"\u003e\n\u003cp\u003e\n\u003cspan class="info-number"\u003e0\u003c/span\u003e\n\u003cspan class="info-label"\u003evoters\u003c/span\u003e\n\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e',
+        post_number: 1,
+        post_type: 1,
+        updated_at: "2021-06-08T21:59:16.444Z",
+        reply_count: 0,
+        reply_to_post_number: null,
+        quote_count: 0,
+        incoming_link_count: 0,
+        reads: 2,
+        readers_count: 1,
+        score: 0,
+        yours: true,
+        topic_id: 134,
+        topic_slug: "load-more-poll-voters",
+        display_username: null,
+        primary_group_name: null,
+        flair_url: null,
+        flair_bg_color: null,
+        flair_color: null,
+        version: 1,
+        can_edit: true,
+        can_delete: false,
+        can_recover: false,
+        can_wiki: true,
+        title_is_group: false,
+        bookmarked: false,
+        bookmarks: [],
+        raw:
+          "[poll type=regular results=always public=true chartType=bar]\n* Option #1\n* Option #2\n[/poll]",
+        actions_summary: [
+          { id: 3, can_act: true },
+          { id: 4, can_act: true },
+          { id: 8, can_act: true },
+          { id: 7, can_act: true },
+        ],
+        moderator: false,
+        admin: true,
+        staff: true,
+        user_id: 1,
+        hidden: false,
+        trust_level: 0,
+        deleted_at: null,
+        user_deleted: false,
+        edit_reason: null,
+        can_view_edit_history: true,
+        wiki: false,
+        reviewable_id: null,
+        reviewable_score_count: 0,
+        reviewable_score_pending_count: 0,
+        calendar_details: [],
+        can_accept_answer: false,
+        can_unaccept_answer: false,
+        accepted_answer: false,
+        polls: [
+          {
+            name: "poll",
+            type: "regular",
+            status: "open",
+            public: true,
+            results: "always",
+            options: [
+              {
+                id: "db753fe0bc4e72869ac1ad8765341764",
+                html:
+                  'Option \u003cspan class="hashtag"\u003e#1\u003c/span\u003e',
+                votes: 0,
+              },
+              {
+                id: "d8c22ff912e03740d9bc19e133e581e0",
+                html:
+                  'Option \u003cspan class="hashtag"\u003e#2\u003c/span\u003e',
+                votes: 0,
+              },
+            ],
+            voters: 0,
+            preloaded_voters: {},
+            chart_type: "bar",
+            title: null,
+          },
+        ],
+      });
+    });
+
+    server.get("/t/load-more-poll-voters.json", () => {
+      return helper.response({
+        post_stream: {
+          posts: [
+            {
+              id: 156,
+              name: null,
+              username: "bianca",
+              avatar_template:
+                "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
+              created_at: "2021-06-08T21:56:55.166Z",
+              cooked:
+                '\u003cdiv class="poll" data-poll-status="open" data-poll-public="true" data-poll-results="always" data-poll-charttype="bar" data-poll-type="regular" data-poll-name="poll"\u003e\n\u003cdiv\u003e\n\u003cdiv class="poll-container"\u003e\n\u003cul\u003e\n\u003cli data-poll-option-id="db753fe0bc4e72869ac1ad8765341764"\u003eOption \u003cspan class="hashtag"\u003e#1\u003c/span\u003e\n\u003c/li\u003e\n\u003cli data-poll-option-id="d8c22ff912e03740d9bc19e133e581e0"\u003eOption \u003cspan class="hashtag"\u003e#2\u003c/span\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cdiv class="poll-info"\u003e\n\u003cp\u003e\n\u003cspan class="info-number"\u003e0\u003c/span\u003e\n\u003cspan class="info-label"\u003evoters\u003c/span\u003e\n\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e',
+              post_number: 1,
+              post_type: 1,
+              updated_at: "2021-06-08T21:59:16.444Z",
+              reply_count: 0,
+              reply_to_post_number: null,
+              quote_count: 0,
+              incoming_link_count: 0,
+              reads: 2,
+              readers_count: 1,
+              score: 0,
+              yours: true,
+              topic_id: 134,
+              topic_slug: "load-more-poll-voters",
+              display_username: null,
+              primary_group_name: null,
+              flair_url: null,
+              flair_bg_color: null,
+              flair_color: null,
+              version: 1,
+              can_edit: true,
+              can_delete: false,
+              can_recover: false,
+              can_wiki: true,
+              read: true,
+              title_is_group: false,
+              bookmarked: false,
+              bookmarks: [],
+              actions_summary: [
+                { id: 3, can_act: true },
+                { id: 4, can_act: true },
+                { id: 8, can_act: true },
+                { id: 7, can_act: true },
+              ],
+              moderator: false,
+              admin: true,
+              staff: true,
+              user_id: 1,
+              hidden: false,
+              trust_level: 0,
+              deleted_at: null,
+              user_deleted: false,
+              edit_reason: null,
+              can_view_edit_history: true,
+              wiki: false,
+              reviewable_id: 0,
+              reviewable_score_count: 0,
+              reviewable_score_pending_count: 0,
+              calendar_details: [],

[... diff too long, it was truncated ...]

GitHub sha: 98d2836eb47b9f56ff22a57acf2e5247854c7363

This commit appears in #14528 which was approved by pmusaraj. It was merged by nbianca.