From 95a68e1fe21ab4b70eaca2981cf3d17136e9deea Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 19 Jul 2019 20:08:17 -0700 Subject: [PATCH] fix: delete-and-redraft preserves polls (#1343) * fix: delete-and-redraft preserves polls fixes #1342 * fix test --- src/routes/_actions/deleteAndRedraft.js | 7 +++- tests/spec/121-delete-and-redraft.js | 49 ++++++++++++++++++++++++- tests/utils.js | 7 ++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/routes/_actions/deleteAndRedraft.js b/src/routes/_actions/deleteAndRedraft.js index 68ae9b46..3cca19f1 100644 --- a/src/routes/_actions/deleteAndRedraft.js +++ b/src/routes/_actions/deleteAndRedraft.js @@ -17,7 +17,12 @@ export async function deleteAndRedraft (status) { description: _.description || '', data: _ })), - inReplyToId: status.in_reply_to_id + inReplyToId: status.in_reply_to_id, + // note that for polls there is no real way to preserve the original expiry + poll: status.poll && { + multiple: !!status.poll.multiple, + options: (status.poll.options || []).map(option => option.title) + } }) let showComposeDialog = await dialogPromise showComposeDialog() diff --git a/tests/spec/121-delete-and-redraft.js b/tests/spec/121-delete-and-redraft.js index 1744258b..1bb8db4f 100644 --- a/tests/spec/121-delete-and-redraft.js +++ b/tests/spec/121-delete-and-redraft.js @@ -12,9 +12,27 @@ import { getNthStatusSpoiler, composeModalContentWarningInput, dialogOptionsOption, - getNthReplyButton, getNthComposeReplyInput, getNthComposeReplyButton, getUrl, sleep, getComposeModalNthMediaListItem + getNthReplyButton, + getNthComposeReplyInput, + getNthComposeReplyButton, + getUrl, + sleep, + getComposeModalNthMediaListItem, + composePoll, + pollButton, + getComposePollNthInput, + composeButton, + getNthStatusPollResult, + getComposePollNthInputInDialog, + composeInput, + composePollMultipleChoice, + composePollMultipleChoiceInDialog, + composePollExpiry, + composePollExpiryOption, + composePollExpiryInDialog } from '../utils' import { postAs, postEmptyStatusWithMediaAs, postWithSpoilerAndPrivacyAs } from '../serverActions' +import { POLL_EXPIRY_DEFAULT } from '../../src/routes/_static/polls' fixture`121-delete-and-redraft.js` .page`http://localhost:4002` @@ -172,3 +190,32 @@ test('multiple paragraphs', async t => { .expect(modalDialog.exists).notOk() .expect(getNthStatusContent(1).innerText).contains(text + '\n\nwoot') }) + +test('delete and redraft polls', async t => { + await loginAsFoobar(t) + await t + .click(pollButton) + .expect(composePoll.exists).ok() + .typeText(composeInput, 'I love this poll', { paste: true }) + .typeText(getComposePollNthInput(1), 'foo', { paste: true }) + .typeText(getComposePollNthInput(2), 'bar', { paste: true }) + .click(composePollExpiry) + .click(composePollExpiryOption.withText('6 hours')) + .click(composePollMultipleChoice) + await sleep(1000) + await t + .click(composeButton) + .expect(getNthStatusContent(1).innerText).contains('I love this poll') + .expect(getNthStatusPollResult(1, 1).innerText).eql('0% foo') + .expect(getNthStatusPollResult(1, 2).innerText).eql('0% bar') + await sleep(1000) + await t + .click(getNthStatusOptionsButton(1)) + .click(dialogOptionsOption.withText('Delete and redraft')) + .expect(composeModalInput.value).eql('I love this poll') + .expect(getComposePollNthInputInDialog(1).value).eql('foo') + .expect(getComposePollNthInputInDialog(2).value).eql('bar') + // there is no way to preserve poll expiry unfortunately + .expect(composePollExpiryInDialog.value).eql(POLL_EXPIRY_DEFAULT.toString()) + .expect(composePollMultipleChoiceInDialog.checked).eql(true) +}) diff --git a/tests/utils.js b/tests/utils.js index 40c19473..9cca6ac0 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -65,7 +65,10 @@ export const composeModalPostPrivacyButton = $('.modal-dialog .compose-box-toolb export const composePoll = $('.compose-poll') export const composePollMultipleChoice = $('.compose-poll input[type="checkbox"]') +export const composePollMultipleChoiceInDialog = $('.modal-dialog .compose-poll input[type="checkbox"]') export const composePollExpiry = $('.compose-poll select') +export const composePollExpiryOption = $('.compose-poll select option') +export const composePollExpiryInDialog = $('.modal-dialog .compose-poll select') export const composePollAddButton = $('.compose-poll button:last-of-type') export const postPrivacyDialogButtonUnlisted = $('[aria-label="Post privacy dialog"] li:nth-child(2) button') @@ -265,6 +268,10 @@ export function getComposePollNthInput (n) { return $(`.compose-poll input[type="text"]:nth-of-type(${n})`) } +export function getComposePollNthInputInDialog (n) { + return $(`.modal-dialog .compose-poll input[type="text"]:nth-of-type(${n})`) +} + export function getComposePollRemoveNthButton (n) { return $(`.compose-poll button:nth-of-type(${n})`) }