Composer: Test scope on reply
This commit is contained in:
parent
6de623127c
commit
f01a8b5b8f
|
@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue