2019-09-04 23:32:49 -04:00
|
|
|
import React from 'react';
|
|
|
|
import {shallowWithIntl} from '../../helpers/intl-helpers.jsx';
|
2019-11-05 11:54:20 -05:00
|
|
|
import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
|
2019-09-04 23:32:49 -04:00
|
|
|
import JoinFlowStep from '../../../src/components/join-flow/join-flow-step';
|
|
|
|
import RegistrationErrorStep from '../../../src/components/join-flow/registration-error-step';
|
|
|
|
|
|
|
|
describe('RegistrationErrorStep', () => {
|
2019-10-18 11:40:31 -04:00
|
|
|
const onSubmit = jest.fn();
|
2019-09-04 23:32:49 -04:00
|
|
|
|
2019-10-18 11:40:31 -04:00
|
|
|
const getRegistrationErrorStepWrapper = props => {
|
|
|
|
const wrapper = shallowWithIntl(
|
2019-09-04 23:32:49 -04:00
|
|
|
<RegistrationErrorStep
|
2019-11-04 10:47:04 -05:00
|
|
|
<<<<<<< HEAD
|
|
|
|
=======
|
|
|
|
errorMsg={'error message'}
|
|
|
|
sendAnalytics={jest.fn()}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
>>>>>>> Add analytics logging to join flow. Adding page views for each step in the flow.
|
2019-10-18 11:40:31 -04:00
|
|
|
{...props}
|
2019-09-04 23:32:49 -04:00
|
|
|
/>
|
|
|
|
);
|
2019-10-18 11:40:31 -04:00
|
|
|
return wrapper
|
|
|
|
.dive(); // unwrap injectIntl()
|
|
|
|
};
|
2019-11-05 11:54:20 -05:00
|
|
|
<<<<<<< HEAD
|
2019-09-04 23:32:49 -04:00
|
|
|
|
2019-10-23 10:16:58 -04:00
|
|
|
test('registrationError has JoinFlowStep', () => {
|
|
|
|
const props = {
|
|
|
|
canTryAgain: true,
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
|
|
|
expect(joinFlowStepWrapper).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when errorMsg provided, registrationError shows it', () => {
|
|
|
|
const props = {
|
|
|
|
canTryAgain: true,
|
|
|
|
errorMsg: 'halp there is a errors!!',
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
|
|
|
const joinFlowStepInstance = joinFlowStepWrapper.dive();
|
2019-10-23 10:36:20 -04:00
|
|
|
const errMsgElement = joinFlowStepInstance.find('.registration-error-msg');
|
2019-10-23 10:16:58 -04:00
|
|
|
expect(errMsgElement).toHaveLength(1);
|
|
|
|
expect(errMsgElement.text()).toEqual('halp there is a errors!!');
|
|
|
|
});
|
|
|
|
|
2019-11-05 08:34:33 -05:00
|
|
|
test('when errorMsg is null, registrationError does not show it', () => {
|
|
|
|
const props = {
|
|
|
|
canTryAgain: true,
|
|
|
|
errorMsg: null,
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
|
|
|
const joinFlowStepInstance = joinFlowStepWrapper.dive();
|
|
|
|
const errMsgElement = joinFlowStepInstance.find('.registration-error-msg');
|
|
|
|
expect(errMsgElement).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2019-10-23 10:16:58 -04:00
|
|
|
test('when no errorMsg provided, registrationError does not show it', () => {
|
|
|
|
const props = {
|
|
|
|
canTryAgain: true,
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
|
|
|
const joinFlowStepInstance = joinFlowStepWrapper.dive();
|
2019-10-23 10:36:20 -04:00
|
|
|
const errMsgElement = joinFlowStepInstance.find('.registration-error-msg');
|
2019-10-23 10:16:58 -04:00
|
|
|
expect(errMsgElement).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2019-11-05 11:54:20 -05:00
|
|
|
=======
|
|
|
|
test('logs to analytics', () => {
|
|
|
|
const analyticsFn = jest.fn();
|
|
|
|
mountWithIntl(
|
|
|
|
<RegistrationErrorStep
|
|
|
|
sendAnalytics={analyticsFn}
|
|
|
|
/>);
|
|
|
|
expect(analyticsFn).toHaveBeenCalledWith('join-error');
|
|
|
|
});
|
|
|
|
>>>>>>> Set sendAnalytics to be required and send the right props to the error step. Also add a test for the error step.
|
2019-10-18 11:40:31 -04:00
|
|
|
test('when canTryAgain is true, show tryAgain message', () => {
|
2019-10-23 10:16:58 -04:00
|
|
|
const props = {
|
|
|
|
canTryAgain: true,
|
|
|
|
errorMsg: 'halp there is a errors!!',
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
2019-10-18 11:40:31 -04:00
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
2019-09-04 23:32:49 -04:00
|
|
|
expect(joinFlowStepWrapper).toHaveLength(1);
|
|
|
|
expect(joinFlowStepWrapper.props().nextButton).toBe('general.tryAgain');
|
|
|
|
});
|
|
|
|
|
2019-10-18 11:40:31 -04:00
|
|
|
test('when canTryAgain is false, show startOver message', () => {
|
2019-10-23 10:16:58 -04:00
|
|
|
const props = {
|
|
|
|
canTryAgain: false,
|
|
|
|
errorMsg: 'halp there is a errors!!',
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
2019-10-18 11:40:31 -04:00
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
|
|
|
expect(joinFlowStepWrapper).toHaveLength(1);
|
|
|
|
expect(joinFlowStepWrapper.props().nextButton).toBe('general.startOver');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when canTryAgain is missing, show startOver message', () => {
|
2019-10-23 10:16:58 -04:00
|
|
|
const props = {
|
|
|
|
errorMsg: 'halp there is a errors!!',
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
2019-10-18 11:40:31 -04:00
|
|
|
expect(joinFlowStepWrapper).toHaveLength(1);
|
|
|
|
expect(joinFlowStepWrapper.props().nextButton).toBe('general.startOver');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when submitted, onSubmit is called', () => {
|
2019-10-23 10:16:58 -04:00
|
|
|
const props = {
|
|
|
|
canTryAgain: true,
|
|
|
|
errorMsg: 'halp there is a errors!!',
|
|
|
|
onSubmit: onSubmit
|
|
|
|
};
|
|
|
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
2019-09-04 23:32:49 -04:00
|
|
|
joinFlowStepWrapper.props().onSubmit(new Event('event')); // eslint-disable-line no-undef
|
2019-10-18 11:40:31 -04:00
|
|
|
expect(onSubmit).toHaveBeenCalled();
|
2019-09-04 23:32:49 -04:00
|
|
|
});
|
|
|
|
});
|