From f01a8b5b8fbcfd660e8a2355be023b1a1b1b60f8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 16 Jun 2020 16:58:09 -0500 Subject: [PATCH] Composer: Test scope on reply --- .../reducers/__tests__/compose-test.js | 90 ++++++++++++++++++- app/soapbox/reducers/compose.js | 2 +- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/app/soapbox/reducers/__tests__/compose-test.js b/app/soapbox/reducers/__tests__/compose-test.js index 9c13c3e71..9270aa25f 100644 --- a/app/soapbox/reducers/__tests__/compose-test.js +++ b/app/soapbox/reducers/__tests__/compose-test.js @@ -1,7 +1,11 @@ import reducer from '../compose'; +import { Map as ImmutableMap } from 'immutable'; +import { COMPOSE_REPLY } from 'soapbox/actions/compose'; +import { ME_FETCH_SUCCESS } from 'soapbox/actions/me'; +import { SETTING_CHANGE } from 'soapbox/actions/settings'; describe('compose reducer', () => { - it('should return the initial state', () => { + it('returns the initial state by default', () => { expect(reducer(undefined, {}).toJS()).toMatchObject({ mounted: 0, sensitive: false, @@ -27,4 +31,88 @@ describe('compose reducer', () => { tagHistory: [], }); }); + + it('uses \'public\' scope as default', () => { + const action = { + type: COMPOSE_REPLY, + status: ImmutableMap(), + account: ImmutableMap(), + }; + expect(reducer(undefined, action).toJS()).toMatchObject({ privacy: 'public' }); + }); + + it('uses \'direct\' scope when replying to a DM', () => { + const state = ImmutableMap({ default_privacy: 'public' }); + const action = { + type: COMPOSE_REPLY, + status: ImmutableMap({ visibility: 'direct' }), + account: ImmutableMap(), + }; + expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'direct' }); + }); + + it('uses \'private\' scope when replying to a private post', () => { + const state = ImmutableMap({ default_privacy: 'public' }); + const action = { + type: COMPOSE_REPLY, + status: ImmutableMap({ visibility: 'private' }), + account: ImmutableMap(), + }; + expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'private' }); + }); + + it('uses \'unlisted\' scope when replying to an unlisted post', () => { + const state = ImmutableMap({ default_privacy: 'public' }); + const action = { + type: COMPOSE_REPLY, + status: ImmutableMap({ visibility: 'unlisted' }), + account: ImmutableMap(), + }; + expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'unlisted' }); + }); + + it('uses \'private\' scope when set as preference and replying to a public post', () => { + const state = ImmutableMap({ default_privacy: 'private' }); + const action = { + type: COMPOSE_REPLY, + status: ImmutableMap({ visibility: 'public' }), + account: ImmutableMap(), + }; + expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'private' }); + }); + + it('uses \'unlisted\' scope when set as preference and replying to a public post', () => { + const state = ImmutableMap({ default_privacy: 'unlisted' }); + const action = { + type: COMPOSE_REPLY, + status: ImmutableMap({ visibility: 'public' }), + account: ImmutableMap(), + }; + expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'unlisted' }); + }); + + it('sets preferred scope on user login', () => { + const state = ImmutableMap({ default_privacy: 'public' }); + const action = { + type: ME_FETCH_SUCCESS, + me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } }, + }; + expect(reducer(state, action).toJS()).toMatchObject({ + default_privacy: 'unlisted', + privacy: 'unlisted', + }); + }); + + it('sets preferred scope on settings change', () => { + const state = ImmutableMap({ default_privacy: 'public' }); + const action = { + type: SETTING_CHANGE, + path: ['defaultPrivacy'], + value: 'unlisted', + }; + expect(reducer(state, action).toJS()).toMatchObject({ + default_privacy: 'unlisted', + privacy: 'unlisted', + }); + }); }); diff --git a/app/soapbox/reducers/compose.js b/app/soapbox/reducers/compose.js index d2d1f5961..5ef9842ab 100644 --- a/app/soapbox/reducers/compose.js +++ b/app/soapbox/reducers/compose.js @@ -249,7 +249,7 @@ export default function compose(state = initialState, action) { map.set('caretPosition', null); map.set('idempotencyKey', uuid()); - if (action.status.get('spoiler_text').length > 0) { + if (action.status.get('spoiler_text', '').length > 0) { map.set('spoiler', true); map.set('spoiler_text', action.status.get('spoiler_text')); } else {