From 073dd4f37ae9d44c995f24e53af59d2779b1dcca Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 6 Jul 2022 11:53:55 -0500 Subject: [PATCH] Fix types in reducer tests --- .../reducers/__tests__/accounts.test.ts | 2 +- app/soapbox/reducers/__tests__/alerts.test.ts | 2 +- .../reducers/__tests__/carousels.test.ts | 4 +- .../reducers/__tests__/compose.test.ts | 6 +-- .../reducers/__tests__/custom_emojis.test.ts | 2 +- .../reducers/__tests__/group_editor.test.ts | 2 +- .../reducers/__tests__/group_lists.test.ts | 2 +- .../__tests__/group_relationships.test.ts | 2 +- app/soapbox/reducers/__tests__/groups.test.ts | 2 +- app/soapbox/reducers/__tests__/index.test.ts | 2 +- app/soapbox/reducers/__tests__/meta.test.ts | 2 +- app/soapbox/reducers/__tests__/mutes.test.ts | 2 +- .../reducers/__tests__/onboarding.test.ts | 6 +-- app/soapbox/reducers/__tests__/rules.test.ts | 4 +- .../reducers/__tests__/settings.test.ts | 2 +- .../reducers/__tests__/statuses.test.ts | 43 ++++++++++++------- app/soapbox/reducers/__tests__/trends.test.ts | 2 +- 17 files changed, 49 insertions(+), 38 deletions(-) diff --git a/app/soapbox/reducers/__tests__/accounts.test.ts b/app/soapbox/reducers/__tests__/accounts.test.ts index 647bb676a..02baa6d92 100644 --- a/app/soapbox/reducers/__tests__/accounts.test.ts +++ b/app/soapbox/reducers/__tests__/accounts.test.ts @@ -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'); }); }); }); diff --git a/app/soapbox/reducers/__tests__/alerts.test.ts b/app/soapbox/reducers/__tests__/alerts.test.ts index 306ab2fcd..441cf2d8d 100644 --- a/app/soapbox/reducers/__tests__/alerts.test.ts +++ b/app/soapbox/reducers/__tests__/alerts.test.ts @@ -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', () => { diff --git a/app/soapbox/reducers/__tests__/carousels.test.ts b/app/soapbox/reducers/__tests__/carousels.test.ts index 45e87c8ff..2745b078d 100644 --- a/app/soapbox/reducers/__tests__/carousels.test.ts +++ b/app/soapbox/reducers/__tests__/carousels.test.ts @@ -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); diff --git a/app/soapbox/reducers/__tests__/compose.test.ts b/app/soapbox/reducers/__tests__/compose.test.ts index a1d40fe7c..bb6906c6d 100644 --- a/app/soapbox/reducers/__tests__/compose.test.ts +++ b/app/soapbox/reducers/__tests__/compose.test.ts @@ -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', }); }); diff --git a/app/soapbox/reducers/__tests__/custom_emojis.test.ts b/app/soapbox/reducers/__tests__/custom_emojis.test.ts index 43fec78ec..e2991d5fb 100644 --- a/app/soapbox/reducers/__tests__/custom_emojis.test.ts +++ b/app/soapbox/reducers/__tests__/custom_emojis.test.ts @@ -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()); }); }); diff --git a/app/soapbox/reducers/__tests__/group_editor.test.ts b/app/soapbox/reducers/__tests__/group_editor.test.ts index 73c9e1b6a..516b6df43 100644 --- a/app/soapbox/reducers/__tests__/group_editor.test.ts +++ b/app/soapbox/reducers/__tests__/group_editor.test.ts @@ -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, diff --git a/app/soapbox/reducers/__tests__/group_lists.test.ts b/app/soapbox/reducers/__tests__/group_lists.test.ts index fa5c21eea..46527f682 100644 --- a/app/soapbox/reducers/__tests__/group_lists.test.ts +++ b/app/soapbox/reducers/__tests__/group_lists.test.ts @@ -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(), diff --git a/app/soapbox/reducers/__tests__/group_relationships.test.ts b/app/soapbox/reducers/__tests__/group_relationships.test.ts index 17cabf3c2..31e3e354f 100644 --- a/app/soapbox/reducers/__tests__/group_relationships.test.ts +++ b/app/soapbox/reducers/__tests__/group_relationships.test.ts @@ -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()); }); }); diff --git a/app/soapbox/reducers/__tests__/groups.test.ts b/app/soapbox/reducers/__tests__/groups.test.ts index 94a1a6ffe..05b88402f 100644 --- a/app/soapbox/reducers/__tests__/groups.test.ts +++ b/app/soapbox/reducers/__tests__/groups.test.ts @@ -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()); }); }); diff --git a/app/soapbox/reducers/__tests__/index.test.ts b/app/soapbox/reducers/__tests__/index.test.ts index 15572f337..e5674e91b 100644 --- a/app/soapbox/reducers/__tests__/index.test.ts +++ b/app/soapbox/reducers/__tests__/index.test.ts @@ -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'); diff --git a/app/soapbox/reducers/__tests__/meta.test.ts b/app/soapbox/reducers/__tests__/meta.test.ts index d318b4a30..272116391 100644 --- a/app/soapbox/reducers/__tests__/meta.test.ts +++ b/app/soapbox/reducers/__tests__/meta.test.ts @@ -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); diff --git a/app/soapbox/reducers/__tests__/mutes.test.ts b/app/soapbox/reducers/__tests__/mutes.test.ts index 411db10c6..66a866958 100644 --- a/app/soapbox/reducers/__tests__/mutes.test.ts +++ b/app/soapbox/reducers/__tests__/mutes.test.ts @@ -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, diff --git a/app/soapbox/reducers/__tests__/onboarding.test.ts b/app/soapbox/reducers/__tests__/onboarding.test.ts index 95ecdf755..69b4b1b21 100644 --- a/app/soapbox/reducers/__tests__/onboarding.test.ts +++ b/app/soapbox/reducers/__tests__/onboarding.test.ts @@ -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); }); }); diff --git a/app/soapbox/reducers/__tests__/rules.test.ts b/app/soapbox/reducers/__tests__/rules.test.ts index 151516a83..25f8575ed 100644 --- a/app/soapbox/reducers/__tests__/rules.test.ts +++ b/app/soapbox/reducers/__tests__/rules.test.ts @@ -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'); diff --git a/app/soapbox/reducers/__tests__/settings.test.ts b/app/soapbox/reducers/__tests__/settings.test.ts index b4574d55c..5b065fd4c 100644 --- a/app/soapbox/reducers/__tests__/settings.test.ts +++ b/app/soapbox/reducers/__tests__/settings.test.ts @@ -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, })); }); diff --git a/app/soapbox/reducers/__tests__/statuses.test.ts b/app/soapbox/reducers/__tests__/statuses.test.ts index fb245062a..06d82c871 100644 --- a/app/soapbox/reducers/__tests__/statuses.test.ts +++ b/app/soapbox/reducers/__tests__/statuses.test.ts @@ -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, diff --git a/app/soapbox/reducers/__tests__/trends.test.ts b/app/soapbox/reducers/__tests__/trends.test.ts index 644654038..25330d770 100644 --- a/app/soapbox/reducers/__tests__/trends.test.ts +++ b/app/soapbox/reducers/__tests__/trends.test.ts @@ -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, });