Fix types in reducer tests
This commit is contained in:
parent
8685b64f9d
commit
073dd4f37a
17 changed files with 49 additions and 38 deletions
|
@ -23,7 +23,7 @@ describe('accounts reducer', () => {
|
|||
const action = { type: ACCOUNT_IMPORT, account };
|
||||
const result = reducer(undefined, action).get('106801667066418367');
|
||||
|
||||
expect(result.moved).toBe('107945464165013501');
|
||||
expect(result?.moved).toBe('107945464165013501');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ import reducer from '../alerts';
|
|||
|
||||
describe('alerts reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableList());
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableList());
|
||||
});
|
||||
|
||||
describe('ALERT_SHOW', () => {
|
||||
|
|
|
@ -19,7 +19,7 @@ describe('carousels reducer', () => {
|
|||
|
||||
describe('CAROUSEL_AVATAR_REQUEST', () => {
|
||||
it('sets "isLoading" to "true"', () => {
|
||||
const initialState = { isLoading: false, avatars: [] };
|
||||
const initialState = { isLoading: false, avatars: [], error: false };
|
||||
const action = { type: CAROUSEL_AVATAR_REQUEST };
|
||||
expect(reducer(initialState, action).isLoading).toEqual(true);
|
||||
});
|
||||
|
@ -39,7 +39,7 @@ describe('carousels reducer', () => {
|
|||
|
||||
describe('CAROUSEL_AVATAR_FAIL', () => {
|
||||
it('sets "isLoading" to "true"', () => {
|
||||
const initialState = { isLoading: true, avatars: [] };
|
||||
const initialState = { isLoading: true, avatars: [], error: false };
|
||||
const action = { type: CAROUSEL_AVATAR_FAIL };
|
||||
const result = reducer(initialState, action);
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ describe('compose reducer', () => {
|
|||
});
|
||||
|
||||
it('should handle COMPOSE_SENSITIVITY_CHANGE on Mark Sensitive click, don\'t toggle if spoiler active', () => {
|
||||
const state = ReducerRecord({ spoiler: true, sensitive: true, idempotencyKey: null });
|
||||
const state = ReducerRecord({ spoiler: true, sensitive: true, idempotencyKey: '' });
|
||||
const action = {
|
||||
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
||||
};
|
||||
|
@ -297,12 +297,12 @@ describe('compose reducer', () => {
|
|||
});
|
||||
|
||||
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
||||
const state = ReducerRecord({ default_privacy: null, privacy: 'public' });
|
||||
const state = ReducerRecord({ default_privacy: 'public', privacy: 'private' });
|
||||
const action = {
|
||||
type: actions.COMPOSE_SUBMIT_SUCCESS,
|
||||
};
|
||||
expect(reducer(state, action).toJS()).toMatchObject({
|
||||
privacy: null,
|
||||
privacy: 'public',
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -4,6 +4,6 @@ import reducer from '../custom_emojis';
|
|||
|
||||
describe('custom_emojis reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableList());
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableList());
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../group_editor';
|
|||
|
||||
describe('group_editor reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap({
|
||||
groupId: null,
|
||||
isSubmitting: false,
|
||||
isChanged: false,
|
||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../group_lists';
|
|||
|
||||
describe('group_lists reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap({
|
||||
featured: ImmutableList(),
|
||||
member: ImmutableList(),
|
||||
admin: ImmutableList(),
|
||||
|
|
|
@ -4,6 +4,6 @@ import reducer from '../group_relationships';
|
|||
|
||||
describe('group_relationships reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap());
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,6 +4,6 @@ import reducer from '../groups';
|
|||
|
||||
describe('groups reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap());
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '..';
|
|||
|
||||
describe('root reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
const result = reducer(undefined, {});
|
||||
const result = reducer(undefined, {} as any);
|
||||
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
||||
expect(result.accounts.get('')).toBe(undefined);
|
||||
expect(result.instance.version).toEqual('0.0.0');
|
||||
|
|
|
@ -6,7 +6,7 @@ import reducer from '../meta';
|
|||
|
||||
describe('meta reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
const result = reducer(undefined, {});
|
||||
const result = reducer(undefined, {} as any);
|
||||
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
||||
expect(result.instance_fetch_failed).toBe(false);
|
||||
expect(result.swUpdating).toBe(false);
|
||||
|
|
|
@ -9,7 +9,7 @@ import reducer from '../mutes';
|
|||
|
||||
describe('mutes reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {}).toJS()).toEqual({
|
||||
expect(reducer(undefined, {} as any).toJS()).toEqual({
|
||||
new: {
|
||||
isSubmitting: false,
|
||||
accountId: null,
|
||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../onboarding';
|
|||
|
||||
describe('onboarding reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual({
|
||||
expect(reducer(undefined, {} as any)).toEqual({
|
||||
needsOnboarding: false,
|
||||
});
|
||||
});
|
||||
|
@ -12,7 +12,7 @@ describe('onboarding reducer', () => {
|
|||
describe('ONBOARDING_START', () => {
|
||||
it('sets "needsOnboarding" to "true"', () => {
|
||||
const initialState = { needsOnboarding: false };
|
||||
const action = { type: ONBOARDING_START };
|
||||
const action = { type: ONBOARDING_START } as any;
|
||||
expect(reducer(initialState, action).needsOnboarding).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ describe('onboarding reducer', () => {
|
|||
describe('ONBOARDING_END', () => {
|
||||
it('sets "needsOnboarding" to "false"', () => {
|
||||
const initialState = { needsOnboarding: true };
|
||||
const action = { type: ONBOARDING_END };
|
||||
const action = { type: ONBOARDING_END } as any;
|
||||
expect(reducer(initialState, action).needsOnboarding).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,14 +15,14 @@ describe('rules reducer', () => {
|
|||
|
||||
describe('RULES_FETCH_REQUEST', () => {
|
||||
it('sets "needsOnboarding" to "true"', () => {
|
||||
const action = { type: RULES_FETCH_REQUEST };
|
||||
const action = { type: RULES_FETCH_REQUEST } as any;
|
||||
expect(reducer(initialState, action).isLoading).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ONBOARDING_END', () => {
|
||||
it('sets "needsOnboarding" to "false"', () => {
|
||||
const action = { type: RULES_FETCH_SUCCESS, payload: [{ id: '123' }] };
|
||||
const action = { type: RULES_FETCH_SUCCESS, payload: [{ id: '123' }] } as any;
|
||||
const result = reducer(initialState, action);
|
||||
expect(result.isLoading).toEqual(false);
|
||||
expect(result.items[0].id).toEqual('123');
|
||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../settings';
|
|||
|
||||
describe('settings reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap({
|
||||
saved: true,
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
Map as ImmutableMap,
|
||||
Record as ImmutableRecord,
|
||||
fromJS,
|
||||
} from 'immutable';
|
||||
|
||||
import { STATUS_IMPORT } from 'soapbox/actions/importer';
|
||||
|
@ -11,12 +10,13 @@ import {
|
|||
STATUS_DELETE_REQUEST,
|
||||
STATUS_DELETE_FAIL,
|
||||
} from 'soapbox/actions/statuses';
|
||||
import { normalizeStatus } from 'soapbox/normalizers';
|
||||
|
||||
import reducer from '../statuses';
|
||||
import reducer, { ReducerStatus } from '../statuses';
|
||||
|
||||
describe('statuses reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap());
|
||||
});
|
||||
|
||||
describe('STATUS_IMPORT', () => {
|
||||
|
@ -35,7 +35,7 @@ describe('statuses reducer', () => {
|
|||
const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden'];
|
||||
|
||||
const result = reducer(undefined, action)
|
||||
.getIn(['AFChectaqZjmOVkXZ2', 'mentions'])
|
||||
.get('AFChectaqZjmOVkXZ2')?.mentions
|
||||
.map(mention => mention.get('username'))
|
||||
.toJS();
|
||||
|
||||
|
@ -84,19 +84,18 @@ describe('statuses reducer', () => {
|
|||
remote_url: null,
|
||||
}];
|
||||
|
||||
expect(state.getIn(['017eeb0e-e5e7-98fe-6b2b-ad02349251fb', 'media_attachments']).toJS()).toMatchObject(expected);
|
||||
expect(state.get('017eeb0e-e5e7-98fe-6b2b-ad02349251fb')?.media_attachments.toJS()).toMatchObject(expected);
|
||||
});
|
||||
|
||||
it('fixes Pleroma attachments', () => {
|
||||
const status = require('soapbox/__fixtures__/pleroma-status-with-attachments.json');
|
||||
const action = { type: STATUS_IMPORT, status };
|
||||
const state = reducer(undefined, action);
|
||||
const result = state.get('AGNkA21auFR5lnEAHw').media_attachments;
|
||||
const result = state.get('AGNkA21auFR5lnEAHw')?.media_attachments;
|
||||
|
||||
expect(result.size).toBe(4);
|
||||
expect(result.get(0).text_url).toBe(undefined);
|
||||
expect(result.get(1).meta).toEqual(ImmutableMap());
|
||||
expect(result.getIn([1, 'pleroma', 'mime_type'])).toBe('application/x-nes-rom');
|
||||
expect(result?.size).toBe(4);
|
||||
expect(result?.get(1)?.meta).toEqual(ImmutableMap());
|
||||
expect(result?.getIn([1, 'pleroma', 'mime_type'])).toBe('application/x-nes-rom');
|
||||
});
|
||||
|
||||
it('hides CWs', () => {
|
||||
|
@ -160,7 +159,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
|||
|
||||
describe('STATUS_CREATE_REQUEST', () => {
|
||||
it('increments the replies_count of its parent', () => {
|
||||
const state = fromJS({ '123': { replies_count: 4 } });
|
||||
const state = ImmutableMap({
|
||||
'123': normalizeStatus({ replies_count: 4 }) as ReducerStatus,
|
||||
});
|
||||
|
||||
const action = {
|
||||
type: STATUS_CREATE_REQUEST,
|
||||
|
@ -174,7 +175,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
|||
|
||||
describe('STATUS_CREATE_FAIL', () => {
|
||||
it('decrements the replies_count of its parent', () => {
|
||||
const state = fromJS({ '123': { replies_count: 5 } });
|
||||
const state = ImmutableMap({
|
||||
'123': normalizeStatus({ replies_count: 5 }) as ReducerStatus,
|
||||
});
|
||||
|
||||
const action = {
|
||||
type: STATUS_CREATE_FAIL,
|
||||
|
@ -188,7 +191,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
|||
|
||||
describe('STATUS_DELETE_REQUEST', () => {
|
||||
it('decrements the replies_count of its parent', () => {
|
||||
const state = fromJS({ '123': { replies_count: 4 } });
|
||||
const state = ImmutableMap({
|
||||
'123': normalizeStatus({ replies_count: 4 }) as ReducerStatus,
|
||||
});
|
||||
|
||||
const action = {
|
||||
type: STATUS_DELETE_REQUEST,
|
||||
|
@ -200,7 +205,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
|||
});
|
||||
|
||||
it('gracefully does nothing if no parent', () => {
|
||||
const state = fromJS({ '123': { replies_count: 4 } });
|
||||
const state = ImmutableMap({
|
||||
'123': normalizeStatus({ replies_count: 4 }) as ReducerStatus,
|
||||
});
|
||||
|
||||
const action = {
|
||||
type: STATUS_DELETE_REQUEST,
|
||||
|
@ -214,7 +221,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
|||
|
||||
describe('STATUS_DELETE_FAIL', () => {
|
||||
it('decrements the replies_count of its parent', () => {
|
||||
const state = fromJS({ '123': { replies_count: 4 } });
|
||||
const state = ImmutableMap({
|
||||
'123': normalizeStatus({ replies_count: 4 }) as ReducerStatus,
|
||||
});
|
||||
|
||||
const action = {
|
||||
type: STATUS_DELETE_FAIL,
|
||||
|
@ -226,7 +235,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
|||
});
|
||||
|
||||
it('gracefully does nothing if no parent', () => {
|
||||
const state = fromJS({ '123': { replies_count: 4 } });
|
||||
const state = ImmutableMap({
|
||||
'123': normalizeStatus({ replies_count: 4 }) as ReducerStatus,
|
||||
});
|
||||
|
||||
const action = {
|
||||
type: STATUS_DELETE_FAIL,
|
||||
|
|
|
@ -2,7 +2,7 @@ import reducer from '../trends';
|
|||
|
||||
describe('trends reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {}).toJS()).toEqual({
|
||||
expect(reducer(undefined, {} as any).toJS()).toEqual({
|
||||
items: [],
|
||||
isLoading: false,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue