From c4ad5e5d78e8e1d6fabc05ed1019eb9ff1668ecf Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 20 Jun 2023 17:48:57 -0500 Subject: [PATCH] Fix tests that set the store wrong --- .../components/__tests__/account.test.tsx | 13 ++++---- .../chat-page/__tests__/chat-page.test.tsx | 30 ++++++++++--------- .../groups/__tests__/discover.test.tsx | 14 +++++---- .../__tests__/pending-requests.test.tsx | 14 +++++---- .../__tests__/pending-group-rows.test.tsx | 14 +++++---- .../search/__tests__/recent-searches.test.tsx | 13 ++++---- .../search/__tests__/results.test.tsx | 14 ++++----- .../features/ui/__tests__/index.test.tsx | 11 +++---- .../__tests__/report-modal.test.tsx | 11 +++---- .../hooks/__tests__/useGroupsPath.test.ts | 16 +++++----- app/soapbox/jest/mock-stores.tsx | 12 ++++---- jest.config.cjs | 1 + 12 files changed, 88 insertions(+), 75 deletions(-) diff --git a/app/soapbox/components/__tests__/account.test.tsx b/app/soapbox/components/__tests__/account.test.tsx index e46b1a3af..c231fc533 100644 --- a/app/soapbox/components/__tests__/account.test.tsx +++ b/app/soapbox/components/__tests__/account.test.tsx @@ -1,4 +1,3 @@ -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { buildAccount } from 'soapbox/jest/factory'; @@ -16,9 +15,9 @@ describe('', () => { }); const store = { - accounts: ImmutableMap({ + accounts: { '1': account, - }), + }, }; render(, undefined, store); @@ -37,9 +36,9 @@ describe('', () => { }); const store = { - accounts: ImmutableMap({ + accounts: { '1': account, - }), + }, }; render(, undefined, store); @@ -56,9 +55,9 @@ describe('', () => { }); const store = { - accounts: ImmutableMap({ + accounts: { '1': account, - }), + }, }; render(, undefined, store); diff --git a/app/soapbox/features/chats/components/chat-page/__tests__/chat-page.test.tsx b/app/soapbox/features/chats/components/chat-page/__tests__/chat-page.test.tsx index 21ed9ddb0..482bd5be3 100644 --- a/app/soapbox/features/chats/components/chat-page/__tests__/chat-page.test.tsx +++ b/app/soapbox/features/chats/components/chat-page/__tests__/chat-page.test.tsx @@ -1,12 +1,10 @@ import userEvent from '@testing-library/user-event'; -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { __stub } from 'soapbox/api'; -import { normalizeAccount } from 'soapbox/normalizers'; -import { ReducerAccount } from 'soapbox/reducers/accounts'; +import { buildAccount } from 'soapbox/jest/factory'; +import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; -import { render, screen, waitFor } from '../../../../../jest/test-helpers'; import ChatPage from '../chat-page'; describe('', () => { @@ -25,15 +23,17 @@ describe('', () => { beforeEach(() => { store = { me: id, - accounts: ImmutableMap({ - [id]: normalizeAccount({ + accounts: { + [id]: buildAccount({ id, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, - }) as ReducerAccount, - }), + source: { + chats_onboarded: false, + }, + }), + }, }; __stub((mock) => { @@ -59,15 +59,17 @@ describe('', () => { beforeEach(() => { store = { me: '1', - accounts: ImmutableMap({ - '1': normalizeAccount({ + accounts: { + '1': buildAccount({ id: '1', acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, - }) as ReducerAccount, - }), + source: { + chats_onboarded: false, + }, + }), + }, }; __stub((mock) => { diff --git a/app/soapbox/features/groups/__tests__/discover.test.tsx b/app/soapbox/features/groups/__tests__/discover.test.tsx index b2485cdde..485cbc72e 100644 --- a/app/soapbox/features/groups/__tests__/discover.test.tsx +++ b/app/soapbox/features/groups/__tests__/discover.test.tsx @@ -1,9 +1,9 @@ import userEvent from '@testing-library/user-event'; -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; +import { buildAccount } from 'soapbox/jest/factory'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; -import { normalizeAccount, normalizeInstance } from 'soapbox/normalizers'; +import { normalizeInstance } from 'soapbox/normalizers'; import Discover from '../discover'; @@ -21,15 +21,17 @@ jest.mock('../../../hooks/useDimensions', () => ({ const userId = '1'; const store: any = { me: userId, - accounts: ImmutableMap({ - [userId]: normalizeAccount({ + accounts: { + [userId]: buildAccount({ id: userId, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, + source: { + chats_onboarded: false, + }, }), - }), + }, instance: normalizeInstance({ version: '3.4.1 (compatible; TruthSocial 1.0.0)', software: 'TRUTHSOCIAL', diff --git a/app/soapbox/features/groups/__tests__/pending-requests.test.tsx b/app/soapbox/features/groups/__tests__/pending-requests.test.tsx index fbc7aba3a..adbe4003e 100644 --- a/app/soapbox/features/groups/__tests__/pending-requests.test.tsx +++ b/app/soapbox/features/groups/__tests__/pending-requests.test.tsx @@ -1,25 +1,27 @@ -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { VirtuosoMockContext } from 'react-virtuoso'; import { __stub } from 'soapbox/api'; +import { buildAccount } from 'soapbox/jest/factory'; 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'; const userId = '1'; const store: any = { me: userId, - accounts: ImmutableMap({ - [userId]: normalizeAccount({ + accounts: { + [userId]: buildAccount({ id: userId, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, + source: { + chats_onboarded: false, + }, }), - }), + }, instance: normalizeInstance({ version: '3.4.1 (compatible; TruthSocial 1.0.0)', software: 'TRUTHSOCIAL', diff --git a/app/soapbox/features/groups/components/__tests__/pending-group-rows.test.tsx b/app/soapbox/features/groups/components/__tests__/pending-group-rows.test.tsx index 1b6cee612..2f9c78b1c 100644 --- a/app/soapbox/features/groups/components/__tests__/pending-group-rows.test.tsx +++ b/app/soapbox/features/groups/components/__tests__/pending-group-rows.test.tsx @@ -1,25 +1,27 @@ -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { VirtuosoMockContext } from 'react-virtuoso'; import { __stub } from 'soapbox/api'; +import { buildAccount } from 'soapbox/jest/factory'; 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'; const userId = '1'; let store: any = { me: userId, - accounts: ImmutableMap({ - [userId]: normalizeAccount({ + accounts: { + [userId]: buildAccount({ id: userId, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, + source: { + chats_onboarded: false, + }, }), - }), + }, }; const renderApp = (store: any) => ( diff --git a/app/soapbox/features/groups/components/discover/search/__tests__/recent-searches.test.tsx b/app/soapbox/features/groups/components/discover/search/__tests__/recent-searches.test.tsx index 8c0e54262..36a08b5c6 100644 --- a/app/soapbox/features/groups/components/discover/search/__tests__/recent-searches.test.tsx +++ b/app/soapbox/features/groups/components/discover/search/__tests__/recent-searches.test.tsx @@ -1,10 +1,9 @@ import userEvent from '@testing-library/user-event'; -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { VirtuosoMockContext } from 'react-virtuoso'; +import { buildAccount } from 'soapbox/jest/factory'; import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; -import { normalizeAccount } from 'soapbox/normalizers'; import { groupSearchHistory } from 'soapbox/settings'; import { clearRecentGroupSearches, saveGroupSearch } from 'soapbox/utils/groups'; @@ -13,15 +12,17 @@ import RecentSearches from '../recent-searches'; const userId = '1'; const store = { me: userId, - accounts: ImmutableMap({ - [userId]: normalizeAccount({ + accounts: { + [userId]: buildAccount({ id: userId, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, + source: { + chats_onboarded: false, + }, }), - }), + }, }; const renderApp = (children: React.ReactNode) => ( diff --git a/app/soapbox/features/groups/components/discover/search/__tests__/results.test.tsx b/app/soapbox/features/groups/components/discover/search/__tests__/results.test.tsx index 66523ec5d..bc310c85b 100644 --- a/app/soapbox/features/groups/components/discover/search/__tests__/results.test.tsx +++ b/app/soapbox/features/groups/components/discover/search/__tests__/results.test.tsx @@ -1,26 +1,26 @@ import userEvent from '@testing-library/user-event'; -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; 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 { normalizeAccount } from 'soapbox/normalizers'; import Results from '../results'; const userId = '1'; const store = { me: userId, - accounts: ImmutableMap({ - [userId]: normalizeAccount({ + accounts: { + [userId]: buildAccount({ id: userId, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, + source: { + chats_onboarded: false, + }, }), - }), + }, }; const renderApp = (children: React.ReactNode) => ( diff --git a/app/soapbox/features/ui/__tests__/index.test.tsx b/app/soapbox/features/ui/__tests__/index.test.tsx index 0a55f3ca5..6fb4b1e83 100644 --- a/app/soapbox/features/ui/__tests__/index.test.tsx +++ b/app/soapbox/features/ui/__tests__/index.test.tsx @@ -1,9 +1,10 @@ -import { Map as ImmutableMap } from 'immutable'; import React from 'react'; import { Route, Switch } from 'react-router-dom'; +import { buildAccount } from 'soapbox/jest/factory'; + import { render, screen, waitFor } from '../../../jest/test-helpers'; -import { normalizeAccount, normalizeInstance } from '../../../normalizers'; +import { normalizeInstance } from '../../../normalizers'; import UI from '../index'; import { WrappedRoute } from '../util/react-router-helpers'; @@ -25,14 +26,14 @@ describe('', () => { beforeEach(() => { store = { me: false, - accounts: ImmutableMap({ - '1': normalizeAccount({ + accounts: { + '1': buildAccount({ id: '1', acct: 'username', display_name: 'My name', avatar: 'test.jpg', }), - }), + }, instance: normalizeInstance({ registrations: true }), }; }); 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 56816b10c..ad46ac174 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 @@ -4,9 +4,10 @@ import React from 'react'; import { ReportableEntities } from 'soapbox/actions/reports'; 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'; describe('', () => { @@ -17,14 +18,14 @@ describe('', () => { const status = require('soapbox/__fixtures__/status-unordered-mentions.json'); store = { - accounts: ImmutableMap({ - '1': normalizeAccount({ + accounts: { + '1': buildAccount({ id: '1', acct: 'username', display_name: 'My name', avatar: 'test.jpg', }), - }), + }, reports: ImmutableRecord({ new: ImmutableRecord({ account_id: '1', diff --git a/app/soapbox/hooks/__tests__/useGroupsPath.test.ts b/app/soapbox/hooks/__tests__/useGroupsPath.test.ts index 7596acd9a..328639f5b 100644 --- a/app/soapbox/hooks/__tests__/useGroupsPath.test.ts +++ b/app/soapbox/hooks/__tests__/useGroupsPath.test.ts @@ -1,9 +1,7 @@ -import { Map as ImmutableMap } from 'immutable'; - 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 { normalizeAccount, normalizeInstance } from 'soapbox/normalizers'; +import { normalizeInstance } from 'soapbox/normalizers'; import { useGroupsPath } from '../useGroupsPath'; @@ -30,15 +28,17 @@ describe('useGroupsPath()', () => { version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)', }), me: userId, - accounts: ImmutableMap({ - [userId]: normalizeAccount({ + accounts: { + [userId]: buildAccount({ id: userId, acct: 'justin-username', display_name: 'Justin L', avatar: 'test.jpg', - chats_onboarded: false, + source: { + chats_onboarded: false, + }, }), - }), + }, }; }); diff --git a/app/soapbox/jest/mock-stores.tsx b/app/soapbox/jest/mock-stores.tsx index db22ed197..e8969780b 100644 --- a/app/soapbox/jest/mock-stores.tsx +++ b/app/soapbox/jest/mock-stores.tsx @@ -1,7 +1,9 @@ -import { Map as ImmutableMap, fromJS } from 'immutable'; +import { fromJS } from 'immutable'; 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. */ const storeOpen = { instance: normalizeInstance({ registrations: true }) }; @@ -26,9 +28,9 @@ const storePepeClosed = { /** Store with a logged-in user. */ const storeLoggedIn = { me: alexJson.id, - accounts: ImmutableMap({ - [alexJson.id]: normalizeAccount(alexJson), - }), + accounts: { + [alexJson.id]: buildAccount(alexJson as any), + }, }; export { diff --git a/jest.config.cjs b/jest.config.cjs index 358bf9ecf..43e750705 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -9,6 +9,7 @@ module.exports = { '/static/', '/tmp/', '/webpack/', + '/app/soapbox/actions/', ], 'setupFiles': [ 'raf/polyfill',