fix: fix multiple-choice poll results (#2101)

Fixes #2100
This commit is contained in:
Nolan Lawson 2022-01-02 16:00:41 -08:00 committed by GitHub
parent 67f4a1ab2f
commit 331f6e8803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 9 deletions

View File

@ -292,13 +292,13 @@
computed: { computed: {
pollId: ({ originalStatus }) => originalStatus.poll.id, pollId: ({ originalStatus }) => originalStatus.poll.id,
poll: ({ originalStatus, $polls, pollId }) => $polls[pollId] || originalStatus.poll, poll: ({ originalStatus, $polls, pollId }) => $polls[pollId] || originalStatus.poll,
options: ({ poll, originalStatusEmojis, $autoplayGifs }) => ( options: ({ poll, originalStatusEmojis, $autoplayGifs, votersCount }) => (
poll.options.map(({ title, votes_count: votesCount }) => ({ poll.options.map(({ title, votes_count: optionsVotesCount }) => ({
title: emojifyText(escapeHtml(title), originalStatusEmojis, $autoplayGifs), title: emojifyText(escapeHtml(title), originalStatusEmojis, $autoplayGifs),
share: poll.votes_count ? Math.round(votesCount / poll.votes_count * 100) : 0 share: votersCount ? Math.round(optionsVotesCount / votersCount * 100) : 0
})) }))
), ),
votesCount: ({ poll }) => poll.votes_count, votersCount: ({ poll }) => poll.voters_count,
voted: ({ poll }) => poll.voted, voted: ({ poll }) => poll.voted,
multiple: ({ poll }) => poll.multiple, multiple: ({ poll }) => poll.multiple,
expired: ({ poll }) => poll.expired, expired: ({ poll }) => poll.expired,
@ -314,8 +314,8 @@
!isStatusInOwnThread && $isMobileSize && !expired !isStatusInOwnThread && $isMobileSize && !expired
), ),
formDisabled: ({ choices }) => !choices.length, formDisabled: ({ choices }) => !choices.length,
votesText: ({ votesCount }) => ( votesText: ({ votersCount }) => (
formatIntl('intl.voteCount', { count: votesCount }) formatIntl('intl.voteCount', { count: votersCount })
), ),
computedClass: ({ isStatusInNotification, isStatusInOwnThread, loading, shown }) => ( computedClass: ({ isStatusInNotification, isStatusInOwnThread, loading, shown }) => (
classname( classname(

View File

@ -50,10 +50,10 @@ test('Can vote on multiple-choice polls', async t => {
await t await t
.click(getNthStatusPollVoteButton(1)) .click(getNthStatusPollVoteButton(1))
.expect(getNthStatusPollForm(1).exists).notOk({ timeout: 20000 }) .expect(getNthStatusPollForm(1).exists).notOk({ timeout: 20000 })
.expect(getNthStatusPollResult(1, 1).innerText).eql('50% yes') .expect(getNthStatusPollResult(1, 1).innerText).eql('100% yes')
.expect(getNthStatusPollResult(1, 2).innerText).eql('0% no') .expect(getNthStatusPollResult(1, 2).innerText).eql('0% no')
.expect(getNthStatusPollResult(1, 3).innerText).eql('50% maybe') .expect(getNthStatusPollResult(1, 3).innerText).eql('100% maybe')
.expect(getNthStatusPollVoteCount(1).innerText).eql('2 votes') .expect(getNthStatusPollVoteCount(1).innerText).eql('1 vote')
}) })
test('Can update poll results', async t => { test('Can update poll results', async t => {
@ -121,3 +121,32 @@ test('Polls with content warnings', async t => {
.expect(getNthStatusPollForm(1).visible).notOk() .expect(getNthStatusPollForm(1).visible).notOk()
.expect(getNthStatusContent(1).visible).notOk() .expect(getNthStatusContent(1).visible).notOk()
}) })
test('Percent total can exceed 100% on multi-choice polls', async t => {
const { poll } = await createPollAs('admin', 'please vote a whole lot', ['yes', 'no', 'maybe', 'huh'], true)
const { id: pollId } = poll
await voteOnPollAs('baz', pollId, [0, 1, 2])
await voteOnPollAs('ExternalLinks', pollId, [0, 1, 2, 3])
await sleep(2000)
await loginAsFoobar(t)
await t
.expect(getNthStatusContent(1).innerText).contains('please vote a whole lot')
await sleep(1000)
await t
.click(getNthStatusPollOption(1, 1))
await sleep(1000)
await t
.click(getNthStatusPollOption(1, 2))
await sleep(1000)
await t
.click(getNthStatusPollOption(1, 3))
await sleep(1000)
await t
.click(getNthStatusPollVoteButton(1))
.expect(getNthStatusPollForm(1).exists).notOk({ timeout: 20000 })
.expect(getNthStatusPollResult(1, 1).innerText).eql('100% yes')
.expect(getNthStatusPollResult(1, 2).innerText).eql('100% no')
.expect(getNthStatusPollResult(1, 3).innerText).eql('100% maybe')
.expect(getNthStatusPollResult(1, 4).innerText).eql('33% huh')
.expect(getNthStatusPollVoteCount(1).innerText).eql('3 votes')
})