fix: fix polls with content warnings (#1768)

* fix: fix polls with content warnings

fixes #1766

* fixup
This commit is contained in:
Nolan Lawson 2020-05-10 19:41:55 -07:00 committed by GitHub
parent a4820a2792
commit dacd9dcc5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 10 deletions

View file

@ -21,7 +21,7 @@
{#if !showContent}
<StatusMentions {...params} />
{/if}
{#if content && (showContent || contentPreloaded)}
{#if content && (showContent || preloadHiddenContent)}
<StatusContent {...params} shown={showContent}/>
{/if}
{#if showCard }
@ -30,8 +30,8 @@
{#if showMedia }
<StatusMediaAttachments {...params} on:recalculateHeight />
{/if}
{#if showPoll}
<StatusPoll {...params} />
{#if showPoll && (showContent || preloadHiddenContent)}
<StatusPoll {...params} shown={showContent} />
{/if}
{#if isStatusInOwnThread}
<StatusDetails {...params} {...timestampParams} />
@ -147,7 +147,7 @@
scheduleIdleTask(() => {
// Perf optimization: lazily load the StatusContent when the user is idle so that
// it's fast when they click the "show more" button
this.set({ contentPreloaded: true })
this.set({ preloadHiddenContent: true })
})
}
},
@ -171,7 +171,7 @@
data: () => ({
notification: undefined,
replyVisibility: undefined,
contentPreloaded: false,
preloadHiddenContent: false,
enableShortcuts: null
}),
store: () => store,

View file

@ -65,6 +65,11 @@
border: 1px solid var(--main-border);
border-radius: 2px;
transition: opacity 0.2s linear;
display: none;
}
.poll.shown {
display: block;
}
.poll.status-in-own-thread {
@ -309,12 +314,13 @@
),
formDisabled: ({ choices }) => !choices.length,
votesText: ({ votesCount }) => `${votesCount} ${votesCount === 1 ? 'vote' : 'votes'}`,
computedClass: ({ isStatusInNotification, isStatusInOwnThread, loading }) => (
computedClass: ({ isStatusInNotification, isStatusInOwnThread, loading, shown }) => (
classname(
'poll',
isStatusInNotification && 'status-in-notification',
isStatusInOwnThread && 'status-in-own-thread',
loading && 'poll-loading'
loading && 'poll-loading',
shown && 'shown'
)
)
},

View file

@ -71,8 +71,8 @@ export async function updateUserDisplayNameAs (username, displayName) {
return updateCredentials(instanceName, users[username].accessToken, { display_name: displayName })
}
export async function createPollAs (username, content, options, multiple) {
return postStatus(instanceName, users[username].accessToken, content, null, null, false, null, 'public', {
export async function createPollAs (username, content, options, multiple, spoilerText) {
return postStatus(instanceName, users[username].accessToken, content, null, null, false, spoilerText, 'public', {
options,
multiple,
expires_in: POLL_EXPIRY_DEFAULT

View file

@ -7,7 +7,7 @@ import {
sleep,
getNthStatusPollRefreshButton,
getNthStatusPollVoteCount,
getNthStatusRelativeDate, getUrl, goBack
getNthStatusRelativeDate, getUrl, goBack, getNthStatusSpoiler, getNthShowOrHideButton
} from '../utils'
import { loginAsFoobar } from '../roles'
import { createPollAs, voteOnPollAs } from '../serverActions'
@ -105,3 +105,19 @@ test('Poll results refresh everywhere', async t => {
.expect(getNthStatusPollResult(1, 2).innerText).eql('0% no')
.expect(getNthStatusPollVoteCount(1).innerText).eql('1 vote')
})
test('Polls with content warnings', async t => {
await createPollAs('admin', 'hidden poll!', ['oui', 'non'], false, 'this poll is hidden')
await sleep(2000)
await loginAsFoobar(t)
await t
.expect(getNthStatusSpoiler(1).innerText).contains('this poll is hidden')
.expect(getNthStatusPollForm(1).visible).notOk()
.expect(getNthStatusContent(1).visible).notOk()
.click(getNthShowOrHideButton(1))
.expect(getNthStatusPollForm(1).visible).ok()
.expect(getNthStatusContent(1).visible).ok()
.click(getNthShowOrHideButton(1))
.expect(getNthStatusPollForm(1).visible).notOk()
.expect(getNthStatusContent(1).visible).notOk()
})