From 3e303a444db203735f4545b152abfa93d03578d3 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 17 Sep 2019 00:19:59 -0700 Subject: [PATCH] fix: removing media should reset sensitive status (#1497) fixes #1495 --- src/routes/_actions/media.js | 7 +++++++ tests/spec/013-compose-media.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/routes/_actions/media.js b/src/routes/_actions/media.js index d71f43fa..b9a0ff20 100644 --- a/src/routes/_actions/media.js +++ b/src/routes/_actions/media.js @@ -38,5 +38,12 @@ export function deleteMedia (realm, i) { store.setComposeData(realm, { media: composeMedia }) + if (!composeMedia.length) { + const contentWarningShown = store.getComposeData(realm, 'contentWarningShown') + const contentWarning = store.getComposeData(realm, 'contentWarning') + store.setComposeData(realm, { + sensitive: contentWarningShown && contentWarning // reset sensitive if the last media is deleted + }) + } scheduleIdleTask(() => store.save()) } diff --git a/tests/spec/013-compose-media.js b/tests/spec/013-compose-media.js index abae22f8..d6b4a22e 100644 --- a/tests/spec/013-compose-media.js +++ b/tests/spec/013-compose-media.js @@ -1,5 +1,6 @@ import { - composeInput, + composeContentWarning, + composeInput, composeMediaSensitiveCheckbox, contentWarningButton, getNthDeleteMediaButton, getNthMedia, getNthMediaAltInput, @@ -126,3 +127,32 @@ test('keeps media in local storage', async t => { .expect(getNthMediaListItem(1).getAttribute('aria-label')).eql('kitten1.jpg') .expect(getNthMediaListItem(2).getAttribute('aria-label')).eql('kitten2.jpg') }) + +test('resets sensitive settings when deleting media', async t => { + await loginAsFoobar(t) + await t + .expect(mediaButton.exists).ok() + await (uploadKittenImage(1)()) + await t + .click(composeMediaSensitiveCheckbox) + .expect(composeMediaSensitiveCheckbox.checked).ok() + await (uploadKittenImage(2)()) + await t + .expect(composeMediaSensitiveCheckbox.checked).ok() + .click(getNthDeleteMediaButton(2)) + .expect(getNthMedia(2).exists).notOk() + .expect(composeMediaSensitiveCheckbox.checked).ok() + .click(getNthDeleteMediaButton(1)) + .expect(getNthMedia(1).exists).notOk() + await (uploadKittenImage(1)()) + await t + .expect(composeMediaSensitiveCheckbox.checked).notOk() + .click(contentWarningButton) + .typeText(composeContentWarning, 'warn warn warn', { paste: true }) + .expect(composeMediaSensitiveCheckbox.checked).ok() + .click(getNthDeleteMediaButton(1)) + .expect(getNthMedia(1).exists).notOk() + await (uploadKittenImage(1)()) + await t + .expect(composeMediaSensitiveCheckbox.checked).ok() +})