kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
FIX ACTION TESTS TYPES
rodzic
e47e33e21c
commit
e9112506c6
|
@ -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<typeof mockStore>;
|
||||
|
||||
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<typeof mockStore>;
|
||||
|
||||
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<typeof mockStore>;
|
||||
|
||||
beforeEach(() => {
|
||||
const state = rootReducer(undefined, {});
|
||||
const state = rootState;
|
||||
store = mockStore(state);
|
||||
});
|
||||
|
||||
|
|
|
@ -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, rootReducer } 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<typeof mockStore>;
|
||||
|
||||
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 = rootReducer(undefined, {} as any)
|
||||
.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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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<any>(message, String(status), null, null, {
|
||||
const buildError = (message: string, status: number) => new AxiosError<any>(message, String(status), undefined, null, {
|
||||
data: {
|
||||
error: message,
|
||||
},
|
||||
|
@ -15,10 +14,10 @@ const buildError = (message: string, status: number) => new AxiosError<any>(mess
|
|||
config: {},
|
||||
});
|
||||
|
||||
let store;
|
||||
let store: ReturnType<typeof mockStore>;
|
||||
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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<typeof mockStore>;
|
||||
|
||||
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<typeof mockStore>;
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ import { mockStore, rootState } from 'soapbox/jest/test-helpers';
|
|||
import { fetchCarouselAvatars } from '../carousels';
|
||||
|
||||
describe('fetchCarouselAvatars()', () => {
|
||||
let store;
|
||||
let store: ReturnType<typeof mockStore>;
|
||||
|
||||
beforeEach(() => {
|
||||
store = mockStore(rootState);
|
||||
});
|
||||
|
||||
describe('with a successful API request', () => {
|
||||
let avatars;
|
||||
let avatars: Record<string, any>[];
|
||||
|
||||
beforeEach(() => {
|
||||
avatars = [
|
||||
|
|
|
@ -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<typeof mockStore>;
|
||||
|
||||
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<typeof mockStore>;
|
||||
|
||||
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 },
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<typeof mockStore>;
|
||||
|
||||
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');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { configureMockStore } from '@jedmao/redux-mock-store';
|
||||
import { render, RenderOptions } from '@testing-library/react';
|
||||
import { merge, Record as ImmutableRecord } from 'immutable';
|
||||
import { merge } from 'immutable';
|
||||
import React, { FC, ReactElement } from 'react';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import { Provider } from 'react-redux';
|
||||
|
@ -17,8 +17,7 @@ import type { AppDispatch } from 'soapbox/store';
|
|||
|
||||
// Mock Redux
|
||||
// https://redux.js.org/recipes/writing-tests/
|
||||
const gg = rootReducer(undefined, {} as Action);
|
||||
const rootState = gg as unknown as ImmutableRecord<typeof gg>;
|
||||
const rootState = rootReducer(undefined, {} as Action);
|
||||
const mockStore = configureMockStore<typeof rootState, AnyAction, AppDispatch>([thunk]);
|
||||
|
||||
/** Apply actions to the state, one at a time. */
|
||||
|
@ -29,7 +28,7 @@ const applyActions = (state: any, actions: any, reducer: any) => {
|
|||
const createTestStore = (initialState: any) => createStore(rootReducer, initialState, applyMiddleware(thunk));
|
||||
|
||||
const TestApp: FC<any> = ({ children, storeProps, routerProps = {} }) => {
|
||||
let store: any;
|
||||
let store: ReturnType<typeof createTestStore>;
|
||||
let appState = rootState;
|
||||
|
||||
if (storeProps) {
|
||||
|
|
|
@ -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(),
|
||||
});
|
||||
|
||||
|
|
|
@ -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<string>(),
|
||||
isLoading: false,
|
||||
|
@ -72,7 +72,7 @@ const ReactionListRecord = ImmutableRecord({
|
|||
isLoading: false,
|
||||
});
|
||||
|
||||
const ReducerRecord = ImmutableRecord({
|
||||
export const ReducerRecord = ImmutableRecord({
|
||||
followers: ImmutableMap<string, List>(),
|
||||
following: ImmutableMap<string, List>(),
|
||||
reblogged_by: ImmutableMap<string, List>(),
|
||||
|
@ -90,7 +90,7 @@ const ReducerRecord = ImmutableRecord({
|
|||
});
|
||||
|
||||
type State = ReturnType<typeof ReducerRecord>;
|
||||
type List = ReturnType<typeof ListRecord>;
|
||||
export type List = ReturnType<typeof ListRecord>;
|
||||
type Reaction = ReturnType<typeof ReactionRecord>;
|
||||
type ReactionList = ReturnType<typeof ReactionListRecord>;
|
||||
type Items = ImmutableOrderedSet<string>;
|
||||
|
|
Ładowanie…
Reference in New Issue