2022-06-20 06:46:43 -07:00
|
|
|
import { Map as ImmutableMap, Record as ImmutableRecord } from 'immutable';
|
2022-04-04 08:54:00 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { Route, Switch } from 'react-router-dom';
|
|
|
|
|
2022-04-12 10:13:51 -07:00
|
|
|
import { __stub } from 'soapbox/api';
|
|
|
|
|
2022-04-04 08:54:00 -07:00
|
|
|
import { render, screen } from '../../../jest/test-helpers';
|
|
|
|
import Verification from '../index';
|
|
|
|
|
|
|
|
const TestableComponent = () => (
|
|
|
|
<Switch>
|
2022-04-30 09:28:18 -07:00
|
|
|
<Route path='/verify' exact><Verification /></Route>
|
2022-04-04 08:54:00 -07:00
|
|
|
<Route path='/' exact><span data-testid='home'>Homepage</span></Route>
|
|
|
|
</Switch>
|
|
|
|
);
|
|
|
|
|
2022-07-06 10:11:39 -07:00
|
|
|
const renderComponent = (store: any) => render(
|
2022-04-04 08:54:00 -07:00
|
|
|
<TestableComponent />,
|
|
|
|
{},
|
|
|
|
store,
|
2022-04-30 09:28:18 -07:00
|
|
|
{ initialEntries: ['/verify'] },
|
2022-04-04 08:54:00 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
describe('<Verification />', () => {
|
2022-07-06 10:11:39 -07:00
|
|
|
let store: any;
|
2022-04-04 08:54:00 -07:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = {
|
2022-06-20 06:46:43 -07:00
|
|
|
verification: ImmutableRecord({
|
|
|
|
instance: ImmutableMap({
|
2022-04-04 08:54:00 -07:00
|
|
|
isReady: true,
|
|
|
|
registrations: true,
|
2022-06-20 06:46:43 -07:00
|
|
|
}),
|
|
|
|
ageMinimum: null,
|
|
|
|
currentChallenge: null,
|
|
|
|
isLoading: false,
|
2022-04-04 08:54:00 -07:00
|
|
|
isComplete: false,
|
2022-06-20 06:46:43 -07:00
|
|
|
token: null,
|
|
|
|
})(),
|
2022-04-04 08:54:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
__stub(mock => {
|
|
|
|
mock.onGet('/api/v1/pepe/instance')
|
|
|
|
.reply(200, {
|
|
|
|
age_minimum: 18,
|
|
|
|
approval_required: true,
|
|
|
|
challenges: ['age', 'email', 'sms'],
|
|
|
|
});
|
|
|
|
|
|
|
|
mock.onPost('/api/v1/pepe/registrations')
|
|
|
|
.reply(200, {
|
|
|
|
access_token: 'N-dZmNqNSmTutJLsGjZ5AnJL4sLw_y-N3pn2acSqJY8',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When registration is closed', () => {
|
|
|
|
it('successfully redirects to the homepage', () => {
|
|
|
|
const verification = store.verification.setIn(['instance', 'registrations'], false);
|
|
|
|
store.verification = verification;
|
|
|
|
|
|
|
|
renderComponent(store);
|
|
|
|
expect(screen.getByTestId('home')).toHaveTextContent('Homepage');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When verification is complete', () => {
|
|
|
|
it('successfully renders the Registration component', () => {
|
|
|
|
const verification = store.verification.set('isComplete', true);
|
|
|
|
store.verification = verification;
|
|
|
|
|
|
|
|
renderComponent(store);
|
|
|
|
expect(screen.getByRole('heading')).toHaveTextContent('Register your account');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Switching verification steps', () => {
|
|
|
|
it('successfully renders the Birthday step', () => {
|
|
|
|
const verification = store.verification.set('currentChallenge', 'age');
|
|
|
|
store.verification = verification;
|
|
|
|
|
|
|
|
renderComponent(store);
|
|
|
|
|
|
|
|
expect(screen.getByRole('heading')).toHaveTextContent('Enter your birth date');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('successfully renders the Email step', () => {
|
|
|
|
const verification = store.verification.set('currentChallenge', 'email');
|
|
|
|
store.verification = verification;
|
|
|
|
|
|
|
|
renderComponent(store);
|
|
|
|
|
|
|
|
expect(screen.getByRole('heading')).toHaveTextContent('Enter your email address');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('successfully renders the SMS step', () => {
|
|
|
|
const verification = store.verification.set('currentChallenge', 'sms');
|
|
|
|
store.verification = verification;
|
|
|
|
|
|
|
|
renderComponent(store);
|
|
|
|
|
|
|
|
expect(screen.getByRole('heading')).toHaveTextContent('Enter your phone number');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|