From ee8cda5d66432596d1f6b14536393e81012a8e4a Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 8 Apr 2018 13:42:31 -0700 Subject: [PATCH] fix modifying replies to statuses --- routes/_actions/compose.js | 16 +++++--- tests/spec/014-compose-post-privacy.js | 6 +-- tests/spec/017-compose-reply.js | 54 +++++++++++++++++++++++++- tests/utils.js | 16 ++++++++ 4 files changed, 81 insertions(+), 11 deletions(-) diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index a9522bd..1ab6bea 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -70,13 +70,13 @@ export async function clickSelectedAutosuggestionUsername (realm) { export function setReplySpoiler (realm, spoiler) { let contentWarning = store.getComposeData(realm, 'contentWarning') let contentWarningShown = store.getComposeData(realm, 'contentWarningShown') - if (typeof contentWarningShown === 'undefined' && !contentWarning) { - // user hasn't interacted with the CW yet - store.setComposeData(realm, { - contentWarning: spoiler, - contentWarningShown: true - }) + if (typeof contentWarningShown !== 'undefined' || contentWarning) { + return // user has already interacted with the CW } + store.setComposeData(realm, { + contentWarning: spoiler, + contentWarningShown: true + }) } const PRIVACY_LEVEL = { @@ -89,6 +89,10 @@ const PRIVACY_LEVEL = { export function setReplyVisibility (realm, replyVisibility) { // return the most private between the user's preferred default privacy // and the privacy of the status they're replying to + let postPrivacy = store.getComposeData(realm, 'postPrivacy') + if (typeof postPrivacy !== 'undefined') { + return // user has already set the postPrivacy + } let verifyCredentials = store.get('currentVerifyCredentials') let defaultVisibility = verifyCredentials.source.privacy let visibility = PRIVACY_LEVEL[replyVisibility] < PRIVACY_LEVEL[defaultVisibility] diff --git a/tests/spec/014-compose-post-privacy.js b/tests/spec/014-compose-post-privacy.js index fa3a84d..f02222d 100644 --- a/tests/spec/014-compose-post-privacy.js +++ b/tests/spec/014-compose-post-privacy.js @@ -1,4 +1,4 @@ -import { postPrivacyButton } from '../utils' +import { getNthPostPrivacyOptionInDialog, postPrivacyButton } from '../utils' import { foobarRole } from '../roles' fixture`014-compose-post-privacy.js` @@ -8,9 +8,9 @@ test('Changes post privacy', async t => { await t.useRole(foobarRole) .expect(postPrivacyButton.getAttribute('aria-label')).eql('Adjust privacy (currently Public)') .click(postPrivacyButton) - .click('.generic-dialog-list li:nth-child(2) button') + .click(getNthPostPrivacyOptionInDialog(2)) .expect(postPrivacyButton.getAttribute('aria-label')).eql('Adjust privacy (currently Unlisted)') .click(postPrivacyButton) - .click('.generic-dialog-list li:nth-child(1) button') + .click(getNthPostPrivacyOptionInDialog(1)) .expect(postPrivacyButton.getAttribute('aria-label')).eql('Adjust privacy (currently Public)') }) diff --git a/tests/spec/017-compose-reply.js b/tests/spec/017-compose-reply.js index c842da7..91fc799 100644 --- a/tests/spec/017-compose-reply.js +++ b/tests/spec/017-compose-reply.js @@ -1,7 +1,9 @@ import { composeInput, - getNthComposeReplyInput, getNthPostPrivacyButton, getNthReplyButton, - getNthStatus, getUrl, homeNavButton, notificationsNavButton + getNthComposeReplyInput, getNthPostPrivacyButton, getNthPostPrivacyOptionInDialog, getNthReplyButton, + getNthReplyContentWarningButton, + getNthReplyContentWarningInput, getNthReplyPostPrivacyButton, + getNthStatus, getUrl, homeNavButton, notificationsNavButton, scrollToStatus } from '../utils' import { foobarRole } from '../roles' @@ -58,3 +60,51 @@ test('replies have same privacy as replied-to status by default', async t => { .expect(getNthPostPrivacyButton(7).getAttribute('aria-label')).eql('Adjust privacy (currently Public)') .click(getNthReplyButton(7)) }) + +test('replies have same CW as replied-to status', async t => { + await t.useRole(foobarRole) + await scrollToStatus(t, 7) + await t.click(getNthReplyButton(7)) + .expect(getNthReplyContentWarningInput(7).value).eql('kitten CW') + .click(getNthStatus(7)) + .click(getNthReplyButton(0)) + .expect(getNthReplyContentWarningInput(0).value).eql('kitten CW') +}) + +test('replies save deletions of CW', async t => { + await t.useRole(foobarRole) + await scrollToStatus(t, 7) + await t.click(getNthReplyButton(7)) + .expect(getNthReplyContentWarningInput(7).value).eql('kitten CW') + .click(getNthReplyContentWarningButton(7)) + .expect(getNthReplyContentWarningInput(7).exists).notOk() + .click(getNthStatus(7)) + .click(getNthReplyButton(0)) + .expect(getNthReplyContentWarningInput(0).exists).notOk() +}) + +test('replies save changes to CW', async t => { + await t.useRole(foobarRole) + await scrollToStatus(t, 7) + await t.click(getNthReplyButton(7)) + .expect(getNthReplyContentWarningInput(7).value).eql('kitten CW') + .typeText(getNthReplyContentWarningInput(7), ' yolo', {paste: true}) + .expect(getNthReplyContentWarningInput(7).value).eql('kitten CW yolo') + .click(getNthStatus(7)) + .click(getNthReplyButton(0)) + .expect(getNthReplyContentWarningInput(0).value).eql('kitten CW yolo') +}) + +test('replies save changes to post privacy', async t => { + await t.useRole(foobarRole) + .hover(getNthStatus(0)) + .hover(getNthStatus(1)) + .click(getNthReplyButton(1)) + .expect(getNthPostPrivacyButton(1).getAttribute('aria-label')).eql('Adjust privacy (currently Unlisted)') + .click(getNthReplyPostPrivacyButton(1)) + .click(getNthPostPrivacyOptionInDialog(1)) + .expect(getNthPostPrivacyButton(1).getAttribute('aria-label')).eql('Adjust privacy (currently Public)') + .click(getNthStatus(1)) + .click(getNthReplyButton(0)) + .expect(getNthPostPrivacyButton(0).getAttribute('aria-label')).eql('Adjust privacy (currently Unlisted)') +}) diff --git a/tests/utils.js b/tests/utils.js index d11bc87..25f3fb6 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -140,6 +140,22 @@ export function getNthReplyButton (n) { return getNthStatus(n).find('.status-toolbar button:nth-child(1)') } +export function getNthReplyContentWarningInput (n) { + return getNthStatus(n).find('.content-warning-input') +} + +export function getNthReplyContentWarningButton (n) { + return getNthStatus(n).find('.compose-box-toolbar button:nth-child(4)') +} + +export function getNthReplyPostPrivacyButton (n) { + return getNthStatus(n).find('.compose-box-toolbar button:nth-child(3)') +} + +export function getNthPostPrivacyOptionInDialog (n) { + return $(`.generic-dialog-list li:nth-child(${n}) button`) +} + export function getNthFavoriteButton (n) { return getNthStatus(n).find('.status-toolbar button:nth-child(3)') }