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 f7ce106a7..f6d66de13 100644
--- a/app/soapbox/features/ui/components/__tests__/cta-banner.test.tsx
+++ b/app/soapbox/features/ui/components/__tests__/cta-banner.test.tsx
@@ -1,46 +1,33 @@
-import { fromJS } from 'immutable';
import React from 'react';
-import { normalizeInstance } from 'soapbox/normalizers';
+import { storeClosed, storeLoggedIn, storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
import { render, screen } from '../../../../jest/test-helpers';
import CtaBanner from '../cta-banner';
describe('', () => {
it('renders the banner', () => {
- const store = { instance: normalizeInstance({ registrations: true }) };
-
- render(, undefined, store);
+ render(, undefined, storeOpen);
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
});
describe('with a logged in user', () => {
it('renders empty', () => {
- const store = { me: true };
-
- render(, undefined, store);
+ render(, undefined, storeLoggedIn);
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
});
});
describe('with registrations closed', () => {
it('renders empty', () => {
- const store = { instance: normalizeInstance({ registrations: false }) };
-
- render(, undefined, store);
+ render(, undefined, storeClosed);
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
});
});
describe('with Pepe enabled', () => {
it('renders the banner', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: true }) },
- };
-
- render(, undefined, store);
+ render(, undefined, storePepeOpen);
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
});
});
diff --git a/app/soapbox/features/ui/components/__tests__/navbar.test.tsx b/app/soapbox/features/ui/components/__tests__/navbar.test.tsx
index 92c295bf1..f46d9db72 100644
--- a/app/soapbox/features/ui/components/__tests__/navbar.test.tsx
+++ b/app/soapbox/features/ui/components/__tests__/navbar.test.tsx
@@ -1,8 +1,7 @@
-import { fromJS } from 'immutable';
import React from 'react';
+import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
import { render, screen } from 'soapbox/jest/test-helpers';
-import { normalizeInstance } from 'soapbox/normalizers';
import Navbar from '../navbar';
@@ -19,21 +18,14 @@ describe('', () => {
describe('with registrations enabled', () => {
it('displays the signup button', () => {
- const store = { instance: normalizeInstance({ registrations: true }) };
- render(, undefined, store);
+ render(, undefined, storeOpen);
expect(screen.getByText('Sign up')).toBeInTheDocument();
});
});
describe('with registrations closed, Pepe enabled', () => {
it('displays the signup button', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: true }) },
- };
-
- render(, undefined, store);
+ render(, undefined, storePepeOpen);
expect(screen.getByText('Sign up')).toBeInTheDocument();
});
});
diff --git a/app/soapbox/features/ui/components/modals/__tests__/landing-page-modal.test.tsx b/app/soapbox/features/ui/components/modals/__tests__/landing-page-modal.test.tsx
index 13602d7b2..aa99a7f65 100644
--- a/app/soapbox/features/ui/components/modals/__tests__/landing-page-modal.test.tsx
+++ b/app/soapbox/features/ui/components/modals/__tests__/landing-page-modal.test.tsx
@@ -1,8 +1,7 @@
-import { fromJS } from 'immutable';
import React from 'react';
+import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
import { render, screen } from 'soapbox/jest/test-helpers';
-import { normalizeInstance } from 'soapbox/normalizers';
import LandingPageModal from '../landing-page-modal';
@@ -19,21 +18,14 @@ describe('', () => {
describe('with registrations enabled', () => {
it('displays the signup button', () => {
- const store = { instance: normalizeInstance({ registrations: true }) };
- render(, undefined, store);
+ render(, undefined, storeOpen);
expect(screen.getByText('Register')).toBeInTheDocument();
});
});
describe('with registrations closed, Pepe enabled', () => {
it('displays the signup button', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: true }) },
- };
-
- render(, undefined, store);
+ render(, undefined, storePepeOpen);
expect(screen.getByText('Register')).toBeInTheDocument();
});
});
diff --git a/app/soapbox/features/ui/components/modals/__tests__/unauthorized-modal.test.tsx b/app/soapbox/features/ui/components/modals/__tests__/unauthorized-modal.test.tsx
index 5f79db2d6..db5f775b4 100644
--- a/app/soapbox/features/ui/components/modals/__tests__/unauthorized-modal.test.tsx
+++ b/app/soapbox/features/ui/components/modals/__tests__/unauthorized-modal.test.tsx
@@ -1,8 +1,7 @@
-import { fromJS } from 'immutable';
import React from 'react';
+import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
import { render, screen } from 'soapbox/jest/test-helpers';
-import { normalizeInstance } from 'soapbox/normalizers';
import UnauthorizedModal from '../unauthorized-modal';
@@ -19,21 +18,14 @@ describe('', () => {
describe('with registrations enabled', () => {
it('displays the signup button', () => {
- const store = { instance: normalizeInstance({ registrations: true }) };
- render(, undefined, store);
+ render(, undefined, storeOpen);
expect(screen.getByText('Sign up')).toBeInTheDocument();
});
});
describe('with registrations closed, Pepe enabled', () => {
it('displays the signup button', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: true }) },
- };
-
- render(, undefined, store);
+ render(, undefined, storePepeOpen);
expect(screen.getByText('Sign up')).toBeInTheDocument();
});
});
diff --git a/app/soapbox/features/ui/components/panels/__tests__/sign-up-panel.test.tsx b/app/soapbox/features/ui/components/panels/__tests__/sign-up-panel.test.tsx
index 003727ab7..0ff47848a 100644
--- a/app/soapbox/features/ui/components/panels/__tests__/sign-up-panel.test.tsx
+++ b/app/soapbox/features/ui/components/panels/__tests__/sign-up-panel.test.tsx
@@ -1,8 +1,7 @@
-import { fromJS } from 'immutable';
import React from 'react';
+import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
import { render, screen } from 'soapbox/jest/test-helpers';
-import { normalizeInstance } from 'soapbox/normalizers';
import SignUpPanel from '../sign-up-panel';
@@ -14,21 +13,14 @@ describe('', () => {
describe('with registrations enabled', () => {
it('successfully renders', () => {
- const store = { instance: normalizeInstance({ registrations: true }) };
- render(, undefined, store);
+ render(, undefined, storeOpen);
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
});
});
describe('with registrations closed, Pepe enabled', () => {
it('successfully renders', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: true }) },
- };
-
- render(, undefined, store);
+ render(, undefined, storePepeOpen);
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
});
});
diff --git a/app/soapbox/hooks/__tests__/useRegistrationStatus.test.ts b/app/soapbox/hooks/__tests__/useRegistrationStatus.test.ts
index 4dd9e42ce..465ca3992 100644
--- a/app/soapbox/hooks/__tests__/useRegistrationStatus.test.ts
+++ b/app/soapbox/hooks/__tests__/useRegistrationStatus.test.ts
@@ -1,14 +1,11 @@
-import { fromJS } from 'immutable';
-
+import { storeClosed, storeOpen, storePepeClosed, storePepeOpen } from 'soapbox/jest/mock-stores';
import { renderHook } from 'soapbox/jest/test-helpers';
-import { normalizeInstance } from 'soapbox/normalizers';
import { useRegistrationStatus } from '../useRegistrationStatus';
describe('useRegistrationStatus()', () => {
test('Registrations open', () => {
- const store = { instance: normalizeInstance({ registrations: true }) };
- const { result } = renderHook(useRegistrationStatus, undefined, store);
+ const { result } = renderHook(useRegistrationStatus, undefined, storeOpen);
expect(result.current).toMatchObject({
isOpen: true,
@@ -18,8 +15,7 @@ describe('useRegistrationStatus()', () => {
});
test('Registrations closed', () => {
- const store = { instance: normalizeInstance({ registrations: false }) };
- const { result } = renderHook(useRegistrationStatus, undefined, store);
+ const { result } = renderHook(useRegistrationStatus, undefined, storeClosed);
expect(result.current).toMatchObject({
isOpen: false,
@@ -29,13 +25,7 @@ describe('useRegistrationStatus()', () => {
});
test('Registrations closed, Pepe enabled & open', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: true }) },
- };
-
- const { result } = renderHook(useRegistrationStatus, undefined, store);
+ const { result } = renderHook(useRegistrationStatus, undefined, storePepeOpen);
expect(result.current).toMatchObject({
isOpen: true,
@@ -45,13 +35,7 @@ describe('useRegistrationStatus()', () => {
});
test('Registrations closed, Pepe enabled & closed', () => {
- const store = {
- instance: normalizeInstance({ registrations: false }),
- soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
- verification: { instance: fromJS({ registrations: false }) },
- };
-
- const { result } = renderHook(useRegistrationStatus, undefined, store);
+ const { result } = renderHook(useRegistrationStatus, undefined, storePepeClosed);
expect(result.current).toMatchObject({
isOpen: false,
diff --git a/app/soapbox/jest/mock-stores.tsx b/app/soapbox/jest/mock-stores.tsx
new file mode 100644
index 000000000..db22ed197
--- /dev/null
+++ b/app/soapbox/jest/mock-stores.tsx
@@ -0,0 +1,40 @@
+import { Map as ImmutableMap, fromJS } from 'immutable';
+
+import alexJson from 'soapbox/__fixtures__/pleroma-account.json';
+import { normalizeAccount, normalizeInstance } from 'soapbox/normalizers';
+
+/** Store with registrations open. */
+const storeOpen = { instance: normalizeInstance({ registrations: true }) };
+
+/** Store with registrations closed. */
+const storeClosed = { instance: normalizeInstance({ registrations: false }) };
+
+/** Store with registrations closed, and Pepe enabled & open. */
+const storePepeOpen = {
+ instance: normalizeInstance({ registrations: false }),
+ soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
+ verification: { instance: fromJS({ registrations: true }) },
+};
+
+/** Store with registrations closed, and Pepe enabled & closed. */
+const storePepeClosed = {
+ instance: normalizeInstance({ registrations: false }),
+ soapbox: fromJS({ extensions: { pepe: { enabled: true } } }),
+ verification: { instance: fromJS({ registrations: false }) },
+};
+
+/** Store with a logged-in user. */
+const storeLoggedIn = {
+ me: alexJson.id,
+ accounts: ImmutableMap({
+ [alexJson.id]: normalizeAccount(alexJson),
+ }),
+};
+
+export {
+ storeOpen,
+ storeClosed,
+ storePepeOpen,
+ storePepeClosed,
+ storeLoggedIn,
+};
\ No newline at end of file