bigbuffet-rw/app/soapbox/features/verification/__tests__/index.test.tsx

102 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-04-04 08:54:00 -07:00
import { Map as ImmutableMap } from 'immutable';
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>
);
const renderComponent = (store) => render(
<TestableComponent />,
{},
store,
2022-04-30 09:28:18 -07:00
{ initialEntries: ['/verify'] },
2022-04-04 08:54:00 -07:00
);
describe('<Verification />', () => {
let store;
beforeEach(() => {
store = {
verification: ImmutableMap({
instance: {
isReady: true,
registrations: true,
},
isComplete: false,
}),
};
__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');
});
});
});