From 380d2a0d451cd6d74483a44fb5ef5f4a263c728b Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 3 Dec 2022 18:53:20 -0800 Subject: [PATCH] fix: fix poll "ends at" time (#2292) Fixes #2286 --- src/routes/_components/status/StatusPoll.html | 5 ++++- tests/spec/126-polls.js | 4 +++- tests/utils.js | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/routes/_components/status/StatusPoll.html b/src/routes/_components/status/StatusPoll.html index c89f68c9..0f8388b5 100644 --- a/src/routes/_components/status/StatusPoll.html +++ b/src/routes/_components/status/StatusPoll.html @@ -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) ), diff --git a/tests/spec/126-polls.js b/tests/spec/126-polls.js index 8f99dfdd..2b48a4ee 100644 --- a/tests/spec/126-polls.js +++ b/tests/spec/126-polls.js @@ -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 => { diff --git a/tests/utils.js b/tests/utils.js index de014857..c6a31a26 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -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})`) }