diff --git a/app/soapbox/features/auth_login/components/registration_form.js b/app/soapbox/features/auth_login/components/registration_form.js index 87de069c7..898a1b7bd 100644 --- a/app/soapbox/features/auth_login/components/registration_form.js +++ b/app/soapbox/features/auth_login/components/registration_form.js @@ -261,7 +261,7 @@ class RegistrationForm extends ImmutablePureComponent { const isLoading = this.state.captchaLoading || this.state.submissionLoading; return ( - +
diff --git a/app/soapbox/features/landing_page/__tests__/landing_page-test.tsx b/app/soapbox/features/landing_page/__tests__/landing_page-test.tsx new file mode 100644 index 000000000..ce0ce778c --- /dev/null +++ b/app/soapbox/features/landing_page/__tests__/landing_page-test.tsx @@ -0,0 +1,86 @@ +import * as React from 'react'; + +import LandingPage from '..'; +import { INSTANCE_REMEMBER_SUCCESS } from '../../../actions/instance'; +import { PEPE_FETCH_INSTANCE_SUCCESS } from '../../../actions/verification'; +import { render, screen, rootReducer, applyActions } from '../../../jest/test-helpers'; + +describe('', () => { + it('renders a RegistrationForm for an open Pleroma instance', () => { + + const state = rootReducer(undefined, { + type: INSTANCE_REMEMBER_SUCCESS, + instance: { + version: '2.7.2 (compatible; Pleroma 2.3.0)', + registrations: true, + }, + }); + + render(, null, state); + + expect(screen.queryByTestId('registrations-open')).toBeInTheDocument(); + expect(screen.queryByTestId('registrations-closed')).not.toBeInTheDocument(); + expect(screen.queryByTestId('registrations-pepe')).not.toBeInTheDocument(); + }); + + it('renders "closed" message for a closed Pleroma instance', () => { + + const state = rootReducer(undefined, { + type: INSTANCE_REMEMBER_SUCCESS, + instance: { + version: '2.7.2 (compatible; Pleroma 2.3.0)', + registrations: false, + }, + }); + + render(, null, state); + + expect(screen.queryByTestId('registrations-closed')).toBeInTheDocument(); + expect(screen.queryByTestId('registrations-open')).not.toBeInTheDocument(); + expect(screen.queryByTestId('registrations-pepe')).not.toBeInTheDocument(); + }); + + it('renders Pepe flow for an open Truth Social instance', () => { + + const state = applyActions(undefined, [{ + type: INSTANCE_REMEMBER_SUCCESS, + instance: { + version: '3.4.1 (compatible; TruthSocial 1.0.0)', + registrations: false, + }, + }, { + type: PEPE_FETCH_INSTANCE_SUCCESS, + instance: { + registrations: true, + }, + }], rootReducer); + + render(, null, state); + + expect(screen.queryByTestId('registrations-pepe')).toBeInTheDocument(); + expect(screen.queryByTestId('registrations-open')).not.toBeInTheDocument(); + expect(screen.queryByTestId('registrations-closed')).not.toBeInTheDocument(); + }); + + it('renders "closed" message for a Truth Social instance with Pepe closed', () => { + + const state = applyActions(undefined, [{ + type: INSTANCE_REMEMBER_SUCCESS, + instance: { + version: '3.4.1 (compatible; TruthSocial 1.0.0)', + registrations: false, + }, + }, { + type: PEPE_FETCH_INSTANCE_SUCCESS, + instance: { + registrations: false, + }, + }], rootReducer); + + render(, null, state); + + expect(screen.queryByTestId('registrations-closed')).toBeInTheDocument(); + expect(screen.queryByTestId('registrations-pepe')).not.toBeInTheDocument(); + expect(screen.queryByTestId('registrations-open')).not.toBeInTheDocument(); + }); +}); diff --git a/app/soapbox/features/landing_page/index.js b/app/soapbox/features/landing_page/index.tsx similarity index 57% rename from app/soapbox/features/landing_page/index.js rename to app/soapbox/features/landing_page/index.tsx index 9cf1edf93..e936342e3 100644 --- a/app/soapbox/features/landing_page/index.js +++ b/app/soapbox/features/landing_page/index.tsx @@ -1,18 +1,21 @@ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; -import { useSelector } from 'react-redux'; import VerificationBadge from 'soapbox/components/verification_badge'; +import RegistrationForm from 'soapbox/features/auth_login/components/registration_form'; +import { useAppSelector, useFeatures } from 'soapbox/hooks'; import { Button, Card, CardBody, Stack, Text } from '../../components/ui'; const LandingPage = () => { - const instance = useSelector((state) => state.get('instance')); - const isOpen = useSelector(state => state.getIn(['verification', 'instance', 'registrations'], false) === true); + const features = useFeatures(); + const instance = useAppSelector((state) => state.instance); + const pepeOpen = useAppSelector(state => state.verification.getIn(['instance', 'registrations'], false) === true); + /** Registrations are closed */ const renderClosed = () => { return ( - + { ); }; + /** Mastodon API registrations are open */ + const renderOpen = () => { + return ; + }; + + /** Pepe API registrations are open */ + const renderPepe = () => { + return ( + + + + + Let's get started! + Social Media Without Discrimination + + + + + ); + }; + + // Render registration flow depending on features + const renderBody = () => { + if (features.pepe && pepeOpen) { + return renderPepe(); + } else if (instance.registrations) { + return renderOpen(); + } else { + return renderClosed(); + } + }; + return (
@@ -49,18 +84,7 @@ const LandingPage = () => {
- {isOpen ? ( - - - - - Let's get started! - Social Media Without Discrimination - - - - - ) : renderClosed()} + {renderBody()}
diff --git a/app/soapbox/jest/test-helpers.tsx b/app/soapbox/jest/test-helpers.tsx index 75dc51f32..7a4f8f53b 100644 --- a/app/soapbox/jest/test-helpers.tsx +++ b/app/soapbox/jest/test-helpers.tsx @@ -69,4 +69,5 @@ export { mockStore, applyActions, rootState, + rootReducer, }; diff --git a/app/soapbox/utils/__tests__/features-test.js b/app/soapbox/utils/__tests__/features-test.js index 1531a83ab..6caa38a7b 100644 --- a/app/soapbox/utils/__tests__/features-test.js +++ b/app/soapbox/utils/__tests__/features-test.js @@ -109,4 +109,22 @@ describe('getFeatures', () => { expect(features.focalPoint).toBe(false); }); }); + + describe('pepe', () => { + it('is true for Truth Social', () => { + const instance = InstanceRecord({ + version: '3.4.1 (compatible; TruthSocial 1.0.0)', + }); + const features = getFeatures(instance); + expect(features.pepe).toBe(true); + }); + + it('is false for Pleroma', () => { + const instance = InstanceRecord({ + version: '2.7.2 (compatible; Pleroma 2.3.0)', + }); + const features = getFeatures(instance); + expect(features.pepe).toBe(false); + }); + }); }); diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index c3452bef5..4f70f9341 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -130,6 +130,7 @@ const getInstanceFeatures = (instance: Instance) => { ]), trendingTruths: v.software === TRUTHSOCIAL, trendingStatuses: v.software === MASTODON && gte(v.compatVersion, '3.5.0'), + pepe: v.software === TRUTHSOCIAL, }; };