diff --git a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 index c1d8bc29e14..e21ca5e0b5c 100644 --- a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 +++ b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 @@ -81,6 +81,7 @@ createWidget('discourse-poll-voters', { if (state.loaded === 'loading') { return; } const { voterIds } = attrs; + if (!voterIds.length) { return; } const windowSize = Math.round(($('.poll-container:eq(0)').width() / 25) * 2); @@ -137,7 +138,19 @@ createWidget('discourse-poll-standard-results', { if (options) { const voters = poll.get('voters'); - const ordered = options.sort((a, b) => b.votes - a.votes); + const ordered = options.sort((a, b) => { + if (a.votes < b.votes) { + return 1; + } else if (a.votes == b.votes) { + if (a.html < b.html) { + return -1; + } else { + return 1; + } + } else { + return -1; + } + }); const percentages = voters === 0 ? Array(ordered.length).fill(0) : diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 index a4172adcee1..f1668b11791 100644 --- a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 +++ b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 @@ -45,10 +45,11 @@ widgetTest('multiple options in descending order', { this.set('poll', Ember.Object.create({ type: 'multiple', options: [ - { votes: 5 }, - { votes: 2 }, - { votes: 4 }, - { votes: 1 } + { votes: 5, html: 'a' }, + { votes: 2, html: 'b' }, + { votes: 4, html: 'c' }, + { votes: 1, html: 'b' }, + { votes: 1, html: 'a' } ], voters: 12 })); @@ -59,5 +60,8 @@ widgetTest('multiple options in descending order', { assert.equal(this.$('.option .percentage:eq(1)').text(), '33%'); assert.equal(this.$('.option .percentage:eq(2)').text(), '16%'); assert.equal(this.$('.option .percentage:eq(3)').text(), '8%'); + assert.equal(this.$('.option span:nth-child(2):eq(3)').text(), 'a'); + assert.equal(this.$('.option .percentage:eq(4)').text(), '8%'); + assert.equal(this.$('.option span:nth-child(2):eq(4)').text(), 'b'); } });