From 84148912ee9df0807e9ef6569228f1e39f1dc470 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 11 Apr 2018 22:55:11 -0700 Subject: [PATCH] Fix spoilers being posted after removal (#90) Fixes #83 --- routes/_actions/contentWarnings.js | 5 ++-- tests/spec/110-compose-content-warnings.js | 33 ++++++++++++++++++++++ tests/utils.js | 4 +++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/spec/110-compose-content-warnings.js diff --git a/routes/_actions/contentWarnings.js b/routes/_actions/contentWarnings.js index b9e535b..43aef34 100644 --- a/routes/_actions/contentWarnings.js +++ b/routes/_actions/contentWarnings.js @@ -3,8 +3,9 @@ import { store } from '../_store/store' export function toggleContentWarningShown (realm) { let shown = store.getComposeData(realm, 'contentWarningShown') let contentWarning = store.getComposeData(realm, 'contentWarning') + let newShown = !shown store.setComposeData(realm, { - contentWarning: shown ? contentWarning : '', - contentWarningShown: !shown + contentWarning: newShown ? contentWarning : '', + contentWarningShown: newShown }) } diff --git a/tests/spec/110-compose-content-warnings.js b/tests/spec/110-compose-content-warnings.js new file mode 100644 index 0000000..0260c5b --- /dev/null +++ b/tests/spec/110-compose-content-warnings.js @@ -0,0 +1,33 @@ +import { + composeButton, composeContentWarning, composeInput, contentWarningButton, + getNthShowOrHideButton, getNthStatus +} from '../utils' +import { foobarRole } from '../roles' + +fixture`110-compose-content-warnings.js` + .page`http://localhost:4002` + +test('content warnings are posted', async t => { + await t.useRole(foobarRole) + .typeText(composeInput, 'hello this is a toot', {paste: true}) + .click(contentWarningButton) + .typeText(composeContentWarning, 'CW', {paste: true}) + .click(composeButton) + .expect(getNthStatus(0).find('.status-spoiler').innerText).contains('CW', {timeout: 30000}) + .click(getNthShowOrHideButton(0)) + .expect(getNthStatus(0).find('.status-content').innerText).contains('hello this is a toot') + .click(getNthShowOrHideButton(0)) + .expect(getNthStatus(0).find('.status-content').exists).notOk() +}) + +test('content warnings are not posted if removed', async t => { + await t.useRole(foobarRole) + .typeText(composeInput, 'hi this is another toot', {paste: true}) + .click(contentWarningButton) + .typeText(composeContentWarning, 'content warning!', {paste: true}) + .click(contentWarningButton) + .expect(composeContentWarning.exists).notOk() + .click(composeButton) + .expect(getNthStatus(0).find('.status-spoiler').exists).notOk({timeout: 30000}) + .expect(getNthStatus(0).find('.status-content').innerText).contains('hi this is another toot') +}) diff --git a/tests/utils.js b/tests/utils.js index af13310..4c5bf82 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -173,6 +173,10 @@ export function getNthFavorited (n) { return getNthFavoriteButton(n).getAttribute('aria-pressed') } +export function getNthShowOrHideButton (n) { + return getNthStatus(n).find('.status-spoiler-button button') +} + export function getFavoritesCount () { return favoritesCountElement.innerCount }