fix: fix poll "ends at" time (#2292)

Fixes #2286
This commit is contained in:
Nolan Lawson 2022-12-03 18:53:20 -08:00 committed by GitHub
parent 7fdbd72f13
commit 380d2a0d45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -307,7 +307,10 @@
expired: ({ poll }) => poll.expired,
expiresAt: ({ poll }) => poll.expires_at,
// Misskey can have polls that never end. These give expiresAt as null
expiresAtTS: ({ expiresAt }) => typeof expiresAt === 'number' ? new Date(expiresAt).getTime() : null,
// Also, Mastodon v4+ uses ISO strings, whereas Mastodon pre-v4 used numbers
expiresAtTS: ({ expiresAt }) => (
(typeof expiresAt === 'number' || typeof expiresAt === 'string') ? new Date(expiresAt).getTime() : null
),
expiresAtTimeagoFormatted: ({ expiresAtTS, expired, $now }) => (
expired ? formatTimeagoDate(expiresAtTS, $now) : formatTimeagoFutureDate(expiresAtTS, $now)
),

View File

@ -7,7 +7,7 @@ import {
sleep,
getNthStatusPollRefreshButton,
getNthStatusPollVoteCount,
getNthStatusRelativeDate, getUrl, goBack, getNthStatusSpoiler, getNthShowOrHideButton
getNthStatusRelativeDate, getUrl, goBack, getNthStatusSpoiler, getNthShowOrHideButton, getNthStatusPollExpiry
} from '../utils'
import { loginAsFoobar } from '../roles'
import { createPollAs, voteOnPollAs } from '../serverActions'
@ -22,6 +22,7 @@ test('Can vote on polls', async t => {
await t
.expect(getNthStatusContent(1).innerText).contains('vote on my cool poll')
.expect(getNthStatusPollVoteCount(1).innerText).eql('0 votes')
.expect(getNthStatusPollExpiry(1).innerText).match(/Ends in .*/)
await sleep(1000)
await t
.click(getNthStatusPollOption(1, 2))
@ -32,6 +33,7 @@ test('Can vote on polls', async t => {
.expect(getNthStatusPollResult(1, 1).innerText).eql('0% yes')
.expect(getNthStatusPollResult(1, 2).innerText).eql('100% no')
.expect(getNthStatusPollVoteCount(1).innerText).eql('1 vote')
.expect(getNthStatusPollExpiry(1).innerText).match(/Ends in .*/)
})
test('Can vote on multiple-choice polls', async t => {

View File

@ -394,6 +394,10 @@ export function getNthStatusPollVoteCount (n) {
return $(`${getNthStatusSelector(n)} .poll .poll-stat:nth-child(1) .poll-stat-text`)
}
export function getNthStatusPollExpiry (n) {
return $(`${getNthStatusSelector(n)} .poll .poll-stat-expiry`)
}
export function getComposePollNthInput (n) {
return $(`.compose-poll input[type="text"]:nth-of-type(${n})`)
}