Fix tests that set the store wrong

This commit is contained in:
Alex Gleason 2023-06-20 17:48:57 -05:00
parent e7217c5c58
commit c4ad5e5d78
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
12 changed files with 88 additions and 75 deletions

View file

@ -1,4 +1,3 @@
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { buildAccount } from 'soapbox/jest/factory'; import { buildAccount } from 'soapbox/jest/factory';
@ -16,9 +15,9 @@ describe('<Account />', () => {
}); });
const store = { const store = {
accounts: ImmutableMap({ accounts: {
'1': account, '1': account,
}), },
}; };
render(<Account account={account} />, undefined, store); render(<Account account={account} />, undefined, store);
@ -37,9 +36,9 @@ describe('<Account />', () => {
}); });
const store = { const store = {
accounts: ImmutableMap({ accounts: {
'1': account, '1': account,
}), },
}; };
render(<Account account={account} />, undefined, store); render(<Account account={account} />, undefined, store);
@ -56,9 +55,9 @@ describe('<Account />', () => {
}); });
const store = { const store = {
accounts: ImmutableMap({ accounts: {
'1': account, '1': account,
}), },
}; };
render(<Account account={account} />, undefined, store); render(<Account account={account} />, undefined, store);

View file

@ -1,12 +1,10 @@
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { __stub } from 'soapbox/api'; import { __stub } from 'soapbox/api';
import { normalizeAccount } from 'soapbox/normalizers'; import { buildAccount } from 'soapbox/jest/factory';
import { ReducerAccount } from 'soapbox/reducers/accounts'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { render, screen, waitFor } from '../../../../../jest/test-helpers';
import ChatPage from '../chat-page'; import ChatPage from '../chat-page';
describe('<ChatPage />', () => { describe('<ChatPage />', () => {
@ -25,15 +23,17 @@ describe('<ChatPage />', () => {
beforeEach(() => { beforeEach(() => {
store = { store = {
me: id, me: id,
accounts: ImmutableMap({ accounts: {
[id]: normalizeAccount({ [id]: buildAccount({
id, id,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
}) as ReducerAccount, },
}), }),
},
}; };
__stub((mock) => { __stub((mock) => {
@ -59,15 +59,17 @@ describe('<ChatPage />', () => {
beforeEach(() => { beforeEach(() => {
store = { store = {
me: '1', me: '1',
accounts: ImmutableMap({ accounts: {
'1': normalizeAccount({ '1': buildAccount({
id: '1', id: '1',
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
}) as ReducerAccount, },
}), }),
},
}; };
__stub((mock) => { __stub((mock) => {

View file

@ -1,9 +1,9 @@
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { buildAccount } from 'soapbox/jest/factory';
import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeAccount, normalizeInstance } from 'soapbox/normalizers'; import { normalizeInstance } from 'soapbox/normalizers';
import Discover from '../discover'; import Discover from '../discover';
@ -21,15 +21,17 @@ jest.mock('../../../hooks/useDimensions', () => ({
const userId = '1'; const userId = '1';
const store: any = { const store: any = {
me: userId, me: userId,
accounts: ImmutableMap({ accounts: {
[userId]: normalizeAccount({ [userId]: buildAccount({
id: userId, id: userId,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
},
}), }),
}), },
instance: normalizeInstance({ instance: normalizeInstance({
version: '3.4.1 (compatible; TruthSocial 1.0.0)', version: '3.4.1 (compatible; TruthSocial 1.0.0)',
software: 'TRUTHSOCIAL', software: 'TRUTHSOCIAL',

View file

@ -1,25 +1,27 @@
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { VirtuosoMockContext } from 'react-virtuoso'; import { VirtuosoMockContext } from 'react-virtuoso';
import { __stub } from 'soapbox/api'; import { __stub } from 'soapbox/api';
import { buildAccount } from 'soapbox/jest/factory';
import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeAccount, normalizeGroup, normalizeGroupRelationship, normalizeInstance } from 'soapbox/normalizers'; import { normalizeGroup, normalizeGroupRelationship, normalizeInstance } from 'soapbox/normalizers';
import PendingRequests from '../pending-requests'; import PendingRequests from '../pending-requests';
const userId = '1'; const userId = '1';
const store: any = { const store: any = {
me: userId, me: userId,
accounts: ImmutableMap({ accounts: {
[userId]: normalizeAccount({ [userId]: buildAccount({
id: userId, id: userId,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
},
}), }),
}), },
instance: normalizeInstance({ instance: normalizeInstance({
version: '3.4.1 (compatible; TruthSocial 1.0.0)', version: '3.4.1 (compatible; TruthSocial 1.0.0)',
software: 'TRUTHSOCIAL', software: 'TRUTHSOCIAL',

View file

@ -1,25 +1,27 @@
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { VirtuosoMockContext } from 'react-virtuoso'; import { VirtuosoMockContext } from 'react-virtuoso';
import { __stub } from 'soapbox/api'; import { __stub } from 'soapbox/api';
import { buildAccount } from 'soapbox/jest/factory';
import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeAccount, normalizeGroup, normalizeGroupRelationship, normalizeInstance } from 'soapbox/normalizers'; import { normalizeGroup, normalizeGroupRelationship, normalizeInstance } from 'soapbox/normalizers';
import PendingGroupsRow from '../pending-groups-row'; import PendingGroupsRow from '../pending-groups-row';
const userId = '1'; const userId = '1';
let store: any = { let store: any = {
me: userId, me: userId,
accounts: ImmutableMap({ accounts: {
[userId]: normalizeAccount({ [userId]: buildAccount({
id: userId, id: userId,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
},
}), }),
}), },
}; };
const renderApp = (store: any) => ( const renderApp = (store: any) => (

View file

@ -1,10 +1,9 @@
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { VirtuosoMockContext } from 'react-virtuoso'; import { VirtuosoMockContext } from 'react-virtuoso';
import { buildAccount } from 'soapbox/jest/factory';
import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeAccount } from 'soapbox/normalizers';
import { groupSearchHistory } from 'soapbox/settings'; import { groupSearchHistory } from 'soapbox/settings';
import { clearRecentGroupSearches, saveGroupSearch } from 'soapbox/utils/groups'; import { clearRecentGroupSearches, saveGroupSearch } from 'soapbox/utils/groups';
@ -13,15 +12,17 @@ import RecentSearches from '../recent-searches';
const userId = '1'; const userId = '1';
const store = { const store = {
me: userId, me: userId,
accounts: ImmutableMap({ accounts: {
[userId]: normalizeAccount({ [userId]: buildAccount({
id: userId, id: userId,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
},
}), }),
}), },
}; };
const renderApp = (children: React.ReactNode) => ( const renderApp = (children: React.ReactNode) => (

View file

@ -1,26 +1,26 @@
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { VirtuosoGridMockContext, VirtuosoMockContext } from 'react-virtuoso'; import { VirtuosoGridMockContext, VirtuosoMockContext } from 'react-virtuoso';
import { buildGroup } from 'soapbox/jest/factory'; import { buildAccount, buildGroup } from 'soapbox/jest/factory';
import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeAccount } from 'soapbox/normalizers';
import Results from '../results'; import Results from '../results';
const userId = '1'; const userId = '1';
const store = { const store = {
me: userId, me: userId,
accounts: ImmutableMap({ accounts: {
[userId]: normalizeAccount({ [userId]: buildAccount({
id: userId, id: userId,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
},
}), }),
}), },
}; };
const renderApp = (children: React.ReactNode) => ( const renderApp = (children: React.ReactNode) => (

View file

@ -1,9 +1,10 @@
import { Map as ImmutableMap } from 'immutable';
import React from 'react'; import React from 'react';
import { Route, Switch } from 'react-router-dom'; import { Route, Switch } from 'react-router-dom';
import { buildAccount } from 'soapbox/jest/factory';
import { render, screen, waitFor } from '../../../jest/test-helpers'; import { render, screen, waitFor } from '../../../jest/test-helpers';
import { normalizeAccount, normalizeInstance } from '../../../normalizers'; import { normalizeInstance } from '../../../normalizers';
import UI from '../index'; import UI from '../index';
import { WrappedRoute } from '../util/react-router-helpers'; import { WrappedRoute } from '../util/react-router-helpers';
@ -25,14 +26,14 @@ describe('<UI />', () => {
beforeEach(() => { beforeEach(() => {
store = { store = {
me: false, me: false,
accounts: ImmutableMap({ accounts: {
'1': normalizeAccount({ '1': buildAccount({
id: '1', id: '1',
acct: 'username', acct: 'username',
display_name: 'My name', display_name: 'My name',
avatar: 'test.jpg', avatar: 'test.jpg',
}), }),
}), },
instance: normalizeInstance({ registrations: true }), instance: normalizeInstance({ registrations: true }),
}; };
}); });

View file

@ -4,9 +4,10 @@ import React from 'react';
import { ReportableEntities } from 'soapbox/actions/reports'; import { ReportableEntities } from 'soapbox/actions/reports';
import { __stub } from 'soapbox/api'; import { __stub } from 'soapbox/api';
import { buildAccount } from 'soapbox/jest/factory';
import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeStatus } from 'soapbox/normalizers';
import { render, screen, waitFor } from '../../../../../../jest/test-helpers';
import { normalizeAccount, normalizeStatus } from '../../../../../../normalizers';
import ReportModal from '../report-modal'; import ReportModal from '../report-modal';
describe('<ReportModal />', () => { describe('<ReportModal />', () => {
@ -17,14 +18,14 @@ describe('<ReportModal />', () => {
const status = require('soapbox/__fixtures__/status-unordered-mentions.json'); const status = require('soapbox/__fixtures__/status-unordered-mentions.json');
store = { store = {
accounts: ImmutableMap({ accounts: {
'1': normalizeAccount({ '1': buildAccount({
id: '1', id: '1',
acct: 'username', acct: 'username',
display_name: 'My name', display_name: 'My name',
avatar: 'test.jpg', avatar: 'test.jpg',
}), }),
}), },
reports: ImmutableRecord({ reports: ImmutableRecord({
new: ImmutableRecord({ new: ImmutableRecord({
account_id: '1', account_id: '1',

View file

@ -1,9 +1,7 @@
import { Map as ImmutableMap } from 'immutable';
import { __stub } from 'soapbox/api'; import { __stub } from 'soapbox/api';
import { buildGroup, buildGroupRelationship } from 'soapbox/jest/factory'; import { buildAccount, buildGroup, buildGroupRelationship } from 'soapbox/jest/factory';
import { renderHook, waitFor } from 'soapbox/jest/test-helpers'; import { renderHook, waitFor } from 'soapbox/jest/test-helpers';
import { normalizeAccount, normalizeInstance } from 'soapbox/normalizers'; import { normalizeInstance } from 'soapbox/normalizers';
import { useGroupsPath } from '../useGroupsPath'; import { useGroupsPath } from '../useGroupsPath';
@ -30,15 +28,17 @@ describe('useGroupsPath()', () => {
version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)', version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)',
}), }),
me: userId, me: userId,
accounts: ImmutableMap({ accounts: {
[userId]: normalizeAccount({ [userId]: buildAccount({
id: userId, id: userId,
acct: 'justin-username', acct: 'justin-username',
display_name: 'Justin L', display_name: 'Justin L',
avatar: 'test.jpg', avatar: 'test.jpg',
source: {
chats_onboarded: false, chats_onboarded: false,
},
}), }),
}), },
}; };
}); });

View file

@ -1,7 +1,9 @@
import { Map as ImmutableMap, fromJS } from 'immutable'; import { fromJS } from 'immutable';
import alexJson from 'soapbox/__fixtures__/pleroma-account.json'; import alexJson from 'soapbox/__fixtures__/pleroma-account.json';
import { normalizeAccount, normalizeInstance } from 'soapbox/normalizers'; import { normalizeInstance } from 'soapbox/normalizers';
import { buildAccount } from './factory';
/** Store with registrations open. */ /** Store with registrations open. */
const storeOpen = { instance: normalizeInstance({ registrations: true }) }; const storeOpen = { instance: normalizeInstance({ registrations: true }) };
@ -26,9 +28,9 @@ const storePepeClosed = {
/** Store with a logged-in user. */ /** Store with a logged-in user. */
const storeLoggedIn = { const storeLoggedIn = {
me: alexJson.id, me: alexJson.id,
accounts: ImmutableMap({ accounts: {
[alexJson.id]: normalizeAccount(alexJson), [alexJson.id]: buildAccount(alexJson as any),
}), },
}; };
export { export {

View file

@ -9,6 +9,7 @@ module.exports = {
'<rootDir>/static/', '<rootDir>/static/',
'<rootDir>/tmp/', '<rootDir>/tmp/',
'<rootDir>/webpack/', '<rootDir>/webpack/',
'<rootDir>/app/soapbox/actions/',
], ],
'setupFiles': [ 'setupFiles': [
'raf/polyfill', 'raf/polyfill',