Redirect the homepage to any path See merge request soapbox-pub/soapbox!2160environments/review-develop-3zknud/deployments/2309
commit
d86878e561
@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
|
|
||||||
|
import Header from '../header';
|
||||||
|
|
||||||
|
describe('<Header />', () => {
|
||||||
|
it('successfully renders', () => {
|
||||||
|
render(<Header />);
|
||||||
|
expect(screen.getByTestId('public-layout-header')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('doesn\'t display the signup button by default', () => {
|
||||||
|
render(<Header />);
|
||||||
|
expect(screen.queryByText('Register')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<Header />, undefined, storeOpen);
|
||||||
|
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<Header />, undefined, storePepeOpen);
|
||||||
|
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,30 +1,34 @@
|
|||||||
import { Map as ImmutableMap } from 'immutable';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeClosed, storeLoggedIn, storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
|
||||||
import { render, screen } from '../../../../jest/test-helpers';
|
import { render, screen } from '../../../../jest/test-helpers';
|
||||||
import CtaBanner from '../cta-banner';
|
import CtaBanner from '../cta-banner';
|
||||||
|
|
||||||
describe('<CtaBanner />', () => {
|
describe('<CtaBanner />', () => {
|
||||||
it('renders the banner', () => {
|
it('renders the banner', () => {
|
||||||
render(<CtaBanner />);
|
render(<CtaBanner />, undefined, storeOpen);
|
||||||
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with a logged in user', () => {
|
describe('with a logged in user', () => {
|
||||||
it('renders empty', () => {
|
it('renders empty', () => {
|
||||||
const store = { me: true };
|
render(<CtaBanner />, undefined, storeLoggedIn);
|
||||||
|
|
||||||
render(<CtaBanner />, undefined, store);
|
|
||||||
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with singleUserMode enabled', () => {
|
describe('with registrations closed', () => {
|
||||||
it('renders empty', () => {
|
it('renders empty', () => {
|
||||||
const store = { soapbox: ImmutableMap({ singleUserMode: true }) };
|
render(<CtaBanner />, undefined, storeClosed);
|
||||||
|
|
||||||
render(<CtaBanner />, undefined, store);
|
|
||||||
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
expect(screen.queryAllByTestId('cta-banner')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with Pepe enabled', () => {
|
||||||
|
it('renders the banner', () => {
|
||||||
|
render(<CtaBanner />, undefined, storePepeOpen);
|
||||||
|
expect(screen.getByTestId('cta-banner')).toHaveTextContent(/sign up/i);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
|
|
||||||
|
import Navbar from '../navbar';
|
||||||
|
|
||||||
|
describe('<Navbar />', () => {
|
||||||
|
it('successfully renders', () => {
|
||||||
|
render(<Navbar />);
|
||||||
|
expect(screen.getByTestId('navbar')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('doesn\'t display the signup button by default', () => {
|
||||||
|
render(<Navbar />);
|
||||||
|
expect(screen.queryByText('Sign up')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<Navbar />, undefined, storeOpen);
|
||||||
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<Navbar />, undefined, storePepeOpen);
|
||||||
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
|
|
||||||
|
import LandingPageModal from '../landing-page-modal';
|
||||||
|
|
||||||
|
describe('<LandingPageModal />', () => {
|
||||||
|
it('successfully renders', () => {
|
||||||
|
render(<LandingPageModal onClose={jest.fn} />);
|
||||||
|
expect(screen.getByTestId('modal')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('doesn\'t display the signup button by default', () => {
|
||||||
|
render(<LandingPageModal onClose={jest.fn} />);
|
||||||
|
expect(screen.queryByText('Register')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<LandingPageModal onClose={jest.fn} />, undefined, storeOpen);
|
||||||
|
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<LandingPageModal onClose={jest.fn} />, undefined, storePepeOpen);
|
||||||
|
expect(screen.getByText('Register')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
|
|
||||||
|
import UnauthorizedModal from '../unauthorized-modal';
|
||||||
|
|
||||||
|
describe('<UnauthorizedModal />', () => {
|
||||||
|
it('successfully renders', () => {
|
||||||
|
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />);
|
||||||
|
expect(screen.getByTestId('modal')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('doesn\'t display the signup button by default', () => {
|
||||||
|
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />);
|
||||||
|
expect(screen.queryByText('Sign up')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, storeOpen);
|
||||||
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
|
it('displays the signup button', () => {
|
||||||
|
render(<UnauthorizedModal onClose={jest.fn} action='FOLLOW' />, undefined, storePepeOpen);
|
||||||
|
expect(screen.getByText('Sign up')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { storeOpen, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
import { render, screen } from 'soapbox/jest/test-helpers';
|
||||||
|
|
||||||
|
import SignUpPanel from '../sign-up-panel';
|
||||||
|
|
||||||
|
describe('<SignUpPanel />', () => {
|
||||||
|
it('doesn\'t render by default', () => {
|
||||||
|
render(<SignUpPanel />);
|
||||||
|
expect(screen.queryByTestId('sign-up-panel')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations enabled', () => {
|
||||||
|
it('successfully renders', () => {
|
||||||
|
render(<SignUpPanel />, undefined, storeOpen);
|
||||||
|
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with registrations closed, Pepe enabled', () => {
|
||||||
|
it('successfully renders', () => {
|
||||||
|
render(<SignUpPanel />, undefined, storePepeOpen);
|
||||||
|
expect(screen.getByTestId('sign-up-panel')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,46 @@
|
|||||||
|
import { storeClosed, storeOpen, storePepeClosed, storePepeOpen } from 'soapbox/jest/mock-stores';
|
||||||
|
import { renderHook } from 'soapbox/jest/test-helpers';
|
||||||
|
|
||||||
|
import { useRegistrationStatus } from '../useRegistrationStatus';
|
||||||
|
|
||||||
|
describe('useRegistrationStatus()', () => {
|
||||||
|
test('Registrations open', () => {
|
||||||
|
const { result } = renderHook(useRegistrationStatus, undefined, storeOpen);
|
||||||
|
|
||||||
|
expect(result.current).toMatchObject({
|
||||||
|
isOpen: true,
|
||||||
|
pepeEnabled: false,
|
||||||
|
pepeOpen: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Registrations closed', () => {
|
||||||
|
const { result } = renderHook(useRegistrationStatus, undefined, storeClosed);
|
||||||
|
|
||||||
|
expect(result.current).toMatchObject({
|
||||||
|
isOpen: false,
|
||||||
|
pepeEnabled: false,
|
||||||
|
pepeOpen: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Registrations closed, Pepe enabled & open', () => {
|
||||||
|
const { result } = renderHook(useRegistrationStatus, undefined, storePepeOpen);
|
||||||
|
|
||||||
|
expect(result.current).toMatchObject({
|
||||||
|
isOpen: true,
|
||||||
|
pepeEnabled: true,
|
||||||
|
pepeOpen: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Registrations closed, Pepe enabled & closed', () => {
|
||||||
|
const { result } = renderHook(useRegistrationStatus, undefined, storePepeClosed);
|
||||||
|
|
||||||
|
expect(result.current).toMatchObject({
|
||||||
|
isOpen: false,
|
||||||
|
pepeEnabled: true,
|
||||||
|
pepeOpen: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,22 @@
|
|||||||
|
import { useAppSelector } from './useAppSelector';
|
||||||
|
import { useFeatures } from './useFeatures';
|
||||||
|
import { useInstance } from './useInstance';
|
||||||
|
import { useSoapboxConfig } from './useSoapboxConfig';
|
||||||
|
|
||||||
|
export const useRegistrationStatus = () => {
|
||||||
|
const instance = useInstance();
|
||||||
|
const features = useFeatures();
|
||||||
|
const soapboxConfig = useSoapboxConfig();
|
||||||
|
|
||||||
|
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
|
||||||
|
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
|
||||||
|
|
||||||
|
return {
|
||||||
|
/** Registrations are open, either through Pepe or traditional account creation. */
|
||||||
|
isOpen: (features.accountCreation && instance.registrations) || (pepeEnabled && pepeOpen),
|
||||||
|
/** Whether Pepe is open. */
|
||||||
|
pepeOpen,
|
||||||
|
/** Whether Pepe is enabled. */
|
||||||
|
pepeEnabled,
|
||||||
|
};
|
||||||
|
};
|
@ -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,
|
||||||
|
};
|
Loading…
Reference in new issue