Update tests
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
7d0247bc27
commit
88f690824c
|
@ -8,8 +8,6 @@ import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
||||||
|
|
||||||
import Column from '../ui/components/better_column';
|
import Column from '../ui/components/better_column';
|
||||||
|
|
||||||
import type { List as ImmutableList, Map as ImmutableMap } from 'immutable';
|
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.backups', defaultMessage: 'Backups' },
|
heading: { id: 'column.backups', defaultMessage: 'Backups' },
|
||||||
create: { id: 'backups.actions.create', defaultMessage: 'Create backup' },
|
create: { id: 'backups.actions.create', defaultMessage: 'Create backup' },
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { List as ImmutableList, Map as ImmutableMap, fromJS } from 'immutable';
|
import { List as ImmutableList, Record as ImmutableRecord, fromJS } from 'immutable';
|
||||||
|
|
||||||
import * as actions from 'soapbox/actions/compose';
|
import * as actions from 'soapbox/actions/compose';
|
||||||
import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me';
|
import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me';
|
||||||
|
@ -6,11 +6,11 @@ import { SETTING_CHANGE } from 'soapbox/actions/settings';
|
||||||
import { TIMELINE_DELETE } from 'soapbox/actions/timelines';
|
import { TIMELINE_DELETE } from 'soapbox/actions/timelines';
|
||||||
import { normalizeStatus } from 'soapbox/normalizers/status';
|
import { normalizeStatus } from 'soapbox/normalizers/status';
|
||||||
|
|
||||||
import reducer from '../compose';
|
import reducer, { ReducerRecord } from '../compose';
|
||||||
|
|
||||||
describe('compose reducer', () => {
|
describe('compose reducer', () => {
|
||||||
it('returns the initial state by default', () => {
|
it('returns the initial state by default', () => {
|
||||||
const state = reducer(undefined, {});
|
const state = reducer(undefined, {} as any);
|
||||||
expect(state.toJS()).toMatchObject({
|
expect(state.toJS()).toMatchObject({
|
||||||
mounted: 0,
|
mounted: 0,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
|
@ -86,64 +86,64 @@ describe('compose reducer', () => {
|
||||||
it('uses \'public\' scope as default', () => {
|
it('uses \'public\' scope as default', () => {
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableMap(),
|
status: ImmutableRecord({})(),
|
||||||
account: ImmutableMap(),
|
account: ImmutableRecord({})(),
|
||||||
};
|
};
|
||||||
expect(reducer(undefined, action).toJS()).toMatchObject({ privacy: 'public' });
|
expect(reducer(undefined, action).toJS()).toMatchObject({ privacy: 'public' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'direct\' scope when replying to a DM', () => {
|
it('uses \'direct\' scope when replying to a DM', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableMap({ visibility: 'direct' }),
|
status: ImmutableRecord({ visibility: 'direct' })(),
|
||||||
account: ImmutableMap(),
|
account: ImmutableRecord({})(),
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'direct' });
|
expect(reducer(state as any, action).toJS()).toMatchObject({ privacy: 'direct' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'private\' scope when replying to a private post', () => {
|
it('uses \'private\' scope when replying to a private post', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableMap({ visibility: 'private' }),
|
status: ImmutableRecord({ visibility: 'private' })(),
|
||||||
account: ImmutableMap(),
|
account: ImmutableRecord({})(),
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'private' });
|
expect(reducer(state as any, action).toJS()).toMatchObject({ privacy: 'private' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'unlisted\' scope when replying to an unlisted post', () => {
|
it('uses \'unlisted\' scope when replying to an unlisted post', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableMap({ visibility: 'unlisted' }),
|
status: ImmutableRecord({ visibility: 'unlisted' })(),
|
||||||
account: ImmutableMap(),
|
account: ImmutableRecord({})(),
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'unlisted' });
|
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'unlisted' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'private\' scope when set as preference and replying to a public post', () => {
|
it('uses \'private\' scope when set as preference and replying to a public post', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'private' });
|
const state = ReducerRecord({ default_privacy: 'private' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableMap({ visibility: 'public' }),
|
status: ImmutableRecord({ visibility: 'public' })(),
|
||||||
account: ImmutableMap(),
|
account: ImmutableRecord({})(),
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'private' });
|
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'private' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'unlisted\' scope when set as preference and replying to a public post', () => {
|
it('uses \'unlisted\' scope when set as preference and replying to a public post', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'unlisted' });
|
const state = ReducerRecord({ default_privacy: 'unlisted' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableMap({ visibility: 'public' }),
|
status: ImmutableRecord({ visibility: 'public' })(),
|
||||||
account: ImmutableMap(),
|
account: ImmutableRecord({})(),
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'unlisted' });
|
expect(reducer(state, action).toJS()).toMatchObject({ privacy: 'unlisted' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets preferred scope on user login', () => {
|
it('sets preferred scope on user login', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: ME_FETCH_SUCCESS,
|
type: ME_FETCH_SUCCESS,
|
||||||
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
||||||
|
@ -155,7 +155,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets preferred scope on settings change', () => {
|
it('sets preferred scope on settings change', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: SETTING_CHANGE,
|
type: SETTING_CHANGE,
|
||||||
path: ['defaultPrivacy'],
|
path: ['defaultPrivacy'],
|
||||||
|
@ -168,7 +168,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets default scope on settings save (but retains current scope)', () => {
|
it('sets default scope on settings save (but retains current scope)', () => {
|
||||||
const state = ImmutableMap({ default_privacy: 'public', privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public', privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: ME_PATCH_SUCCESS,
|
type: ME_PATCH_SUCCESS,
|
||||||
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
||||||
|
@ -180,7 +180,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_MOUNT', () => {
|
it('should handle COMPOSE_MOUNT', () => {
|
||||||
const state = ImmutableMap({ mounted: 1 });
|
const state = ReducerRecord({ mounted: 1 });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_MOUNT,
|
type: actions.COMPOSE_MOUNT,
|
||||||
};
|
};
|
||||||
|
@ -190,7 +190,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UNMOUNT', () => {
|
it('should handle COMPOSE_UNMOUNT', () => {
|
||||||
const state = ImmutableMap({ mounted: 1 });
|
const state = ReducerRecord({ mounted: 1 });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_UNMOUNT,
|
type: actions.COMPOSE_UNMOUNT,
|
||||||
};
|
};
|
||||||
|
@ -200,7 +200,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SENSITIVITY_CHANGE on Mark Sensitive click, don\'t toggle if spoiler active', () => {
|
it('should handle COMPOSE_SENSITIVITY_CHANGE on Mark Sensitive click, don\'t toggle if spoiler active', () => {
|
||||||
const state = ImmutableMap({ spoiler: true, sensitive: true, idempotencyKey: null });
|
const state = ReducerRecord({ spoiler: true, sensitive: true, idempotencyKey: null });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
||||||
};
|
};
|
||||||
|
@ -210,7 +210,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SENSITIVITY_CHANGE on Mark Sensitive click, toggle if spoiler inactive', () => {
|
it('should handle COMPOSE_SENSITIVITY_CHANGE on Mark Sensitive click, toggle if spoiler inactive', () => {
|
||||||
const state = ImmutableMap({ spoiler: false, sensitive: true });
|
const state = ReducerRecord({ spoiler: false, sensitive: true });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
||||||
};
|
};
|
||||||
|
@ -220,7 +220,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SPOILERNESS_CHANGE on CW button click', () => {
|
it('should handle COMPOSE_SPOILERNESS_CHANGE on CW button click', () => {
|
||||||
const state = ImmutableMap({ spoiler_text: 'spoiler text', spoiler: true, media_attachments: ImmutableList() });
|
const state = ReducerRecord({ spoiler_text: 'spoiler text', spoiler: true, media_attachments: ImmutableList() });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SPOILERNESS_CHANGE,
|
type: actions.COMPOSE_SPOILERNESS_CHANGE,
|
||||||
};
|
};
|
||||||
|
@ -231,7 +231,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SPOILER_TEXT_CHANGE', () => {
|
it('should handle COMPOSE_SPOILER_TEXT_CHANGE', () => {
|
||||||
const state = ImmutableMap({ spoiler_text: 'prevtext' });
|
const state = ReducerRecord({ spoiler_text: 'prevtext' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SPOILER_TEXT_CHANGE,
|
type: actions.COMPOSE_SPOILER_TEXT_CHANGE,
|
||||||
text: 'nexttext',
|
text: 'nexttext',
|
||||||
|
@ -242,7 +242,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_VISIBILITY_CHANGE', () => {
|
it('should handle COMPOSE_VISIBILITY_CHANGE', () => {
|
||||||
const state = ImmutableMap({ privacy: 'public' });
|
const state = ReducerRecord({ privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_VISIBILITY_CHANGE,
|
type: actions.COMPOSE_VISIBILITY_CHANGE,
|
||||||
value: 'direct',
|
value: 'direct',
|
||||||
|
@ -254,7 +254,7 @@ describe('compose reducer', () => {
|
||||||
|
|
||||||
describe('COMPOSE_CHANGE', () => {
|
describe('COMPOSE_CHANGE', () => {
|
||||||
it('should handle text changing', () => {
|
it('should handle text changing', () => {
|
||||||
const state = ImmutableMap({ text: 'prevtext' });
|
const state = ReducerRecord({ text: 'prevtext' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_CHANGE,
|
type: actions.COMPOSE_CHANGE,
|
||||||
text: 'nexttext',
|
text: 'nexttext',
|
||||||
|
@ -266,7 +266,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_COMPOSING_CHANGE', () => {
|
it('should handle COMPOSE_COMPOSING_CHANGE', () => {
|
||||||
const state = ImmutableMap({ is_composing: true });
|
const state = ReducerRecord({ is_composing: true });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_COMPOSING_CHANGE,
|
type: actions.COMPOSE_COMPOSING_CHANGE,
|
||||||
value: false,
|
value: false,
|
||||||
|
@ -277,7 +277,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SUBMIT_REQUEST', () => {
|
it('should handle COMPOSE_SUBMIT_REQUEST', () => {
|
||||||
const state = ImmutableMap({ is_submitting: false });
|
const state = ReducerRecord({ is_submitting: false });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SUBMIT_REQUEST,
|
type: actions.COMPOSE_SUBMIT_REQUEST,
|
||||||
};
|
};
|
||||||
|
@ -287,7 +287,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UPLOAD_CHANGE_REQUEST', () => {
|
it('should handle COMPOSE_UPLOAD_CHANGE_REQUEST', () => {
|
||||||
const state = ImmutableMap({ is_changing_upload: false });
|
const state = ReducerRecord({ is_changing_upload: false });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_UPLOAD_CHANGE_REQUEST,
|
type: actions.COMPOSE_UPLOAD_CHANGE_REQUEST,
|
||||||
};
|
};
|
||||||
|
@ -297,17 +297,17 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
||||||
const state = ImmutableMap({ privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: null, privacy: 'public' });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SUBMIT_SUCCESS,
|
type: actions.COMPOSE_SUBMIT_SUCCESS,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS()).toMatchObject({
|
expect(reducer(state, action).toJS()).toMatchObject({
|
||||||
privacy: undefined,
|
privacy: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SUBMIT_FAIL', () => {
|
it('should handle COMPOSE_SUBMIT_FAIL', () => {
|
||||||
const state = ImmutableMap({ is_submitting: true });
|
const state = ReducerRecord({ is_submitting: true });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SUBMIT_FAIL,
|
type: actions.COMPOSE_SUBMIT_FAIL,
|
||||||
};
|
};
|
||||||
|
@ -317,7 +317,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UPLOAD_CHANGE_FAIL', () => {
|
it('should handle COMPOSE_UPLOAD_CHANGE_FAIL', () => {
|
||||||
const state = ImmutableMap({ is_changing_upload: true });
|
const state = ReducerRecord({ is_changing_upload: true });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_UPLOAD_CHANGE_FAIL,
|
type: actions.COMPOSE_UPLOAD_CHANGE_FAIL,
|
||||||
};
|
};
|
||||||
|
@ -327,7 +327,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UPLOAD_REQUEST', () => {
|
it('should handle COMPOSE_UPLOAD_REQUEST', () => {
|
||||||
const state = ImmutableMap({ is_uploading: false });
|
const state = ReducerRecord({ is_uploading: false });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_UPLOAD_REQUEST,
|
type: actions.COMPOSE_UPLOAD_REQUEST,
|
||||||
};
|
};
|
||||||
|
@ -337,7 +337,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UPLOAD_SUCCESS', () => {
|
it('should handle COMPOSE_UPLOAD_SUCCESS', () => {
|
||||||
const state = ImmutableMap({ media_attachments: ImmutableList() });
|
const state = ReducerRecord({ media_attachments: ImmutableList() });
|
||||||
const media = [
|
const media = [
|
||||||
{
|
{
|
||||||
description: null,
|
description: null,
|
||||||
|
@ -363,7 +363,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UPLOAD_FAIL', () => {
|
it('should handle COMPOSE_UPLOAD_FAIL', () => {
|
||||||
const state = ImmutableMap({ is_uploading: true });
|
const state = ReducerRecord({ is_uploading: true });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_UPLOAD_FAIL,
|
type: actions.COMPOSE_UPLOAD_FAIL,
|
||||||
};
|
};
|
||||||
|
@ -373,7 +373,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_UPLOAD_PROGRESS', () => {
|
it('should handle COMPOSE_UPLOAD_PROGRESS', () => {
|
||||||
const state = ImmutableMap({ progress: 0 });
|
const state = ReducerRecord({ progress: 0 });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_UPLOAD_PROGRESS,
|
type: actions.COMPOSE_UPLOAD_PROGRESS,
|
||||||
loaded: 10,
|
loaded: 10,
|
||||||
|
@ -396,7 +396,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SUGGESTION_TAGS_UPDATE', () => {
|
it('should handle COMPOSE_SUGGESTION_TAGS_UPDATE', () => {
|
||||||
const state = ImmutableMap({ tagHistory: ImmutableList([ 'hashtag' ]) });
|
const state = ReducerRecord({ tagHistory: ImmutableList([ 'hashtag' ]) });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SUGGESTION_TAGS_UPDATE,
|
type: actions.COMPOSE_SUGGESTION_TAGS_UPDATE,
|
||||||
token: 'aaadken3',
|
token: 'aaadken3',
|
||||||
|
@ -419,7 +419,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle TIMELINE_DELETE - delete status from timeline', () => {
|
it('should handle TIMELINE_DELETE - delete status from timeline', () => {
|
||||||
const state = ImmutableMap({ in_reply_to: '9wk6pmImMrZjgrK7iC' });
|
const state = ReducerRecord({ in_reply_to: '9wk6pmImMrZjgrK7iC' });
|
||||||
const action = {
|
const action = {
|
||||||
type: TIMELINE_DELETE,
|
type: TIMELINE_DELETE,
|
||||||
id: '9wk6pmImMrZjgrK7iC',
|
id: '9wk6pmImMrZjgrK7iC',
|
||||||
|
@ -430,7 +430,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_POLL_ADD', () => {
|
it('should handle COMPOSE_POLL_ADD', () => {
|
||||||
const state = ImmutableMap({ poll: null });
|
const state = ReducerRecord({ poll: null });
|
||||||
const initialPoll = Object({
|
const initialPoll = Object({
|
||||||
options: [
|
options: [
|
||||||
'',
|
'',
|
||||||
|
@ -465,7 +465,7 @@ describe('compose reducer', () => {
|
||||||
expires_in: 86400,
|
expires_in: 86400,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
});
|
});
|
||||||
const state = ImmutableMap({ poll: initialPoll });
|
const state = ReducerRecord({ poll: initialPoll });
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_POLL_OPTION_CHANGE,
|
type: actions.COMPOSE_POLL_OPTION_CHANGE,
|
||||||
index: 0,
|
index: 0,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
|
import { Map as ImmutableMap, Record as ImmutableRecord } from 'immutable';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BACKUPS_FETCH_SUCCESS,
|
BACKUPS_FETCH_SUCCESS,
|
||||||
|
|
|
@ -75,14 +75,14 @@ const PollRecord = ImmutableRecord({
|
||||||
multiple: false,
|
multiple: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const ReducerRecord = ImmutableRecord({
|
export const ReducerRecord = ImmutableRecord({
|
||||||
caretPosition: null as number | null,
|
caretPosition: null as number | null,
|
||||||
content_type: 'text/plain',
|
content_type: 'text/plain',
|
||||||
default_content_type: 'text/plain',
|
default_content_type: 'text/plain',
|
||||||
default_privacy: 'public',
|
default_privacy: 'public',
|
||||||
default_sensitive: false,
|
default_sensitive: false,
|
||||||
focusDate: null as Date | null,
|
focusDate: null as Date | null,
|
||||||
idempotencyKey: uuid(),
|
idempotencyKey: '',
|
||||||
id: null as string | null,
|
id: null as string | null,
|
||||||
in_reply_to: null as string | null,
|
in_reply_to: null as string | null,
|
||||||
is_changing_upload: false,
|
is_changing_upload: false,
|
||||||
|
@ -112,7 +112,7 @@ type Poll = ReturnType<typeof PollRecord>;
|
||||||
|
|
||||||
const statusToTextMentions = (state: State, status: ImmutableMap<string, any>, account: AccountEntity) => {
|
const statusToTextMentions = (state: State, status: ImmutableMap<string, any>, account: AccountEntity) => {
|
||||||
const author = status.getIn(['account', 'acct']);
|
const author = status.getIn(['account', 'acct']);
|
||||||
const mentions = status.get('mentions').map((m: ImmutableMap<string, any>) => m.get('acct'));
|
const mentions = status.get('mentions')?.map((m: ImmutableMap<string, any>) => m.get('acct')) || [];
|
||||||
|
|
||||||
return ImmutableOrderedSet([author])
|
return ImmutableOrderedSet([author])
|
||||||
.concat(mentions)
|
.concat(mentions)
|
||||||
|
@ -123,7 +123,7 @@ const statusToTextMentions = (state: State, status: ImmutableMap<string, any>, a
|
||||||
|
|
||||||
export const statusToMentionsArray = (status: ImmutableMap<string, any>, account: AccountEntity) => {
|
export const statusToMentionsArray = (status: ImmutableMap<string, any>, account: AccountEntity) => {
|
||||||
const author = status.getIn(['account', 'acct']) as string;
|
const author = status.getIn(['account', 'acct']) as string;
|
||||||
const mentions = status.get('mentions').map((m: ImmutableMap<string, any>) => m.get('acct'));
|
const mentions = status.get('mentions')?.map((m: ImmutableMap<string, any>) => m.get('acct')) || [];
|
||||||
|
|
||||||
return ImmutableOrderedSet([author])
|
return ImmutableOrderedSet([author])
|
||||||
.concat(mentions)
|
.concat(mentions)
|
||||||
|
@ -140,24 +140,29 @@ export const statusToMentionsAccountIdsArray = (status: StatusEntity, account: A
|
||||||
};
|
};
|
||||||
|
|
||||||
function clearAll(state: State) {
|
function clearAll(state: State) {
|
||||||
return state.withMutations(map => {
|
return ReducerRecord({
|
||||||
map.set('id', null);
|
content_type: state.default_content_type,
|
||||||
map.set('text', '');
|
privacy: state.default_privacy,
|
||||||
map.set('to', ImmutableOrderedSet());
|
idempotencyKey: uuid(),
|
||||||
map.set('spoiler', false);
|
|
||||||
map.set('spoiler_text', '');
|
|
||||||
map.set('content_type', state.default_content_type);
|
|
||||||
map.set('is_submitting', false);
|
|
||||||
map.set('is_changing_upload', false);
|
|
||||||
map.set('in_reply_to', null);
|
|
||||||
map.set('quote', null);
|
|
||||||
map.set('privacy', state.default_privacy);
|
|
||||||
map.set('sensitive', false);
|
|
||||||
map.set('media_attachments', ImmutableList());
|
|
||||||
map.set('poll', null);
|
|
||||||
map.set('idempotencyKey', uuid());
|
|
||||||
map.set('schedule', null);
|
|
||||||
});
|
});
|
||||||
|
// state.withMutations(map => {
|
||||||
|
// map.set('id', null);
|
||||||
|
// map.set('text', '');
|
||||||
|
// map.set('to', ImmutableOrderedSet());
|
||||||
|
// map.set('spoiler', false);
|
||||||
|
// map.set('spoiler_text', '');
|
||||||
|
// map.set('content_type', state.COMPOSE_SUBMIT_SUCCESS);
|
||||||
|
// map.set('is_submitting', false);
|
||||||
|
// map.set('is_changing_upload', false);
|
||||||
|
// map.set('in_reply_to', null);
|
||||||
|
// map.set('quote', null);
|
||||||
|
// map.set('privacy', state.default_privacy);
|
||||||
|
// map.set('sensitive', false);
|
||||||
|
// map.set('media_attachments', ImmutableList());
|
||||||
|
// map.set('poll', null);
|
||||||
|
// map.set('idempotencyKey', uuid());
|
||||||
|
// map.set('schedule', null);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendMedia(state: State, media: APIEntity) {
|
function appendMedia(state: State, media: APIEntity) {
|
||||||
|
@ -297,7 +302,7 @@ const updateSetting = (state: State, path: string[], value: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function compose(state = ReducerRecord({ resetFileKey: getResetFileKey() }), action: AnyAction) {
|
export default function compose(state = ReducerRecord({ idempotencyKey: uuid(), resetFileKey: getResetFileKey() }), action: AnyAction) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case COMPOSE_MOUNT:
|
case COMPOSE_MOUNT:
|
||||||
return state.set('mounted', state.mounted + 1);
|
return state.set('mounted', state.mounted + 1);
|
||||||
|
|
Loading…
Reference in New Issue