diff --git a/app/soapbox/actions/__tests__/account-notes.test.ts b/app/soapbox/actions/__tests__/account-notes.test.ts index 134b0abc7..61e0c20b0 100644 --- a/app/soapbox/actions/__tests__/account-notes.test.ts +++ b/app/soapbox/actions/__tests__/account-notes.test.ts @@ -1,18 +1,20 @@ import { Map as ImmutableMap } from 'immutable'; import { __stub } from 'soapbox/api'; -import { mockStore } from 'soapbox/jest/test-helpers'; -import rootReducer from 'soapbox/reducers'; +import { mockStore, rootState } from 'soapbox/jest/test-helpers'; +import { ReducerRecord, EditRecord } from 'soapbox/reducers/account_notes'; -import { normalizeAccount } from '../../normalizers'; +import { normalizeAccount, normalizeRelationship } from '../../normalizers'; import { changeAccountNoteComment, initAccountNoteModal, submitAccountNote } from '../account-notes'; +import type { Account } from 'soapbox/types/entities'; + describe('submitAccountNote()', () => { - let store; + let store: ReturnType; beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('account_notes', { edit: { account: 1, comment: 'hello' } }); + const state = rootState + .set('account_notes', ReducerRecord({ edit: EditRecord({ account: '1', comment: 'hello' }) })); store = mockStore(state); }); @@ -60,11 +62,11 @@ describe('submitAccountNote()', () => { }); describe('initAccountNoteModal()', () => { - let store; + let store: ReturnType; beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('relationships', ImmutableMap({ 1: { note: 'hello' } })); + const state = rootState + .set('relationships', ImmutableMap({ '1': normalizeRelationship({ note: 'hello' }) })); store = mockStore(state); }); @@ -75,7 +77,7 @@ describe('initAccountNoteModal()', () => { display_name: 'Justin L', avatar: 'test.jpg', verified: true, - }); + }) as Account; const expectedActions = [ { type: 'ACCOUNT_NOTE_INIT_MODAL', account, comment: 'hello' }, { type: 'MODAL_OPEN', modalType: 'ACCOUNT_NOTE' }, @@ -88,10 +90,10 @@ describe('initAccountNoteModal()', () => { }); describe('changeAccountNoteComment()', () => { - let store; + let store: ReturnType; beforeEach(() => { - const state = rootReducer(undefined, {}); + const state = rootState; store = mockStore(state); }); diff --git a/app/soapbox/actions/__tests__/accounts.test.ts b/app/soapbox/actions/__tests__/accounts.test.ts index dcfeabcf1..0793e36f7 100644 --- a/app/soapbox/actions/__tests__/accounts.test.ts +++ b/app/soapbox/actions/__tests__/accounts.test.ts @@ -1,10 +1,10 @@ import { Map as ImmutableMap } from 'immutable'; import { __stub } from 'soapbox/api'; -import { mockStore } from 'soapbox/jest/test-helpers'; -import rootReducer from 'soapbox/reducers'; +import { mockStore, rootState } from 'soapbox/jest/test-helpers'; +import { ListRecord, ReducerRecord } from 'soapbox/reducers/user_lists'; -import { normalizeAccount } from '../../normalizers'; +import { normalizeAccount, normalizeInstance, normalizeRelationship } from '../../normalizers'; import { authorizeFollowRequest, blockAccount, @@ -28,7 +28,7 @@ import { unsubscribeAccount, } from '../accounts'; -let store; +let store: ReturnType; describe('createAccount()', () => { const params = { @@ -37,7 +37,7 @@ describe('createAccount()', () => { describe('with a successful API request', () => { beforeEach(() => { - const state = rootReducer(undefined, {}); + const state = rootState; store = mockStore(state); __stub((mock) => { @@ -74,10 +74,10 @@ describe('fetchAccount()', () => { avatar: 'test.jpg', }); - const state = rootReducer(undefined, {}) + const state = rootState .set('accounts', ImmutableMap({ [id]: account, - })); + }) as any); store = mockStore(state); @@ -98,7 +98,7 @@ describe('fetchAccount()', () => { const account = require('soapbox/__fixtures__/pleroma-account.json'); beforeEach(() => { - const state = rootReducer(undefined, {}); + const state = rootState; store = mockStore(state); __stub((mock) => { @@ -125,7 +125,7 @@ describe('fetchAccount()', () => { describe('with an unsuccessful API request', () => { beforeEach(() => { - const state = rootReducer(undefined, {}); + const state = rootState; store = mockStore(state); __stub((mock) => { @@ -155,7 +155,7 @@ describe('fetchAccount()', () => { describe('fetchAccountByUsername()', () => { const id = '123'; const username = 'tiger'; - let state, account; + let state, account: any; beforeEach(() => { account = normalizeAccount({ @@ -166,7 +166,7 @@ describe('fetchAccountByUsername()', () => { birthday: undefined, }); - state = rootReducer(undefined, {}) + state = rootState .set('accounts', ImmutableMap({ [id]: account, })); @@ -180,15 +180,15 @@ describe('fetchAccountByUsername()', () => { describe('when "accountByUsername" feature is enabled', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('instance', { + const state = rootState + .set('instance', normalizeInstance({ version: '2.7.2 (compatible; Pleroma 2.4.52-1337-g4779199e.gleasonator+soapbox)', pleroma: ImmutableMap({ metadata: ImmutableMap({ features: [], }), }), - }) + })) .set('me', '123'); store = mockStore(state); }); @@ -243,15 +243,15 @@ describe('fetchAccountByUsername()', () => { describe('when "accountLookup" feature is enabled', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('instance', { + const state = rootState + .set('instance', normalizeInstance({ version: '3.4.1 (compatible; TruthSocial 1.0.0)', pleroma: ImmutableMap({ metadata: ImmutableMap({ features: [], }), }), - }) + })) .set('me', '123'); store = mockStore(state); }); @@ -308,7 +308,7 @@ describe('fetchAccountByUsername()', () => { describe('when using the accountSearch function', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -373,12 +373,12 @@ describe('fetchAccountByUsername()', () => { describe('followAccount()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); it('should do nothing', async() => { - await store.dispatch(followAccount(1)); + await store.dispatch(followAccount('1')); const actions = store.getActions(); expect(actions).toEqual([]); @@ -386,10 +386,10 @@ describe('followAccount()', () => { }); describe('when logged in', () => { - const id = 1; + const id = '1'; beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -460,12 +460,12 @@ describe('followAccount()', () => { describe('unfollowAccount()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); it('should do nothing', async() => { - await store.dispatch(unfollowAccount(1)); + await store.dispatch(unfollowAccount('1')); const actions = store.getActions(); expect(actions).toEqual([]); @@ -473,10 +473,10 @@ describe('unfollowAccount()', () => { }); describe('when logged in', () => { - const id = 1; + const id = '1'; beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -489,7 +489,7 @@ describe('unfollowAccount()', () => { it('should dispatch the correct actions', async() => { const expectedActions = [ - { type: 'ACCOUNT_UNFOLLOW_REQUEST', id: 1, skipLoading: true }, + { type: 'ACCOUNT_UNFOLLOW_REQUEST', id: '1', skipLoading: true }, { type: 'ACCOUNT_UNFOLLOW_SUCCESS', relationship: { success: true }, @@ -534,11 +534,11 @@ describe('unfollowAccount()', () => { }); describe('blockAccount()', () => { - const id = 1; + const id = '1'; describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -552,7 +552,7 @@ describe('blockAccount()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -601,11 +601,11 @@ describe('blockAccount()', () => { }); describe('unblockAccount()', () => { - const id = 1; + const id = '1'; describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -619,7 +619,7 @@ describe('unblockAccount()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -667,11 +667,11 @@ describe('unblockAccount()', () => { }); describe('muteAccount()', () => { - const id = 1; + const id = '1'; describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -685,7 +685,7 @@ describe('muteAccount()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -734,11 +734,11 @@ describe('muteAccount()', () => { }); describe('unmuteAccount()', () => { - const id = 1; + const id = '1'; describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -752,7 +752,7 @@ describe('unmuteAccount()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -800,11 +800,11 @@ describe('unmuteAccount()', () => { }); describe('subscribeAccount()', () => { - const id = 1; + const id = '1'; describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -818,7 +818,7 @@ describe('subscribeAccount()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -866,11 +866,11 @@ describe('subscribeAccount()', () => { }); describe('unsubscribeAccount()', () => { - const id = 1; + const id = '1'; describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -884,7 +884,7 @@ describe('unsubscribeAccount()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -936,7 +936,7 @@ describe('removeFromFollowers()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -950,7 +950,7 @@ describe('removeFromFollowers()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -1002,7 +1002,7 @@ describe('fetchFollowers()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -1059,7 +1059,7 @@ describe('expandFollowers()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -1073,28 +1073,28 @@ describe('expandFollowers()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('user_lists', { + const state = rootState + .set('user_lists', ReducerRecord({ followers: ImmutableMap({ - [id]: { + [id]: ListRecord({ next: 'next_url', - }, + }), }), - }) + })) .set('me', '123'); store = mockStore(state); }); describe('when the url is null', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('user_lists', { + const state = rootState + .set('user_lists', ReducerRecord({ followers: ImmutableMap({ - [id]: { + [id]: ListRecord({ next: null, - }, + }), }), - }) + })) .set('me', '123'); store = mockStore(state); }); @@ -1160,7 +1160,7 @@ describe('fetchFollowing()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); @@ -1217,7 +1217,7 @@ describe('expandFollowing()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -1231,28 +1231,28 @@ describe('expandFollowing()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('user_lists', { + const state = rootState + .set('user_lists', ReducerRecord({ following: ImmutableMap({ - [id]: { + [id]: ListRecord({ next: 'next_url', - }, + }), }), - }) + })) .set('me', '123'); store = mockStore(state); }); describe('when the url is null', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('user_lists', { + const state = rootState + .set('user_lists', ReducerRecord({ following: ImmutableMap({ - [id]: { + [id]: ListRecord({ next: null, - }, + }), }), - }) + })) .set('me', '123'); store = mockStore(state); }); @@ -1318,7 +1318,7 @@ describe('fetchRelationships()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -1332,15 +1332,15 @@ describe('fetchRelationships()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '123'); store = mockStore(state); }); describe('without newAccountIds', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('relationships', ImmutableMap({ [id]: {} })) + const state = rootState + .set('relationships', ImmutableMap({ [id]: normalizeRelationship({}) })) .set('me', '123'); store = mockStore(state); }); @@ -1355,7 +1355,7 @@ describe('fetchRelationships()', () => { describe('with a successful API request', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('relationships', ImmutableMap({})) .set('me', '123'); store = mockStore(state); @@ -1409,7 +1409,7 @@ describe('fetchRelationships()', () => { describe('fetchFollowRequests()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -1423,14 +1423,14 @@ describe('fetchFollowRequests()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '123'); store = mockStore(state); }); describe('with a successful API request', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('relationships', ImmutableMap({})) .set('me', '123'); store = mockStore(state); @@ -1483,7 +1483,7 @@ describe('fetchFollowRequests()', () => { describe('expandFollowRequests()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -1497,24 +1497,24 @@ describe('expandFollowRequests()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('user_lists', { - follow_requests: { + const state = rootState + .set('user_lists', ReducerRecord({ + follow_requests: ListRecord({ next: 'next_url', - }, - }) + }), + })) .set('me', '123'); store = mockStore(state); }); describe('when the url is null', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) - .set('user_lists', { - follow_requests: { + const state = rootState + .set('user_lists', ReducerRecord({ + follow_requests: ListRecord({ next: null, - }, - }) + }), + })) .set('me', '123'); store = mockStore(state); }); @@ -1579,7 +1579,7 @@ describe('authorizeFollowRequest()', () => { describe('when logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -1593,7 +1593,7 @@ describe('authorizeFollowRequest()', () => { describe('when logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '123'); + const state = rootState.set('me', '123'); store = mockStore(state); }); diff --git a/app/soapbox/actions/__tests__/alerts.test.ts b/app/soapbox/actions/__tests__/alerts.test.ts index f2419893a..5f1f9f4d6 100644 --- a/app/soapbox/actions/__tests__/alerts.test.ts +++ b/app/soapbox/actions/__tests__/alerts.test.ts @@ -1,11 +1,10 @@ import { AxiosError } from 'axios'; -import { mockStore } from 'soapbox/jest/test-helpers'; -import rootReducer from 'soapbox/reducers'; +import { mockStore, rootState } from 'soapbox/jest/test-helpers'; import { dismissAlert, showAlert, showAlertForError } from '../alerts'; -const buildError = (message: string, status: number) => new AxiosError(message, String(status), null, null, { +const buildError = (message: string, status: number) => new AxiosError(message, String(status), undefined, null, { data: { error: message, }, @@ -15,10 +14,10 @@ const buildError = (message: string, status: number) => new AxiosError(mess config: {}, }); -let store; +let store: ReturnType; beforeEach(() => { - const state = rootReducer(undefined, {}); + const state = rootState; store = mockStore(state); }); @@ -28,7 +27,7 @@ describe('dismissAlert()', () => { const expectedActions = [ { type: 'ALERT_DISMISS', alert }, ]; - await store.dispatch(dismissAlert(alert)); + await store.dispatch(dismissAlert(alert as any)); const actions = store.getActions(); expect(actions).toEqual(expectedActions); @@ -70,11 +69,10 @@ describe('showAlert()', () => { it('dispatches the proper actions', async() => { const error = buildError('', 404); - const expectedActions = []; await store.dispatch(showAlertForError(error)); const actions = store.getActions(); - expect(actions).toEqual(expectedActions); + expect(actions).toEqual([]); }); }); @@ -82,11 +80,10 @@ describe('showAlert()', () => { it('dispatches the proper actions', async() => { const error = buildError('', 410); - const expectedActions = []; await store.dispatch(showAlertForError(error)); const actions = store.getActions(); - expect(actions).toEqual(expectedActions); + expect(actions).toEqual([]); }); }); diff --git a/app/soapbox/actions/__tests__/blocks.test.ts b/app/soapbox/actions/__tests__/blocks.test.ts index 2d4832007..8b4c040b3 100644 --- a/app/soapbox/actions/__tests__/blocks.test.ts +++ b/app/soapbox/actions/__tests__/blocks.test.ts @@ -1,8 +1,6 @@ -import { Record as ImmutableRecord } from 'immutable'; - import { __stub } from 'soapbox/api'; -import { mockStore } from 'soapbox/jest/test-helpers'; -import rootReducer from 'soapbox/reducers'; +import { mockStore, rootState } from 'soapbox/jest/test-helpers'; +import { ListRecord, ReducerRecord as UserListsRecord } from 'soapbox/reducers/user_lists'; import { expandBlocks, fetchBlocks } from '../blocks'; @@ -14,11 +12,11 @@ const account = { }; describe('fetchBlocks()', () => { - let store; + let store: ReturnType; describe('if logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -32,7 +30,7 @@ describe('fetchBlocks()', () => { describe('if logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '1234'); + const state = rootState.set('me', '1234'); store = mockStore(state); }); @@ -87,11 +85,11 @@ describe('fetchBlocks()', () => { }); describe('expandBlocks()', () => { - let store; + let store: ReturnType; describe('if logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -105,15 +103,15 @@ describe('expandBlocks()', () => { describe('if logged in', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', '1234'); + const state = rootState.set('me', '1234'); store = mockStore(state); }); describe('without a url', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '1234') - .set('user_lists', ImmutableRecord({ blocks: { next: null } })()); + .set('user_lists', UserListsRecord({ blocks: ListRecord({ next: null }) })); store = mockStore(state); }); @@ -127,9 +125,9 @@ describe('expandBlocks()', () => { describe('with a url', () => { beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '1234') - .set('user_lists', ImmutableRecord({ blocks: { next: 'example' } })()); + .set('user_lists', UserListsRecord({ blocks: ListRecord({ next: 'example' }) })); store = mockStore(state); }); diff --git a/app/soapbox/actions/__tests__/carousels.test.ts b/app/soapbox/actions/__tests__/carousels.test.ts index 0953b8276..44e4ff0c0 100644 --- a/app/soapbox/actions/__tests__/carousels.test.ts +++ b/app/soapbox/actions/__tests__/carousels.test.ts @@ -4,14 +4,14 @@ import { mockStore, rootState } from 'soapbox/jest/test-helpers'; import { fetchCarouselAvatars } from '../carousels'; describe('fetchCarouselAvatars()', () => { - let store; + let store: ReturnType; beforeEach(() => { store = mockStore(rootState); }); describe('with a successful API request', () => { - let avatars; + let avatars: Record[]; beforeEach(() => { avatars = [ diff --git a/app/soapbox/actions/__tests__/compose.test.ts b/app/soapbox/actions/__tests__/compose.test.ts index 0dd6fc309..6a9ac6e43 100644 --- a/app/soapbox/actions/__tests__/compose.test.ts +++ b/app/soapbox/actions/__tests__/compose.test.ts @@ -1,28 +1,29 @@ -import { fromJS } from 'immutable'; +import { Map as ImmutableMap } from 'immutable'; -import { mockStore } from 'soapbox/jest/test-helpers'; +import { mockStore, rootState } from 'soapbox/jest/test-helpers'; import { InstanceRecord } from 'soapbox/normalizers'; -import rootReducer from 'soapbox/reducers'; import { uploadCompose } from '../compose'; +import type { IntlShape } from 'react-intl'; + describe('uploadCompose()', () => { describe('with images', () => { - let files, store; + let files: FileList, store: ReturnType; beforeEach(() => { const instance = InstanceRecord({ - configuration: fromJS({ - statuses: { + configuration: ImmutableMap({ + statuses: ImmutableMap({ max_media_attachments: 4, - }, - media_attachments: { + }), + media_attachments: ImmutableMap({ image_size_limit: 10, - }, + }), }), }); - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '1234') .set('instance', instance); @@ -32,13 +33,13 @@ describe('uploadCompose()', () => { name: 'Image', size: 15, type: 'image/png', - }]; + }] as unknown as FileList; }); it('creates an alert if exceeds max size', async() => { const mockIntl = { formatMessage: jest.fn().mockReturnValue('Image exceeds the current file size limit (10 Bytes)'), - }; + } as unknown as IntlShape; const expectedActions = [ { type: 'COMPOSE_UPLOAD_REQUEST', skipLoading: true }, @@ -60,21 +61,21 @@ describe('uploadCompose()', () => { }); describe('with videos', () => { - let files, store; + let files: FileList, store: ReturnType; beforeEach(() => { const instance = InstanceRecord({ - configuration: fromJS({ - statuses: { + configuration: ImmutableMap({ + statuses: ImmutableMap({ max_media_attachments: 4, - }, - media_attachments: { + }), + media_attachments: ImmutableMap({ video_size_limit: 10, - }, + }), }), }); - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '1234') .set('instance', instance); @@ -84,13 +85,13 @@ describe('uploadCompose()', () => { name: 'Video', size: 15, type: 'video/mp4', - }]; + }] as unknown as FileList; }); it('creates an alert if exceeds max size', async() => { const mockIntl = { formatMessage: jest.fn().mockReturnValue('Video exceeds the current file size limit (10 Bytes)'), - }; + } as unknown as IntlShape; const expectedActions = [ { type: 'COMPOSE_UPLOAD_REQUEST', skipLoading: true }, diff --git a/app/soapbox/actions/__tests__/onboarding.test.ts b/app/soapbox/actions/__tests__/onboarding.test.ts index cdd268ed5..f786c7f90 100644 --- a/app/soapbox/actions/__tests__/onboarding.test.ts +++ b/app/soapbox/actions/__tests__/onboarding.test.ts @@ -1,5 +1,4 @@ -import { mockStore, mockWindowProperty } from 'soapbox/jest/test-helpers'; -import rootReducer from 'soapbox/reducers'; +import { mockStore, mockWindowProperty, rootState } from 'soapbox/jest/test-helpers'; import { checkOnboardingStatus, startOnboarding, endOnboarding } from '../onboarding'; @@ -17,7 +16,7 @@ describe('checkOnboarding()', () => { it('does nothing if localStorage item is not set', async() => { mockGetItem = jest.fn().mockReturnValue(null); - const state = rootReducer(undefined, { onboarding: { needsOnboarding: false } }); + const state = rootState.setIn(['onboarding', 'needsOnboarding'], false); const store = mockStore(state); await store.dispatch(checkOnboardingStatus()); @@ -30,7 +29,7 @@ describe('checkOnboarding()', () => { it('does nothing if localStorage item is invalid', async() => { mockGetItem = jest.fn().mockReturnValue('invalid'); - const state = rootReducer(undefined, { onboarding: { needsOnboarding: false } }); + const state = rootState.setIn(['onboarding', 'needsOnboarding'], false); const store = mockStore(state); await store.dispatch(checkOnboardingStatus()); @@ -43,7 +42,7 @@ describe('checkOnboarding()', () => { it('dispatches the correct action', async() => { mockGetItem = jest.fn().mockReturnValue('1'); - const state = rootReducer(undefined, { onboarding: { needsOnboarding: false } }); + const state = rootState.setIn(['onboarding', 'needsOnboarding'], false); const store = mockStore(state); await store.dispatch(checkOnboardingStatus()); @@ -66,7 +65,7 @@ describe('startOnboarding()', () => { }); it('dispatches the correct action', async() => { - const state = rootReducer(undefined, { onboarding: { needsOnboarding: false } }); + const state = rootState.setIn(['onboarding', 'needsOnboarding'], false); const store = mockStore(state); await store.dispatch(startOnboarding()); @@ -89,7 +88,7 @@ describe('endOnboarding()', () => { }); it('dispatches the correct action', async() => { - const state = rootReducer(undefined, { onboarding: { needsOnboarding: false } }); + const state = rootState.setIn(['onboarding', 'needsOnboarding'], false); const store = mockStore(state); await store.dispatch(endOnboarding()); diff --git a/app/soapbox/actions/__tests__/statuses.test.ts b/app/soapbox/actions/__tests__/statuses.test.ts index b206f17b9..18cbc173b 100644 --- a/app/soapbox/actions/__tests__/statuses.test.ts +++ b/app/soapbox/actions/__tests__/statuses.test.ts @@ -4,7 +4,6 @@ import { STATUSES_IMPORT } from 'soapbox/actions/importer'; import { __stub } from 'soapbox/api'; import { mockStore, rootState } from 'soapbox/jest/test-helpers'; import { normalizeStatus } from 'soapbox/normalizers/status'; -import rootReducer from 'soapbox/reducers'; import { deleteStatus, fetchContext } from '../statuses'; @@ -19,7 +18,7 @@ describe('fetchContext()', () => { const store = mockStore(rootState); - store.dispatch(fetchContext('017ed505-5926-392f-256a-f86d5075df70')).then(context => { + store.dispatch(fetchContext('017ed505-5926-392f-256a-f86d5075df70')).then(() => { const actions = store.getActions(); expect(actions[3].type).toEqual(STATUSES_IMPORT); @@ -31,11 +30,11 @@ describe('fetchContext()', () => { }); describe('deleteStatus()', () => { - let store; + let store: ReturnType; describe('if logged out', () => { beforeEach(() => { - const state = rootReducer(undefined, {}).set('me', null); + const state = rootState.set('me', null); store = mockStore(state); }); @@ -54,16 +53,16 @@ describe('deleteStatus()', () => { }); beforeEach(() => { - const state = rootReducer(undefined, {}) + const state = rootState .set('me', '1234') .set('statuses', fromJS({ [statusId]: cachedStatus, - })); + }) as any); store = mockStore(state); }); describe('with a successful API request', () => { - let status; + let status: any; beforeEach(() => { status = require('soapbox/__fixtures__/pleroma-status-deleted.json'); diff --git a/app/soapbox/components/__tests__/account.test.tsx b/app/soapbox/components/__tests__/account.test.tsx index e7af7b8f0..7f1458349 100644 --- a/app/soapbox/components/__tests__/account.test.tsx +++ b/app/soapbox/components/__tests__/account.test.tsx @@ -5,6 +5,8 @@ import { render, screen } from '../../jest/test-helpers'; import { normalizeAccount } from '../../normalizers'; import Account from '../account'; +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + describe('', () => { it('renders account name and username', () => { const account = normalizeAccount({ @@ -12,7 +14,7 @@ describe('', () => { acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - }); + }) as ReducerAccount; const store = { accounts: ImmutableMap({ @@ -20,7 +22,7 @@ describe('', () => { }), }; - render(, null, store); + render(, undefined, store); expect(screen.getByTestId('account')).toHaveTextContent('Justin L'); expect(screen.getByTestId('account')).toHaveTextContent(/justin-username/i); }); @@ -33,7 +35,7 @@ describe('', () => { display_name: 'Justin L', avatar: 'test.jpg', verified: true, - }); + }) as ReducerAccount; const store = { accounts: ImmutableMap({ @@ -41,7 +43,7 @@ describe('', () => { }), }; - render(, null, store); + render(, undefined, store); expect(screen.getByTestId('verified-badge')).toBeInTheDocument(); }); @@ -52,7 +54,7 @@ describe('', () => { display_name: 'Justin L', avatar: 'test.jpg', verified: false, - }); + }) as ReducerAccount; const store = { accounts: ImmutableMap({ @@ -60,7 +62,7 @@ describe('', () => { }), }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('verified-badge')).toHaveLength(0); }); }); diff --git a/app/soapbox/components/__tests__/avatar.test.tsx b/app/soapbox/components/__tests__/avatar.test.tsx index 55abca520..56f592925 100644 --- a/app/soapbox/components/__tests__/avatar.test.tsx +++ b/app/soapbox/components/__tests__/avatar.test.tsx @@ -5,6 +5,8 @@ import { normalizeAccount } from 'soapbox/normalizers'; import { render, screen } from '../../jest/test-helpers'; import Avatar from '../avatar'; +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + describe('', () => { const account = normalizeAccount({ username: 'alice', @@ -12,7 +14,7 @@ describe('', () => { display_name: 'Alice', avatar: '/animated/alice.gif', avatar_static: '/static/alice.jpg', - }); + }) as ReducerAccount; const size = 100; diff --git a/app/soapbox/components/__tests__/avatar_overlay.test.tsx b/app/soapbox/components/__tests__/avatar_overlay.test.tsx index b62d4eef8..105828556 100644 --- a/app/soapbox/components/__tests__/avatar_overlay.test.tsx +++ b/app/soapbox/components/__tests__/avatar_overlay.test.tsx @@ -1,25 +1,28 @@ -import { fromJS } from 'immutable'; import React from 'react'; +import { normalizeAccount } from 'soapbox/normalizers'; + import { render, screen } from '../../jest/test-helpers'; import AvatarOverlay from '../avatar_overlay'; +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + describe(' { - const account = fromJS({ + const account = normalizeAccount({ username: 'alice', acct: 'alice', display_name: 'Alice', avatar: '/animated/alice.gif', avatar_static: '/static/alice.jpg', - }); + }) as ReducerAccount; - const friend = fromJS({ + const friend = normalizeAccount({ username: 'eve', acct: 'eve@blackhat.lair', display_name: 'Evelyn', avatar: '/animated/eve.gif', avatar_static: '/static/eve.jpg', - }); + }) as ReducerAccount; it('renders a overlay avatar', () => { render(); diff --git a/app/soapbox/components/__tests__/display_name.test.tsx b/app/soapbox/components/__tests__/display_name.test.tsx index 6d0a05ed5..4c1c1bd23 100644 --- a/app/soapbox/components/__tests__/display_name.test.tsx +++ b/app/soapbox/components/__tests__/display_name.test.tsx @@ -5,9 +5,11 @@ import { normalizeAccount } from 'soapbox/normalizers'; import { render, screen } from '../../jest/test-helpers'; import DisplayName from '../display-name'; +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + describe('', () => { it('renders display name + account name', () => { - const account = normalizeAccount({ acct: 'bar@baz' }); + const account = normalizeAccount({ acct: 'bar@baz' }) as ReducerAccount; render(); expect(screen.getByTestId('display-name')).toHaveTextContent('bar@baz'); diff --git a/app/soapbox/components/__tests__/emoji_selector.test.tsx b/app/soapbox/components/__tests__/emoji_selector.test.tsx index 891e3e61c..c680d156e 100644 --- a/app/soapbox/components/__tests__/emoji_selector.test.tsx +++ b/app/soapbox/components/__tests__/emoji_selector.test.tsx @@ -6,6 +6,7 @@ import EmojiSelector from '../emoji_selector'; describe('', () => { it('renders correctly', () => { const children = ; + // @ts-ignore children.__proto__.addEventListener = () => {}; render(children); diff --git a/app/soapbox/components/__tests__/quoted-status.test.tsx b/app/soapbox/components/__tests__/quoted-status.test.tsx index 208a913b2..d57b59b30 100644 --- a/app/soapbox/components/__tests__/quoted-status.test.tsx +++ b/app/soapbox/components/__tests__/quoted-status.test.tsx @@ -4,6 +4,8 @@ import { render, screen, rootState } from '../../jest/test-helpers'; import { normalizeStatus, normalizeAccount } from '../../normalizers'; import QuotedStatus from '../quoted-status'; +import type { ReducerStatus } from 'soapbox/reducers/statuses'; + describe('', () => { it('renders content', () => { const account = normalizeAccount({ @@ -16,11 +18,11 @@ describe('', () => { account, content: 'hello world', contentHtml: 'hello world', - }); + }) as ReducerStatus; - const state = rootState.setIn(['accounts', '1', account]); + const state = rootState.setIn(['accounts', '1'], account); - render(, null, state); + render(, undefined, state); screen.getByText(/hello world/i); expect(screen.getByTestId('quoted-status')).toHaveTextContent(/hello world/i); }); diff --git a/app/soapbox/components/__tests__/scroll-top-button.test.tsx b/app/soapbox/components/__tests__/scroll-top-button.test.tsx index 89518b977..76e6b7c1c 100644 --- a/app/soapbox/components/__tests__/scroll-top-button.test.tsx +++ b/app/soapbox/components/__tests__/scroll-top-button.test.tsx @@ -28,7 +28,7 @@ describe('', () => { message={messages.queue} />, ); - expect(screen.getByText('Click to see 1 new post', { hidden: true })).toBeInTheDocument(); + expect(screen.getByText('Click to see 1 new post')).toBeInTheDocument(); render( ', () => { message={messages.queue} />, ); - expect(screen.getByText('Click to see 9999999 new posts', { hidden: true })).toBeInTheDocument(); + expect(screen.getByText('Click to see 9999999 new posts')).toBeInTheDocument(); }); }); diff --git a/app/soapbox/components/polls/__tests__/poll-footer.test.tsx b/app/soapbox/components/polls/__tests__/poll-footer.test.tsx index 7265f7e1c..29c841a0a 100644 --- a/app/soapbox/components/polls/__tests__/poll-footer.test.tsx +++ b/app/soapbox/components/polls/__tests__/poll-footer.test.tsx @@ -6,7 +6,7 @@ import { Provider } from 'react-redux'; import { __stub } from 'soapbox/api'; import { normalizePoll } from 'soapbox/normalizers/poll'; -import { mockStore, render, rootReducer, screen } from '../../../jest/test-helpers'; +import { mockStore, render, screen, rootState } from '../../../jest/test-helpers'; import PollFooter from '../poll-footer'; let poll = normalizePoll({ @@ -36,7 +36,7 @@ describe('', () => { }); const user = userEvent.setup(); - const store = mockStore(rootReducer(undefined, {})); + const store = mockStore(rootState); render( diff --git a/app/soapbox/components/status.tsx b/app/soapbox/components/status.tsx index 200b2de10..90d7e13df 100644 --- a/app/soapbox/components/status.tsx +++ b/app/soapbox/components/status.tsx @@ -84,8 +84,6 @@ interface IStatus extends RouteComponentProps { onMoveDown: (statusId: string, featured?: boolean) => void, getScrollPosition?: () => ScrollPosition | undefined, updateScrollBottom?: (bottom: number) => void, - cacheMediaWidth: () => void, - cachedMediaWidth: number, group: ImmutableMap, displayMedia: string, allowedEmoji: ImmutableList, diff --git a/app/soapbox/components/ui/datepicker/__tests__/datepicker.test.tsx b/app/soapbox/components/ui/datepicker/__tests__/datepicker.test.tsx index c4f94c89f..f2db8981c 100644 --- a/app/soapbox/components/ui/datepicker/__tests__/datepicker.test.tsx +++ b/app/soapbox/components/ui/datepicker/__tests__/datepicker.test.tsx @@ -30,7 +30,7 @@ describe('', () => { ); let daySelect: HTMLElement; - daySelect = document.querySelector('[data-testid="datepicker-day"]'); + daySelect = document.querySelector('[data-testid="datepicker-day"]') as HTMLElement; expect(queryAllByRole(daySelect, 'option')).toHaveLength(29); await userEvent.selectOptions( diff --git a/app/soapbox/features/auth_login/components/__tests__/captcha.test.tsx b/app/soapbox/features/auth_login/components/__tests__/captcha.test.tsx index d48071b0c..bb09d1dba 100644 --- a/app/soapbox/features/auth_login/components/__tests__/captcha.test.tsx +++ b/app/soapbox/features/auth_login/components/__tests__/captcha.test.tsx @@ -6,7 +6,7 @@ import CaptchaField, { NativeCaptchaField } from '../captcha'; describe('', () => { it('renders null by default', () => { - render(); + render(); expect(screen.queryAllByRole('textbox')).toHaveLength(0); }); @@ -24,7 +24,9 @@ describe('', () => { render( {}} // eslint-disable-line react/jsx-no-bind + onChange={() => {}} + onClick={() => {}} + value='' />, ); diff --git a/app/soapbox/features/auth_login/components/__tests__/login_form.test.tsx b/app/soapbox/features/auth_login/components/__tests__/login_form.test.tsx index ac1c52930..b46acf31a 100644 --- a/app/soapbox/features/auth_login/components/__tests__/login_form.test.tsx +++ b/app/soapbox/features/auth_login/components/__tests__/login_form.test.tsx @@ -13,7 +13,7 @@ describe('', () => { }), }; - render(, null, store); + render(, undefined, store); expect(screen.getByRole('heading')).toHaveTextContent(/sign in/i); }); @@ -26,7 +26,7 @@ describe('', () => { }), }; - render(, null, store); + render(, undefined, store); expect(screen.getByRole('heading')).toHaveTextContent(/sign in/i); }); diff --git a/app/soapbox/features/auth_login/components/__tests__/login_page.test.tsx b/app/soapbox/features/auth_login/components/__tests__/login_page.test.tsx index 85daf3e4e..50f94b285 100644 --- a/app/soapbox/features/auth_login/components/__tests__/login_page.test.tsx +++ b/app/soapbox/features/auth_login/components/__tests__/login_page.test.tsx @@ -12,7 +12,7 @@ describe('', () => { }), }; - render(, null, store); + render(, undefined, store); expect(screen.getByRole('heading')).toHaveTextContent('Sign In'); }); diff --git a/app/soapbox/features/emoji/__tests__/emoji_index.test.ts b/app/soapbox/features/emoji/__tests__/emoji_index.test.ts index 99f46e3b3..78698981a 100644 --- a/app/soapbox/features/emoji/__tests__/emoji_index.test.ts +++ b/app/soapbox/features/emoji/__tests__/emoji_index.test.ts @@ -1,9 +1,10 @@ +// @ts-ignore import { emojiIndex } from 'emoji-mart'; import pick from 'lodash/pick'; import { search } from '../emoji_mart_search_light'; -const trimEmojis = emoji => pick(emoji, ['id', 'unified', 'native', 'custom']); +const trimEmojis = (emoji: any) => pick(emoji, ['id', 'unified', 'native', 'custom']); describe('emoji_index', () => { it('should give same result for emoji_index_light and emoji-mart', () => { @@ -46,7 +47,7 @@ describe('emoji_index', () => { }); it('can include/exclude categories', () => { - expect(search('flag', { include: ['people'] })).toEqual([]); + expect(search('flag', { include: ['people'] } as any)).toEqual([]); expect(emojiIndex.search('flag', { include: ['people'] })).toEqual([]); }); @@ -63,9 +64,8 @@ describe('emoji_index', () => { custom: true, }, ]; - search('', { custom }); + search('', { custom } as any); emojiIndex.search('', { custom }); - const expected = []; const lightExpected = [ { id: 'mastodon', @@ -73,7 +73,7 @@ describe('emoji_index', () => { }, ]; expect(search('masto').map(trimEmojis)).toEqual(lightExpected); - expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected); + expect(emojiIndex.search('masto').map(trimEmojis)).toEqual([]); }); it('(different behavior from emoji-mart) erases custom emoji if another is passed', () => { @@ -89,11 +89,10 @@ describe('emoji_index', () => { custom: true, }, ]; - search('', { custom }); + search('', { custom } as any); emojiIndex.search('', { custom }); - const expected = []; - expect(search('masto', { custom: [] }).map(trimEmojis)).toEqual(expected); - expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected); + expect(search('masto', { custom: [] } as any).map(trimEmojis)).toEqual([]); + expect(emojiIndex.search('masto').map(trimEmojis)).toEqual([]); }); it('handles custom emoji', () => { @@ -109,7 +108,7 @@ describe('emoji_index', () => { custom: true, }, ]; - search('', { custom }); + search('', { custom } as any); emojiIndex.search('', { custom }); const expected = [ { @@ -117,15 +116,15 @@ describe('emoji_index', () => { custom: true, }, ]; - expect(search('masto', { custom }).map(trimEmojis)).toEqual(expected); + expect(search('masto', { custom } as any).map(trimEmojis)).toEqual(expected); expect(emojiIndex.search('masto', { custom }).map(trimEmojis)).toEqual(expected); }); it('should filter only emojis we care about, exclude pineapple', () => { - const emojisToShowFilter = emoji => emoji.unified !== '1F34D'; - expect(search('apple', { emojisToShowFilter }).map((obj) => obj.id)) + const emojisToShowFilter = (emoji: any) => emoji.unified !== '1F34D'; + expect(search('apple', { emojisToShowFilter } as any).map((obj: any) => obj.id)) .not.toContain('pineapple'); - expect(emojiIndex.search('apple', { emojisToShowFilter }).map((obj) => obj.id)) + expect(emojiIndex.search('apple', { emojisToShowFilter }).map((obj: any) => obj.id)) .not.toContain('pineapple'); }); diff --git a/app/soapbox/features/feed-filtering/__tests__/feed-carousel.test.tsx b/app/soapbox/features/feed-filtering/__tests__/feed-carousel.test.tsx index 096682fa0..eb84e7ad0 100644 --- a/app/soapbox/features/feed-filtering/__tests__/feed-carousel.test.tsx +++ b/app/soapbox/features/feed-filtering/__tests__/feed-carousel.test.tsx @@ -18,7 +18,7 @@ jest.mock('../../../hooks/useDimensions', () => ({ }; describe('', () => { - let store; + let store: any; describe('with "feedUserFiltering" disabled', () => { beforeEach(() => { @@ -35,7 +35,7 @@ describe('', () => { }); it('should render nothing', () => { - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('feed-carousel')).toHaveLength(0); }); @@ -56,7 +56,7 @@ describe('', () => { }); it('should render the Carousel', () => { - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('feed-carousel')).toHaveLength(1); }); @@ -70,7 +70,7 @@ describe('', () => { }); it('renders the error message', () => { - render(, null, store); + render(, undefined, store); expect(screen.getByTestId('feed-carousel-error')).toBeInTheDocument(); }); @@ -110,7 +110,7 @@ describe('', () => { it('should render the correct prev/next buttons', async() => { const user = userEvent.setup(); - render(, null, store); + render(, undefined, store); await waitFor(() => { expect(screen.getByTestId('next-page')).toBeInTheDocument(); diff --git a/app/soapbox/features/landing_page/__tests__/landing_page.test.tsx b/app/soapbox/features/landing_page/__tests__/landing_page.test.tsx index 02b9a4fe0..a52dbd975 100644 --- a/app/soapbox/features/landing_page/__tests__/landing_page.test.tsx +++ b/app/soapbox/features/landing_page/__tests__/landing_page.test.tsx @@ -17,7 +17,7 @@ describe('', () => { }, }); - render(, null, state); + render(, undefined, state); expect(screen.queryByTestId('registrations-open')).toBeInTheDocument(); expect(screen.queryByTestId('registrations-closed')).not.toBeInTheDocument(); @@ -34,7 +34,7 @@ describe('', () => { }, }); - render(, null, state); + render(, undefined, state); expect(screen.queryByTestId('registrations-closed')).toBeInTheDocument(); expect(screen.queryByTestId('registrations-open')).not.toBeInTheDocument(); @@ -59,7 +59,7 @@ describe('', () => { }, }], rootReducer); - render(, null, state); + render(, undefined, state); expect(screen.queryByTestId('registrations-pepe')).toBeInTheDocument(); expect(screen.queryByTestId('registrations-open')).not.toBeInTheDocument(); @@ -81,7 +81,7 @@ describe('', () => { }, }], rootReducer); - render(, null, state); + render(, undefined, state); expect(screen.queryByTestId('registrations-closed')).toBeInTheDocument(); expect(screen.queryByTestId('registrations-pepe')).not.toBeInTheDocument(); diff --git a/app/soapbox/features/notifications/components/__tests__/notification.test.tsx b/app/soapbox/features/notifications/components/__tests__/notification.test.tsx index 14c43f50c..eacca0f99 100644 --- a/app/soapbox/features/notifications/components/__tests__/notification.test.tsx +++ b/app/soapbox/features/notifications/components/__tests__/notification.test.tsx @@ -33,10 +33,12 @@ describe('', () => { describe('grouped notifications', () => { it('renders a grouped follow notification for more than 2', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); - const groupedNotification = { ...notification.toJS(), total_count: 5 }; + const { notification, state } = normalize({ + ...require('soapbox/__fixtures__/notification-follow.json'), + total_count: 5, + }); - render(, undefined, state); + render(, undefined, state); expect(screen.getByTestId('notification')).toBeInTheDocument(); expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc'); @@ -44,10 +46,12 @@ describe('', () => { }); it('renders a grouped follow notification for 1', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); - const groupedNotification = { ...notification.toJS(), total_count: 2 }; + const { notification, state } = normalize({ + ...require('soapbox/__fixtures__/notification-follow.json'), + total_count: 2, + }); - render(, undefined, state); + render(, undefined, state); expect(screen.getByTestId('notification')).toBeInTheDocument(); expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc'); diff --git a/app/soapbox/features/notifications/components/notification.tsx b/app/soapbox/features/notifications/components/notification.tsx index dda887919..4b67e5645 100644 --- a/app/soapbox/features/notifications/components/notification.tsx +++ b/app/soapbox/features/notifications/components/notification.tsx @@ -128,16 +128,14 @@ const buildMessage = ( interface INotificaton { hidden?: boolean, notification: NotificationEntity, - onMoveUp: (notificationId: string) => void, - onMoveDown: (notificationId: string) => void, - onMention: (account: Account) => void, - onFavourite: (status: Status) => void, - onReblog: (status: Status, e?: KeyboardEvent) => void, - onToggleHidden: (status: Status) => void, + onMoveUp?: (notificationId: string) => void, + onMoveDown?: (notificationId: string) => void, + onMention?: (account: Account) => void, + onFavourite?: (status: Status) => void, + onReblog?: (status: Status, e?: KeyboardEvent) => void, + onToggleHidden?: (status: Status) => void, getScrollPosition?: () => ScrollPosition | undefined, updateScrollBottom?: (bottom: number) => void, - cacheMediaWidth: () => void, - cachedMediaWidth: number, siteTitle?: string, } @@ -180,35 +178,39 @@ const Notification: React.FC = (props) => { const handleMention = (e?: KeyboardEvent) => { e?.preventDefault(); - if (account && typeof account === 'object') { + if (props.onMention && account && typeof account === 'object') { props.onMention(account); } }; const handleHotkeyFavourite = (e?: KeyboardEvent) => { - if (status && typeof status === 'object') { + if (props.onFavourite && status && typeof status === 'object') { props.onFavourite(status); } }; const handleHotkeyBoost = (e?: KeyboardEvent) => { - if (status && typeof status === 'object') { + if (props.onReblog && status && typeof status === 'object') { props.onReblog(status, e); } }; const handleHotkeyToggleHidden = (e?: KeyboardEvent) => { - if (status && typeof status === 'object') { + if (props.onToggleHidden && status && typeof status === 'object') { props.onToggleHidden(status); } }; const handleMoveUp = () => { - onMoveUp(notification.id); + if (onMoveUp) { + onMoveUp(notification.id); + } }; const handleMoveDown = () => { - onMoveDown(notification.id); + if (onMoveDown) { + onMoveDown(notification.id); + } }; const renderIcon = (): React.ReactNode => { @@ -268,8 +270,6 @@ const Notification: React.FC = (props) => { contextType='notifications' getScrollPosition={props.getScrollPosition} updateScrollBottom={props.updateScrollBottom} - cachedMediaWidth={props.cachedMediaWidth} - cacheMediaWidth={props.cacheMediaWidth} /> ) : null; default: diff --git a/app/soapbox/features/ui/__tests__/index.test.tsx b/app/soapbox/features/ui/__tests__/index.test.tsx index 5a3164996..c28c21589 100644 --- a/app/soapbox/features/ui/__tests__/index.test.tsx +++ b/app/soapbox/features/ui/__tests__/index.test.tsx @@ -15,12 +15,12 @@ const TestableComponent = () => ( Sign in {/* WrappedRount will redirect to /login for logged out users... which will resolve to the route above! */} - + null} /> ); describe('', () => { - let store; + let store: any; beforeEach(() => { store = { diff --git a/app/soapbox/features/ui/components/__tests__/compose-button.test.tsx b/app/soapbox/features/ui/components/__tests__/compose-button.test.tsx index 86b9b84bd..c98b7aa50 100644 --- a/app/soapbox/features/ui/components/__tests__/compose-button.test.tsx +++ b/app/soapbox/features/ui/components/__tests__/compose-button.test.tsx @@ -1,17 +1,15 @@ import { fireEvent, render, screen } from '@testing-library/react'; -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { IntlProvider } from 'react-intl'; import { Provider } from 'react-redux'; import '@testing-library/jest-dom'; import { MODAL_OPEN } from 'soapbox/actions/modals'; -import { mockStore } from 'soapbox/jest/test-helpers'; -import rootReducer from 'soapbox/reducers'; +import { mockStore, rootState } from 'soapbox/jest/test-helpers'; import ComposeButton from '../compose-button'; -const store = mockStore(rootReducer(ImmutableMap(), {})); +const store = mockStore(rootState); const renderComposeButton = () => { render( diff --git a/app/soapbox/features/ui/components/__tests__/cta-banner.test.tsx b/app/soapbox/features/ui/components/__tests__/cta-banner.test.tsx index cc4c118e6..dbda24b55 100644 --- a/app/soapbox/features/ui/components/__tests__/cta-banner.test.tsx +++ b/app/soapbox/features/ui/components/__tests__/cta-banner.test.tsx @@ -14,7 +14,7 @@ describe('', () => { it('renders empty', () => { const store = { me: true }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0); }); }); @@ -23,7 +23,7 @@ describe('', () => { it('renders empty', () => { const store = { soapbox: ImmutableMap({ singleUserMode: true }) }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0); }); }); diff --git a/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx b/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx index 3dea16d97..d0ec92f96 100644 --- a/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx +++ b/app/soapbox/features/ui/components/__tests__/subscribe-button.test.tsx @@ -5,7 +5,9 @@ import { render, screen } from '../../../../jest/test-helpers'; import { normalizeAccount, normalizeRelationship } from '../../../../normalizers'; import SubscribeButton from '../subscription-button'; -let account = { +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + +const justin = { id: '1', acct: 'justin-username', display_name: 'Justin L', @@ -13,13 +15,13 @@ let account = { }; describe('', () => { - let store; + let store: any; describe('with "accountNotifies" disabled', () => { it('renders nothing', () => { - account = normalizeAccount({ ...account, relationship: normalizeRelationship({ following: true }) }); + const account = normalizeAccount({ ...justin, relationship: normalizeRelationship({ following: true }) }) as ReducerAccount; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('icon-button')).toHaveLength(0); }); }); diff --git a/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx b/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx index 03ae48553..487a84bfb 100644 --- a/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx +++ b/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx @@ -23,7 +23,7 @@ describe('', () => { })(), }; - render(, null, store); + render(, undefined, store); expect(screen.getByTestId('hashtag')).toHaveTextContent(/hashtag 1/i); expect(screen.getByTestId('hashtag')).toHaveTextContent(/180 people talking/i); expect(screen.getByTestId('sparklines')).toBeInTheDocument(); @@ -46,7 +46,7 @@ describe('', () => { })(), }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('hashtag')).toHaveLength(2); }); @@ -67,7 +67,7 @@ describe('', () => { })(), }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('hashtag')).toHaveLength(1); }); @@ -79,7 +79,7 @@ describe('', () => { })(), }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('hashtag')).toHaveLength(0); }); }); diff --git a/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx b/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx index 56e4f8422..84a645514 100644 --- a/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx +++ b/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx @@ -24,7 +24,7 @@ describe('', () => { }, }; - render(, null, store); + render(, undefined, store); expect(screen.getByTestId('account')).toHaveTextContent(/my name/i); }); @@ -58,7 +58,7 @@ describe('', () => { }, }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('account')).toHaveLength(2); }); @@ -92,7 +92,7 @@ describe('', () => { }, }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('account')).toHaveLength(1); }); @@ -117,7 +117,7 @@ describe('', () => { }, }; - render(, null, store); + render(, undefined, store); expect(screen.queryAllByTestId('account')).toHaveLength(0); }); }); diff --git a/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx b/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx index 1fe62d7f2..a2dee08b5 100644 --- a/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx +++ b/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx @@ -9,7 +9,7 @@ import { normalizeAccount, normalizeStatus } from '../../../../../../normalizers import ReportModal from '../report-modal'; describe('', () => { - let store; + let store: any; beforeEach(() => { const rules = require('soapbox/__fixtures__/rules.json'); diff --git a/app/soapbox/features/verification/__tests__/index.test.tsx b/app/soapbox/features/verification/__tests__/index.test.tsx index 32182f515..e24aee442 100644 --- a/app/soapbox/features/verification/__tests__/index.test.tsx +++ b/app/soapbox/features/verification/__tests__/index.test.tsx @@ -14,7 +14,7 @@ const TestableComponent = () => ( ); -const renderComponent = (store) => render( +const renderComponent = (store: any) => render( , {}, store, @@ -22,7 +22,7 @@ const renderComponent = (store) => render( ); describe('', () => { - let store; + let store: any; beforeEach(() => { store = { diff --git a/app/soapbox/features/verification/steps/__tests__/age-verification.test.tsx b/app/soapbox/features/verification/steps/__tests__/age-verification.test.tsx index 7dd835313..f310a0741 100644 --- a/app/soapbox/features/verification/steps/__tests__/age-verification.test.tsx +++ b/app/soapbox/features/verification/steps/__tests__/age-verification.test.tsx @@ -8,7 +8,7 @@ import { fireEvent, render, screen } from 'soapbox/jest/test-helpers'; import AgeVerification from '../age-verification'; describe('', () => { - let store; + let store: any; beforeEach(() => { store = { diff --git a/app/soapbox/hooks/__tests__/useDimensions.test.ts b/app/soapbox/hooks/__tests__/useDimensions.test.ts index c437f1394..0adee42e4 100644 --- a/app/soapbox/hooks/__tests__/useDimensions.test.ts +++ b/app/soapbox/hooks/__tests__/useDimensions.test.ts @@ -6,7 +6,7 @@ let listener: ((rect: any) => void) | undefined = undefined; (window as any).ResizeObserver = class ResizeObserver { - constructor(ls) { + constructor(ls: any) { listener = ls; } @@ -63,7 +63,7 @@ describe('useDimensions()', () => { disconnect() { disconnect(); } - + }; const { result, unmount } = renderHook(() => useDimensions()); diff --git a/app/soapbox/jest/test-helpers.tsx b/app/soapbox/jest/test-helpers.tsx index 459049b52..657919b5a 100644 --- a/app/soapbox/jest/test-helpers.tsx +++ b/app/soapbox/jest/test-helpers.tsx @@ -1,3 +1,4 @@ +import { configureMockStore } from '@jedmao/redux-mock-store'; import { render, RenderOptions } from '@testing-library/react'; import { merge } from 'immutable'; import React, { FC, ReactElement } from 'react'; @@ -5,18 +6,19 @@ import { IntlProvider } from 'react-intl'; import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router-dom'; import { Action, applyMiddleware, createStore } from 'redux'; -import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; import '@testing-library/jest-dom'; import NotificationsContainer from '../features/ui/containers/notifications_container'; import { default as rootReducer } from '../reducers'; +import type { AnyAction } from 'redux'; +import type { AppDispatch } from 'soapbox/store'; + // Mock Redux // https://redux.js.org/recipes/writing-tests/ -const middlewares = [thunk]; -const mockStore = configureMockStore(middlewares); -let rootState = rootReducer(undefined, {} as Action); +const rootState = rootReducer(undefined, {} as Action); +const mockStore = configureMockStore([thunk]); /** Apply actions to the state, one at a time. */ const applyActions = (state: any, actions: any, reducer: any) => { @@ -26,13 +28,14 @@ const applyActions = (state: any, actions: any, reducer: any) => { const createTestStore = (initialState: any) => createStore(rootReducer, initialState, applyMiddleware(thunk)); const TestApp: FC = ({ children, storeProps, routerProps = {} }) => { - let store: any; + let store: ReturnType; + let appState = rootState; if (storeProps) { - rootState = merge(rootState, storeProps); - store = createTestStore(rootState); + appState = merge(rootState, storeProps); + store = createTestStore(appState); } else { - store = createTestStore(rootState); + store = createTestStore(appState); } const props = { diff --git a/app/soapbox/normalizers/__tests__/account.test.ts b/app/soapbox/normalizers/__tests__/account.test.ts index 761b2fac5..b5f4f5a75 100644 --- a/app/soapbox/normalizers/__tests__/account.test.ts +++ b/app/soapbox/normalizers/__tests__/account.test.ts @@ -154,9 +154,9 @@ describe('normalizeAccount()', () => { const result = normalizeAccount(account); const field = result.fields.get(1); - expect(field.name_emojified).toBe('Soapbox :ablobcatrainbow:'); - expect(field.value_emojified).toBe('https://soapbox.pub :soapbox:'); - expect(field.value_plain).toBe('https://soapbox.pub :soapbox:'); + expect(field?.name_emojified).toBe('Soapbox :ablobcatrainbow:'); + expect(field?.value_emojified).toBe('https://soapbox.pub :soapbox:'); + expect(field?.value_plain).toBe('https://soapbox.pub :soapbox:'); }); it('adds default avatar and banner to GoToSocial account', () => { diff --git a/app/soapbox/normalizers/__tests__/poll.test.ts b/app/soapbox/normalizers/__tests__/poll.test.ts index 31691f484..8acf2ece4 100644 --- a/app/soapbox/normalizers/__tests__/poll.test.ts +++ b/app/soapbox/normalizers/__tests__/poll.test.ts @@ -38,11 +38,11 @@ describe('normalizePoll()', () => { const result = normalizePoll(poll); // Emojifies poll options - expect(result.options.get(1).title_emojified) + expect(result.options.get(1)?.title_emojified) .toEqual('Custom emoji :gleason_excited: '); // Parses emojis as Immutable.Record's expect(ImmutableRecord.isRecord(result.emojis.get(0))).toBe(true); - expect(result.emojis.get(1).shortcode).toEqual('soapbox'); + expect(result.emojis.get(1)?.shortcode).toEqual('soapbox'); }); }); diff --git a/app/soapbox/normalizers/__tests__/status.test.ts b/app/soapbox/normalizers/__tests__/status.test.ts index ac9358f51..43336d00f 100644 --- a/app/soapbox/normalizers/__tests__/status.test.ts +++ b/app/soapbox/normalizers/__tests__/status.test.ts @@ -2,6 +2,8 @@ import { Record as ImmutableRecord, fromJS } from 'immutable'; import { normalizeStatus } from '../status'; +import type { Poll, Card } from 'soapbox/types/entities'; + describe('normalizeStatus()', () => { it('adds base fields', () => { const status = {}; @@ -42,8 +44,8 @@ describe('normalizeStatus()', () => { const result = normalizeStatus(status).mentions; expect(result.size).toBe(1); - expect(result.get(0).toJS()).toMatchObject(expected); - expect(result.get(0).id).toEqual('106801667066418367'); + expect(result.get(0)?.toJS()).toMatchObject(expected); + expect(result.get(0)?.id).toEqual('106801667066418367'); expect(ImmutableRecord.isRecord(result.get(0))).toBe(true); }); @@ -101,8 +103,7 @@ describe('normalizeStatus()', () => { const result = normalizeStatus(status).media_attachments; expect(result.size).toBe(4); - expect(result.get(0).text_url).toBe(undefined); - expect(result.get(1).meta).toEqual(fromJS({})); + expect(result.get(1)?.meta).toEqual(fromJS({})); expect(result.getIn([1, 'pleroma', 'mime_type'])).toBe('application/x-nes-rom'); expect(ImmutableRecord.isRecord(result.get(3))).toBe(true); }); @@ -147,6 +148,7 @@ describe('normalizeStatus()', () => { it('normalizes poll and poll options', () => { const status = { poll: { options: [{ title: 'Apples' }] } }; const result = normalizeStatus(status); + const poll = result.poll as Poll; const expected = { options: [{ title: 'Apples', votes_count: 0 }], @@ -159,46 +161,49 @@ describe('normalizeStatus()', () => { voted: false, }; - expect(ImmutableRecord.isRecord(result.poll)).toBe(true); - expect(ImmutableRecord.isRecord(result.poll.options.get(0))).toBe(true); - expect(result.poll.toJS()).toMatchObject(expected); - expect(result.poll.expires_at instanceof Date).toBe(true); + expect(ImmutableRecord.isRecord(poll)).toBe(true); + expect(ImmutableRecord.isRecord(poll.options.get(0))).toBe(true); + expect(poll.toJS()).toMatchObject(expected); + expect(poll.expires_at instanceof Date).toBe(true); }); it('normalizes a Pleroma logged-out poll', () => { const status = require('soapbox/__fixtures__/pleroma-status-with-poll.json'); const result = normalizeStatus(status); + const poll = result.poll as Poll; // Adds logged-in fields - expect(result.poll.voted).toBe(false); - expect(result.poll.own_votes).toBe(null); + expect(poll.voted).toBe(false); + expect(poll.own_votes).toBe(null); }); it('normalizes poll with emojis', () => { const status = require('soapbox/__fixtures__/pleroma-status-with-poll-with-emojis.json'); const result = normalizeStatus(status); + const poll = result.poll as Poll; // Emojifies poll options - expect(result.poll.options.get(1).title_emojified) + expect(poll.options.get(1)?.title_emojified) .toEqual('Custom emoji :gleason_excited: '); // Parses emojis as Immutable.Record's - expect(ImmutableRecord.isRecord(result.poll.emojis.get(0))).toBe(true); - expect(result.poll.emojis.get(1).shortcode).toEqual('soapbox'); + expect(ImmutableRecord.isRecord(poll.emojis.get(0))).toBe(true); + expect(poll.emojis.get(1)?.shortcode).toEqual('soapbox'); }); it('normalizes a card', () => { const status = require('soapbox/__fixtures__/status-with-card.json'); const result = normalizeStatus(status); + const card = result.card as Card; - expect(ImmutableRecord.isRecord(result.card)).toBe(true); - expect(result.card.type).toEqual('link'); - expect(result.card.provider_url).toEqual('https://soapbox.pub'); + expect(ImmutableRecord.isRecord(card)).toBe(true); + expect(card.type).toEqual('link'); + expect(card.provider_url).toEqual('https://soapbox.pub'); }); it('preserves Truth Social external_video_id', () => { const status = require('soapbox/__fixtures__/truthsocial-status-with-external-video.json'); const result = normalizeStatus(status); - expect(result.media_attachments.get(0).external_video_id).toBe('vwfnq9'); + expect(result.media_attachments.get(0)?.external_video_id).toBe('vwfnq9'); }); }); diff --git a/app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.ts b/app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.ts index 65c4291f8..e48198ecc 100644 --- a/app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.ts +++ b/app/soapbox/normalizers/soapbox/__tests__/soapbox_config-test.ts @@ -32,6 +32,6 @@ describe('normalizeSoapboxConfig()', () => { const result = normalizeSoapboxConfig(require('soapbox/__fixtures__/spinster-soapbox.json')); expect(ImmutableRecord.isRecord(result.promoPanel)).toBe(true); expect(ImmutableRecord.isRecord(result.promoPanel.items.get(0))).toBe(true); - expect(result.promoPanel.items.get(2).icon).toBe('question-circle'); + expect(result.promoPanel.items.get(2)?.icon).toBe('question-circle'); }); }); 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, }); diff --git a/app/soapbox/reducers/account_notes.ts b/app/soapbox/reducers/account_notes.ts index f5d753ee3..0f30b8d60 100644 --- a/app/soapbox/reducers/account_notes.ts +++ b/app/soapbox/reducers/account_notes.ts @@ -10,13 +10,13 @@ import { import type { AnyAction } from 'redux'; -const EditRecord = ImmutableRecord({ +export const EditRecord = ImmutableRecord({ isSubmitting: false, - account: null, + account: null as string | null, comment: '', }); -const ReducerRecord = ImmutableRecord({ +export const ReducerRecord = ImmutableRecord({ edit: EditRecord(), }); diff --git a/app/soapbox/reducers/index.ts b/app/soapbox/reducers/index.ts index 7f33dad1c..72b33f785 100644 --- a/app/soapbox/reducers/index.ts +++ b/app/soapbox/reducers/index.ts @@ -134,7 +134,6 @@ export const StateRecord = ImmutableRecord( }, {}), ); -// @ts-ignore: This type is fine but TS thinks it's wrong const appReducer = combineReducers(reducers, StateRecord); // Clear the state (mostly) when the user logs out diff --git a/app/soapbox/reducers/user_lists.ts b/app/soapbox/reducers/user_lists.ts index 99483a854..fc86cceb2 100644 --- a/app/soapbox/reducers/user_lists.ts +++ b/app/soapbox/reducers/user_lists.ts @@ -54,7 +54,7 @@ import { import type { APIEntity } from 'soapbox/types/entities'; -const ListRecord = ImmutableRecord({ +export const ListRecord = ImmutableRecord({ next: null as string | null, items: ImmutableOrderedSet(), isLoading: false, @@ -72,7 +72,7 @@ const ReactionListRecord = ImmutableRecord({ isLoading: false, }); -const ReducerRecord = ImmutableRecord({ +export const ReducerRecord = ImmutableRecord({ followers: ImmutableMap(), following: ImmutableMap(), reblogged_by: ImmutableMap(), @@ -90,7 +90,7 @@ const ReducerRecord = ImmutableRecord({ }); type State = ReturnType; -type List = ReturnType; +export type List = ReturnType; type Reaction = ReturnType; type ReactionList = ReturnType; type Items = ImmutableOrderedSet; diff --git a/app/soapbox/utils/__tests__/accounts.test.ts b/app/soapbox/utils/__tests__/accounts.test.ts index cafedce35..878d278dd 100644 --- a/app/soapbox/utils/__tests__/accounts.test.ts +++ b/app/soapbox/utils/__tests__/accounts.test.ts @@ -4,11 +4,13 @@ import { getDomain, } from '../accounts'; +import type { ReducerAccount } from 'soapbox/reducers/accounts'; + describe('getDomain', () => { const account = AccountRecord({ acct: 'alice', url: 'https://party.com/users/alice', - }); + }) as ReducerAccount; it('returns the domain', () => { expect(getDomain(account)).toEqual('party.com'); }); diff --git a/app/soapbox/utils/__tests__/numbers.test.tsx b/app/soapbox/utils/__tests__/numbers.test.tsx index 63c45b26b..a0edf41fe 100644 --- a/app/soapbox/utils/__tests__/numbers.test.tsx +++ b/app/soapbox/utils/__tests__/numbers.test.tsx @@ -10,28 +10,28 @@ test('isIntegerId()', () => { expect(isIntegerId('-1764036199')).toBe(true); expect(isIntegerId('106801667066418367')).toBe(true); expect(isIntegerId('9v5bmRalQvjOy0ECcC')).toBe(false); - expect(isIntegerId(null)).toBe(false); - expect(isIntegerId(undefined)).toBe(false); + expect(isIntegerId(null as any)).toBe(false); + expect(isIntegerId(undefined as any)).toBe(false); }); describe('shortNumberFormat', () => { test('handles non-numbers', () => { - render(
{shortNumberFormat('not-number')}
, null, null); + render(
{shortNumberFormat('not-number')}
, undefined, null); expect(screen.getByTestId('num')).toHaveTextContent('•'); }); test('formats numbers under 1,000', () => { - render(
{shortNumberFormat(555)}
, null, null); + render(
{shortNumberFormat(555)}
, undefined, null); expect(screen.getByTestId('num')).toHaveTextContent('555'); }); test('formats numbers under 1,000,000', () => { - render(
{shortNumberFormat(5555)}
, null, null); + render(
{shortNumberFormat(5555)}
, undefined, null); expect(screen.getByTestId('num')).toHaveTextContent('5.6K'); }); test('formats numbers over 1,000,000', () => { - render(
{shortNumberFormat(5555555)}
, null, null); + render(
{shortNumberFormat(5555555)}
, undefined, null); expect(screen.getByTestId('num')).toHaveTextContent('5.6M'); }); }); diff --git a/app/soapbox/utils/__tests__/status.test.ts b/app/soapbox/utils/__tests__/status.test.ts index 4556382de..2bc803ee5 100644 --- a/app/soapbox/utils/__tests__/status.test.ts +++ b/app/soapbox/utils/__tests__/status.test.ts @@ -1,4 +1,3 @@ -import { fromJS } from 'immutable'; import { normalizeStatus } from 'soapbox/normalizers/status'; @@ -7,9 +6,11 @@ import { defaultMediaVisibility, } from '../status'; +import type { ReducerStatus } from 'soapbox/reducers/statuses'; + describe('hasIntegerMediaIds()', () => { it('returns true for a Pleroma deleted status', () => { - const status = normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))); + const status = normalizeStatus(require('soapbox/__fixtures__/pleroma-status-deleted.json')) as ReducerStatus; expect(hasIntegerMediaIds(status)).toBe(true); }); }); @@ -20,17 +21,17 @@ describe('defaultMediaVisibility()', () => { }); it('hides sensitive media by default', () => { - const status = normalizeStatus({ sensitive: true }); + const status = normalizeStatus({ sensitive: true }) as ReducerStatus; expect(defaultMediaVisibility(status, 'default')).toBe(false); }); it('hides media when displayMedia is hide_all', () => { - const status = normalizeStatus({}); + const status = normalizeStatus({}) as ReducerStatus; expect(defaultMediaVisibility(status, 'hide_all')).toBe(false); }); it('shows sensitive media when displayMedia is show_all', () => { - const status = normalizeStatus({ sensitive: true }); + const status = normalizeStatus({ sensitive: true }) as ReducerStatus; expect(defaultMediaVisibility(status, 'show_all')).toBe(true); }); }); diff --git a/app/soapbox/utils/__tests__/tailwind.test.ts b/app/soapbox/utils/__tests__/tailwind.test.ts index 822408393..3c359ecc0 100644 --- a/app/soapbox/utils/__tests__/tailwind.test.ts +++ b/app/soapbox/utils/__tests__/tailwind.test.ts @@ -4,7 +4,7 @@ import { toTailwind, fromLegacyColors, expandPalette } from '../tailwind'; describe('toTailwind()', () => { it('handles empty Soapbox config', () => { - const soapboxConfig = ImmutableMap(); + const soapboxConfig = ImmutableMap(); const result = toTailwind(soapboxConfig); const expected = ImmutableMap({ colors: ImmutableMap() }); expect(result).toEqual(expected); diff --git a/app/soapbox/utils/__tests__/timelines.test.ts b/app/soapbox/utils/__tests__/timelines.test.ts index df48bdae9..852a76ef6 100644 --- a/app/soapbox/utils/__tests__/timelines.test.ts +++ b/app/soapbox/utils/__tests__/timelines.test.ts @@ -4,70 +4,72 @@ import { normalizeStatus } from 'soapbox/normalizers/status'; import { shouldFilter } from '../timelines'; +import type { ReducerStatus } from 'soapbox/reducers/statuses'; + describe('shouldFilter', () => { it('returns false under normal circumstances', () => { const columnSettings = fromJS({}); - const status = normalizeStatus(fromJS({})); + const status = normalizeStatus({}) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('reblog: returns true when `shows.reblog == false`', () => { const columnSettings = fromJS({ shows: { reblog: false } }); - const status = normalizeStatus(fromJS({ reblog: {} })); + const status = normalizeStatus({ reblog: {} }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('reblog: returns false when `shows.reblog == true`', () => { const columnSettings = fromJS({ shows: { reblog: true } }); - const status = normalizeStatus(fromJS({ reblog: {} })); + const status = normalizeStatus({ reblog: {} }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('reply: returns true when `shows.reply == false`', () => { const columnSettings = fromJS({ shows: { reply: false } }); - const status = normalizeStatus(fromJS({ in_reply_to_id: '1234' })); + const status = normalizeStatus({ in_reply_to_id: '1234' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('reply: returns false when `shows.reply == true`', () => { const columnSettings = fromJS({ shows: { reply: true } }); - const status = normalizeStatus(fromJS({ in_reply_to_id: '1234' })); + const status = normalizeStatus({ in_reply_to_id: '1234' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('direct: returns true when `shows.direct == false`', () => { const columnSettings = fromJS({ shows: { direct: false } }); - const status = normalizeStatus(fromJS({ visibility: 'direct' })); + const status = normalizeStatus({ visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('direct: returns false when `shows.direct == true`', () => { const columnSettings = fromJS({ shows: { direct: true } }); - const status = normalizeStatus(fromJS({ visibility: 'direct' })); + const status = normalizeStatus({ visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('direct: returns false for a public post when `shows.direct == false`', () => { const columnSettings = fromJS({ shows: { direct: false } }); - const status = normalizeStatus(fromJS({ visibility: 'public' })); + const status = normalizeStatus({ visibility: 'public' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('multiple settings', () => { const columnSettings = fromJS({ shows: { reblog: false, reply: false, direct: false } }); - const status = normalizeStatus(fromJS({ reblog: null, in_reply_to_id: null, visibility: 'direct' })); + const status = normalizeStatus({ reblog: null, in_reply_to_id: null, visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); it('multiple settings', () => { const columnSettings = fromJS({ shows: { reblog: false, reply: true, direct: false } }); - const status = normalizeStatus(fromJS({ reblog: null, in_reply_to_id: '1234', visibility: 'public' })); + const status = normalizeStatus({ reblog: null, in_reply_to_id: '1234', visibility: 'public' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(false); }); it('multiple settings', () => { const columnSettings = fromJS({ shows: { reblog: true, reply: false, direct: true } }); - const status = normalizeStatus(fromJS({ reblog: {}, in_reply_to_id: '1234', visibility: 'direct' })); + const status = normalizeStatus({ reblog: {}, in_reply_to_id: '1234', visibility: 'direct' }) as ReducerStatus; expect(shouldFilter(status, columnSettings)).toBe(true); }); }); diff --git a/package.json b/package.json index 7568e6eba..cb9ab4481 100644 --- a/package.json +++ b/package.json @@ -202,6 +202,7 @@ "wicg-inert": "^3.1.1" }, "devDependencies": { + "@jedmao/redux-mock-store": "^3.0.5", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react-hooks": "^8.0.1", "@testing-library/user-event": "^14.0.3", @@ -225,7 +226,6 @@ "lint-staged": ">=10", "raf": "^3.4.1", "react-intl-translations-manager": "^5.0.3", - "redux-mock-store": "^1.5.4", "stylelint": "^13.7.2", "stylelint-config-standard": "^22.0.0", "stylelint-scss": "^3.18.0", diff --git a/tsconfig.json b/tsconfig.json index 8989bd57e..dba721d72 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,5 @@ "experimentalDecorators": true, "esModuleInterop": true, "typeRoots": [ "./types", "./node_modules/@types"] - }, - "exclude": ["node_modules", "types", "**/*.test.*", "**/__mocks__/*", "**/__tests__/*"] + } } diff --git a/types/redux-immutable/index.d.ts b/types/redux-immutable/index.d.ts index 80d00209a..fbaecd198 100644 --- a/types/redux-immutable/index.d.ts +++ b/types/redux-immutable/index.d.ts @@ -13,5 +13,5 @@ declare module 'redux-immutable' { export function combineReducers(reducers: ReducersMapObject, getDefaultState?: () => Collection.Keyed): Reducer; export function combineReducers(reducers: ReducersMapObject, getDefaultState?: () => Collection.Indexed): Reducer; export function combineReducers(reducers: ReducersMapObject, getDefaultState?: () => Collection.Indexed): Reducer; - export function combineReducers(reducers: ReducersMapObject, getDefaultState?: Record.Factory): Reducer; + export function combineReducers(reducers: ReducersMapObject, getDefaultState?: Record.Factory): Reducer>>; } diff --git a/yarn.lock b/yarn.lock index 893a03639..8d2248152 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1603,6 +1603,11 @@ resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.3.tgz#e45e384e4b8ec16bce2fd903af78450f6bf7ec98" integrity sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA== +"@jedmao/redux-mock-store@^3.0.5": + version "3.0.5" + resolved "https://registry.yarnpkg.com/@jedmao/redux-mock-store/-/redux-mock-store-3.0.5.tgz#015fa4fc96bfc02b61ca221d9ea0476b78c70c97" + integrity sha512-zNcVCd5/ekSMdQWk64CqTPM24D9Lo59st9KvS+fljGpQXV4SliB7Vo0NFQIgvQJWPYeeobdngnrGy0XbCaARNw== + "@jest/console@^27.5.1": version "27.5.1" resolved "https://registry.yarnpkg.com/@jest/console/-/console-27.5.1.tgz#260fe7239602fe5130a94f1aa386eff54b014bba" @@ -10028,13 +10033,6 @@ redux-immutable@^4.0.0: resolved "https://registry.yarnpkg.com/redux-immutable/-/redux-immutable-4.0.0.tgz#3a1a32df66366462b63691f0e1dc35e472bbc9f3" integrity sha1-Ohoy32Y2ZGK2NpHw4dw15HK7yfM= -redux-mock-store@^1.5.4: - version "1.5.4" - resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.5.4.tgz#90d02495fd918ddbaa96b83aef626287c9ab5872" - integrity sha512-xmcA0O/tjCLXhh9Fuiq6pMrJCwFRaouA8436zcikdIpYWWCjU76CRk+i2bHx8EeiSiMGnB85/lZdU3wIJVXHTA== - dependencies: - lodash.isplainobject "^4.0.6" - redux-thunk@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"