sforkowany z mirror/soapbox
Fix types in reducer tests
rodzic
8685b64f9d
commit
073dd4f37a
|
@ -23,7 +23,7 @@ describe('accounts reducer', () => {
|
||||||
const action = { type: ACCOUNT_IMPORT, account };
|
const action = { type: ACCOUNT_IMPORT, account };
|
||||||
const result = reducer(undefined, action).get('106801667066418367');
|
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', () => {
|
describe('alerts reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {})).toEqual(ImmutableList());
|
expect(reducer(undefined, {} as any)).toEqual(ImmutableList());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ALERT_SHOW', () => {
|
describe('ALERT_SHOW', () => {
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe('carousels reducer', () => {
|
||||||
|
|
||||||
describe('CAROUSEL_AVATAR_REQUEST', () => {
|
describe('CAROUSEL_AVATAR_REQUEST', () => {
|
||||||
it('sets "isLoading" to "true"', () => {
|
it('sets "isLoading" to "true"', () => {
|
||||||
const initialState = { isLoading: false, avatars: [] };
|
const initialState = { isLoading: false, avatars: [], error: false };
|
||||||
const action = { type: CAROUSEL_AVATAR_REQUEST };
|
const action = { type: CAROUSEL_AVATAR_REQUEST };
|
||||||
expect(reducer(initialState, action).isLoading).toEqual(true);
|
expect(reducer(initialState, action).isLoading).toEqual(true);
|
||||||
});
|
});
|
||||||
|
@ -39,7 +39,7 @@ describe('carousels reducer', () => {
|
||||||
|
|
||||||
describe('CAROUSEL_AVATAR_FAIL', () => {
|
describe('CAROUSEL_AVATAR_FAIL', () => {
|
||||||
it('sets "isLoading" to "true"', () => {
|
it('sets "isLoading" to "true"', () => {
|
||||||
const initialState = { isLoading: true, avatars: [] };
|
const initialState = { isLoading: true, avatars: [], error: false };
|
||||||
const action = { type: CAROUSEL_AVATAR_FAIL };
|
const action = { type: CAROUSEL_AVATAR_FAIL };
|
||||||
const result = reducer(initialState, action);
|
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', () => {
|
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 = {
|
const action = {
|
||||||
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
type: actions.COMPOSE_SENSITIVITY_CHANGE,
|
||||||
};
|
};
|
||||||
|
@ -297,12 +297,12 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
||||||
const state = ReducerRecord({ default_privacy: null, privacy: 'public' });
|
const state = ReducerRecord({ default_privacy: 'public', privacy: 'private' });
|
||||||
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: null,
|
privacy: 'public',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,6 @@ import reducer from '../custom_emojis';
|
||||||
|
|
||||||
describe('custom_emojis reducer', () => {
|
describe('custom_emojis reducer', () => {
|
||||||
it('should return the initial state', () => {
|
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', () => {
|
describe('group_editor reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap({
|
||||||
groupId: null,
|
groupId: null,
|
||||||
isSubmitting: false,
|
isSubmitting: false,
|
||||||
isChanged: false,
|
isChanged: false,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../group_lists';
|
||||||
|
|
||||||
describe('group_lists reducer', () => {
|
describe('group_lists reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap({
|
||||||
featured: ImmutableList(),
|
featured: ImmutableList(),
|
||||||
member: ImmutableList(),
|
member: ImmutableList(),
|
||||||
admin: ImmutableList(),
|
admin: ImmutableList(),
|
||||||
|
|
|
@ -4,6 +4,6 @@ import reducer from '../group_relationships';
|
||||||
|
|
||||||
describe('group_relationships reducer', () => {
|
describe('group_relationships reducer', () => {
|
||||||
it('should return the initial state', () => {
|
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', () => {
|
describe('groups reducer', () => {
|
||||||
it('should return the initial state', () => {
|
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', () => {
|
describe('root reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
const result = reducer(undefined, {});
|
const result = reducer(undefined, {} as any);
|
||||||
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
||||||
expect(result.accounts.get('')).toBe(undefined);
|
expect(result.accounts.get('')).toBe(undefined);
|
||||||
expect(result.instance.version).toEqual('0.0.0');
|
expect(result.instance.version).toEqual('0.0.0');
|
||||||
|
|
|
@ -6,7 +6,7 @@ import reducer from '../meta';
|
||||||
|
|
||||||
describe('meta reducer', () => {
|
describe('meta reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
const result = reducer(undefined, {});
|
const result = reducer(undefined, {} as any);
|
||||||
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
expect(ImmutableRecord.isRecord(result)).toBe(true);
|
||||||
expect(result.instance_fetch_failed).toBe(false);
|
expect(result.instance_fetch_failed).toBe(false);
|
||||||
expect(result.swUpdating).toBe(false);
|
expect(result.swUpdating).toBe(false);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import reducer from '../mutes';
|
||||||
|
|
||||||
describe('mutes reducer', () => {
|
describe('mutes reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {}).toJS()).toEqual({
|
expect(reducer(undefined, {} as any).toJS()).toEqual({
|
||||||
new: {
|
new: {
|
||||||
isSubmitting: false,
|
isSubmitting: false,
|
||||||
accountId: null,
|
accountId: null,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../onboarding';
|
||||||
|
|
||||||
describe('onboarding reducer', () => {
|
describe('onboarding reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {})).toEqual({
|
expect(reducer(undefined, {} as any)).toEqual({
|
||||||
needsOnboarding: false,
|
needsOnboarding: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,7 @@ describe('onboarding reducer', () => {
|
||||||
describe('ONBOARDING_START', () => {
|
describe('ONBOARDING_START', () => {
|
||||||
it('sets "needsOnboarding" to "true"', () => {
|
it('sets "needsOnboarding" to "true"', () => {
|
||||||
const initialState = { needsOnboarding: false };
|
const initialState = { needsOnboarding: false };
|
||||||
const action = { type: ONBOARDING_START };
|
const action = { type: ONBOARDING_START } as any;
|
||||||
expect(reducer(initialState, action).needsOnboarding).toEqual(true);
|
expect(reducer(initialState, action).needsOnboarding).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,7 @@ describe('onboarding reducer', () => {
|
||||||
describe('ONBOARDING_END', () => {
|
describe('ONBOARDING_END', () => {
|
||||||
it('sets "needsOnboarding" to "false"', () => {
|
it('sets "needsOnboarding" to "false"', () => {
|
||||||
const initialState = { needsOnboarding: true };
|
const initialState = { needsOnboarding: true };
|
||||||
const action = { type: ONBOARDING_END };
|
const action = { type: ONBOARDING_END } as any;
|
||||||
expect(reducer(initialState, action).needsOnboarding).toEqual(false);
|
expect(reducer(initialState, action).needsOnboarding).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,14 +15,14 @@ describe('rules reducer', () => {
|
||||||
|
|
||||||
describe('RULES_FETCH_REQUEST', () => {
|
describe('RULES_FETCH_REQUEST', () => {
|
||||||
it('sets "needsOnboarding" to "true"', () => {
|
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);
|
expect(reducer(initialState, action).isLoading).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ONBOARDING_END', () => {
|
describe('ONBOARDING_END', () => {
|
||||||
it('sets "needsOnboarding" to "false"', () => {
|
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);
|
const result = reducer(initialState, action);
|
||||||
expect(result.isLoading).toEqual(false);
|
expect(result.isLoading).toEqual(false);
|
||||||
expect(result.items[0].id).toEqual('123');
|
expect(result.items[0].id).toEqual('123');
|
||||||
|
|
|
@ -4,7 +4,7 @@ import reducer from '../settings';
|
||||||
|
|
||||||
describe('settings reducer', () => {
|
describe('settings reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap({
|
||||||
saved: true,
|
saved: true,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {
|
import {
|
||||||
Map as ImmutableMap,
|
Map as ImmutableMap,
|
||||||
Record as ImmutableRecord,
|
Record as ImmutableRecord,
|
||||||
fromJS,
|
|
||||||
} from 'immutable';
|
} from 'immutable';
|
||||||
|
|
||||||
import { STATUS_IMPORT } from 'soapbox/actions/importer';
|
import { STATUS_IMPORT } from 'soapbox/actions/importer';
|
||||||
|
@ -11,12 +10,13 @@ import {
|
||||||
STATUS_DELETE_REQUEST,
|
STATUS_DELETE_REQUEST,
|
||||||
STATUS_DELETE_FAIL,
|
STATUS_DELETE_FAIL,
|
||||||
} from 'soapbox/actions/statuses';
|
} from 'soapbox/actions/statuses';
|
||||||
|
import { normalizeStatus } from 'soapbox/normalizers';
|
||||||
|
|
||||||
import reducer from '../statuses';
|
import reducer, { ReducerStatus } from '../statuses';
|
||||||
|
|
||||||
describe('statuses reducer', () => {
|
describe('statuses reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('STATUS_IMPORT', () => {
|
describe('STATUS_IMPORT', () => {
|
||||||
|
@ -35,7 +35,7 @@ describe('statuses reducer', () => {
|
||||||
const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden'];
|
const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden'];
|
||||||
|
|
||||||
const result = reducer(undefined, action)
|
const result = reducer(undefined, action)
|
||||||
.getIn(['AFChectaqZjmOVkXZ2', 'mentions'])
|
.get('AFChectaqZjmOVkXZ2')?.mentions
|
||||||
.map(mention => mention.get('username'))
|
.map(mention => mention.get('username'))
|
||||||
.toJS();
|
.toJS();
|
||||||
|
|
||||||
|
@ -84,19 +84,18 @@ describe('statuses reducer', () => {
|
||||||
remote_url: null,
|
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', () => {
|
it('fixes Pleroma attachments', () => {
|
||||||
const status = require('soapbox/__fixtures__/pleroma-status-with-attachments.json');
|
const status = require('soapbox/__fixtures__/pleroma-status-with-attachments.json');
|
||||||
const action = { type: STATUS_IMPORT, status };
|
const action = { type: STATUS_IMPORT, status };
|
||||||
const state = reducer(undefined, action);
|
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?.size).toBe(4);
|
||||||
expect(result.get(0).text_url).toBe(undefined);
|
expect(result?.get(1)?.meta).toEqual(ImmutableMap());
|
||||||
expect(result.get(1).meta).toEqual(ImmutableMap());
|
expect(result?.getIn([1, 'pleroma', 'mime_type'])).toBe('application/x-nes-rom');
|
||||||
expect(result.getIn([1, 'pleroma', 'mime_type'])).toBe('application/x-nes-rom');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hides CWs', () => {
|
it('hides CWs', () => {
|
||||||
|
@ -160,7 +159,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
||||||
|
|
||||||
describe('STATUS_CREATE_REQUEST', () => {
|
describe('STATUS_CREATE_REQUEST', () => {
|
||||||
it('increments the replies_count of its parent', () => {
|
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 = {
|
const action = {
|
||||||
type: STATUS_CREATE_REQUEST,
|
type: STATUS_CREATE_REQUEST,
|
||||||
|
@ -174,7 +175,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
||||||
|
|
||||||
describe('STATUS_CREATE_FAIL', () => {
|
describe('STATUS_CREATE_FAIL', () => {
|
||||||
it('decrements the replies_count of its parent', () => {
|
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 = {
|
const action = {
|
||||||
type: STATUS_CREATE_FAIL,
|
type: STATUS_CREATE_FAIL,
|
||||||
|
@ -188,7 +191,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
||||||
|
|
||||||
describe('STATUS_DELETE_REQUEST', () => {
|
describe('STATUS_DELETE_REQUEST', () => {
|
||||||
it('decrements the replies_count of its parent', () => {
|
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 = {
|
const action = {
|
||||||
type: STATUS_DELETE_REQUEST,
|
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', () => {
|
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 = {
|
const action = {
|
||||||
type: STATUS_DELETE_REQUEST,
|
type: STATUS_DELETE_REQUEST,
|
||||||
|
@ -214,7 +221,9 @@ Promoting free speech, even for people and ideas you dislike`;
|
||||||
|
|
||||||
describe('STATUS_DELETE_FAIL', () => {
|
describe('STATUS_DELETE_FAIL', () => {
|
||||||
it('decrements the replies_count of its parent', () => {
|
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 = {
|
const action = {
|
||||||
type: STATUS_DELETE_FAIL,
|
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', () => {
|
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 = {
|
const action = {
|
||||||
type: STATUS_DELETE_FAIL,
|
type: STATUS_DELETE_FAIL,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import reducer from '../trends';
|
||||||
|
|
||||||
describe('trends reducer', () => {
|
describe('trends reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {}).toJS()).toEqual({
|
expect(reducer(undefined, {} as any).toJS()).toEqual({
|
||||||
items: [],
|
items: [],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue