mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
removed stray onCaptchaError from bind list
This commit is contained in:
parent
f713298d37
commit
510906e538
2 changed files with 51 additions and 66 deletions
|
@ -25,8 +25,7 @@ class EmailStep extends React.Component {
|
|||
'validateForm',
|
||||
'setCaptchaRef',
|
||||
'captchaSolved',
|
||||
'onCaptchaLoad',
|
||||
'onCaptchaError'
|
||||
'onCaptchaLoad'
|
||||
]);
|
||||
this.state = {
|
||||
captchaIsLoading: true
|
||||
|
|
|
@ -26,23 +26,23 @@ describe('EmailStep test', () => {
|
|||
});
|
||||
|
||||
test('send correct props to formik', () => {
|
||||
const wrapper = shallowWithIntl(<EmailStep />);
|
||||
const intlWrapper = shallowWithIntl(<EmailStep />);
|
||||
|
||||
const formikWrapper = wrapper.dive();
|
||||
expect(formikWrapper.props().initialValues.subscribe).toBe(false);
|
||||
expect(formikWrapper.props().initialValues.email).toBe('');
|
||||
expect(formikWrapper.props().validateOnBlur).toBe(false);
|
||||
expect(formikWrapper.props().validateOnChange).toBe(false);
|
||||
expect(formikWrapper.props().validate).toBe(formikWrapper.instance().validateForm);
|
||||
expect(formikWrapper.props().onSubmit).toBe(formikWrapper.instance().handleValidSubmit);
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
expect(emailStepWrapper.props().initialValues.subscribe).toBe(false);
|
||||
expect(emailStepWrapper.props().initialValues.email).toBe('');
|
||||
expect(emailStepWrapper.props().validateOnBlur).toBe(false);
|
||||
expect(emailStepWrapper.props().validateOnChange).toBe(false);
|
||||
expect(emailStepWrapper.props().validate).toBe(emailStepWrapper.instance().validateForm);
|
||||
expect(emailStepWrapper.props().onSubmit).toBe(emailStepWrapper.instance().handleValidSubmit);
|
||||
});
|
||||
|
||||
test('props sent to JoinFlowStep', () => {
|
||||
const wrapper = shallowWithIntl(<EmailStep />);
|
||||
const intlWrapper = shallowWithIntl(<EmailStep />);
|
||||
// Dive to get past the intl wrapper
|
||||
const formikWrapper = wrapper.dive();
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
// Dive to get past the anonymous component.
|
||||
const joinFlowWrapper = formikWrapper.dive().find(JoinFlowStep);
|
||||
const joinFlowWrapper = emailStepWrapper.dive().find(JoinFlowStep);
|
||||
expect(joinFlowWrapper).toHaveLength(1);
|
||||
expect(joinFlowWrapper.props().footerContent.props.id).toBe('registration.acceptTermsOfUse');
|
||||
expect(joinFlowWrapper.props().headerImgSrc).toBe('/images/join-flow/email-header.png');
|
||||
|
@ -54,11 +54,11 @@ describe('EmailStep test', () => {
|
|||
});
|
||||
|
||||
test('props sent to FormikInput for email', () => {
|
||||
const wrapper = shallowWithIntl(<EmailStep />);
|
||||
const intlWrapper = shallowWithIntl(<EmailStep />);
|
||||
// Dive to get past the intl wrapper
|
||||
const formikWrapper = wrapper.dive();
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
// Dive to get past the anonymous component.
|
||||
const joinFlowWrapper = formikWrapper.dive().find(JoinFlowStep);
|
||||
const joinFlowWrapper = emailStepWrapper.dive().find(JoinFlowStep);
|
||||
expect(joinFlowWrapper).toHaveLength(1);
|
||||
const emailInputWrapper = joinFlowWrapper.find(FormikInput).first();
|
||||
expect(emailInputWrapper.props().id).toEqual('email');
|
||||
|
@ -66,16 +66,16 @@ describe('EmailStep test', () => {
|
|||
expect(emailInputWrapper.props().name).toEqual('email');
|
||||
expect(emailInputWrapper.props().placeholder).toEqual('general.emailAddress');
|
||||
expect(emailInputWrapper.props().validationClassName).toEqual('validation-full-width-input');
|
||||
expect(emailInputWrapper.props().onSetRef).toEqual(formikWrapper.instance().handleSetEmailRef);
|
||||
expect(emailInputWrapper.props().validate).toEqual(formikWrapper.instance().validateEmail);
|
||||
expect(emailInputWrapper.props().onSetRef).toEqual(emailStepWrapper.instance().handleSetEmailRef);
|
||||
expect(emailInputWrapper.props().validate).toEqual(emailStepWrapper.instance().validateEmail);
|
||||
});
|
||||
|
||||
test('props sent to FormikCheckbox for subscribe', () => {
|
||||
const wrapper = shallowWithIntl(<EmailStep />);
|
||||
const intlWrapper = shallowWithIntl(<EmailStep />);
|
||||
// Dive to get past the intl wrapper
|
||||
const formikWrapper = wrapper.dive();
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
// Dive to get past the anonymous component.
|
||||
const joinFlowWrapper = formikWrapper.dive().find(JoinFlowStep);
|
||||
const joinFlowWrapper = emailStepWrapper.dive().find(JoinFlowStep);
|
||||
expect(joinFlowWrapper).toHaveLength(1);
|
||||
const checkboxWrapper = joinFlowWrapper.find(FormikCheckbox).first();
|
||||
expect(checkboxWrapper).toHaveLength(1);
|
||||
|
@ -93,12 +93,12 @@ describe('EmailStep test', () => {
|
|||
render: jest.fn()
|
||||
};
|
||||
const formData = {item1: 'thing', item2: 'otherthing'};
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />);
|
||||
|
||||
const formikWrapper = wrapper.dive();
|
||||
formikWrapper.instance().onCaptchaLoad(); // to setup catpcha state
|
||||
formikWrapper.instance().handleValidSubmit(formData, formikBag);
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
emailStepWrapper.instance().onCaptchaLoad(); // to setup catpcha state
|
||||
emailStepWrapper.instance().handleValidSubmit(formData, formikBag);
|
||||
|
||||
expect(formikBag.setSubmitting).toHaveBeenCalledWith(false);
|
||||
expect(global.grecaptcha.execute).toHaveBeenCalled();
|
||||
|
@ -116,18 +116,18 @@ describe('EmailStep test', () => {
|
|||
render: jest.fn()
|
||||
};
|
||||
const formData = {item1: 'thing', item2: 'otherthing'};
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep
|
||||
{...props}
|
||||
/>);
|
||||
|
||||
const formikWrapper = wrapper.dive();
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
// Call these to setup captcha.
|
||||
formikWrapper.instance().onCaptchaLoad(); // to setup catpcha state
|
||||
formikWrapper.instance().handleValidSubmit(formData, formikBag);
|
||||
emailStepWrapper.instance().onCaptchaLoad(); // to setup catpcha state
|
||||
emailStepWrapper.instance().handleValidSubmit(formData, formikBag);
|
||||
|
||||
const captchaToken = 'abcd';
|
||||
formikWrapper.instance().captchaSolved(captchaToken);
|
||||
emailStepWrapper.instance().captchaSolved(captchaToken);
|
||||
// Make sure captchaSolved calls onNextStep with formData that has
|
||||
// a captcha token and left everything else in the object in place.
|
||||
expect(props.onNextStep).toHaveBeenCalledWith(
|
||||
|
@ -139,65 +139,51 @@ describe('EmailStep test', () => {
|
|||
expect(formikBag.setSubmitting).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
test('onCaptchaError calls error function with correct message', () => {
|
||||
const props = {
|
||||
onRegistrationError: jest.fn()
|
||||
};
|
||||
|
||||
const wrapper = shallowWithIntl(
|
||||
<EmailStep
|
||||
{...props}
|
||||
/>);
|
||||
|
||||
const formikWrapper = wrapper.dive();
|
||||
formikWrapper.instance().onCaptchaError();
|
||||
expect(props.onRegistrationError).toHaveBeenCalledWith('registration.troubleReload');
|
||||
});
|
||||
|
||||
test('Captcha load error calls error function', () => {
|
||||
const props = {
|
||||
onRegistrationError: jest.fn()
|
||||
onCaptchaError: jest.fn()
|
||||
};
|
||||
// Set this to null to force an error.
|
||||
global.grecaptcha = null;
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep
|
||||
{...props}
|
||||
/>);
|
||||
/>
|
||||
);
|
||||
|
||||
const formikWrapper = wrapper.dive();
|
||||
formikWrapper.instance().onCaptchaLoad();
|
||||
expect(props.onRegistrationError).toHaveBeenCalledWith('registration.troubleReload');
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
emailStepWrapper.instance().onCaptchaLoad();
|
||||
expect(props.onCaptchaError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('validateEmail test email empty', () => {
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />);
|
||||
const formikWrapper = wrapper.dive();
|
||||
const val = formikWrapper.instance().validateEmail('');
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
const val = emailStepWrapper.instance().validateEmail('');
|
||||
expect(val).toBe('general.required');
|
||||
});
|
||||
|
||||
test('validateEmail test email null', () => {
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />);
|
||||
const formikWrapper = wrapper.dive();
|
||||
const val = formikWrapper.instance().validateEmail(null);
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
const val = emailStepWrapper.instance().validateEmail(null);
|
||||
expect(val).toBe('general.required');
|
||||
});
|
||||
|
||||
test('validateEmail test email undefined', () => {
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />);
|
||||
const formikWrapper = wrapper.dive();
|
||||
const val = formikWrapper.instance().validateEmail();
|
||||
const emailStepWrapper = intlWrapper.dive();
|
||||
const val = emailStepWrapper.instance().validateEmail();
|
||||
expect(val).toBe('general.required');
|
||||
});
|
||||
|
||||
test('validateEmailRemotelyWithCache calls validate.validateEmailRemotely', done => {
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />);
|
||||
const instance = wrapper.dive().instance();
|
||||
const instance = intlWrapper.dive().instance();
|
||||
|
||||
instance.validateEmailRemotelyWithCache('some-email@some-domain.com')
|
||||
.then(response => {
|
||||
|
@ -209,10 +195,10 @@ describe('EmailStep test', () => {
|
|||
});
|
||||
|
||||
test('validateEmailRemotelyWithCache, called twice with different data, makes two remote requests', done => {
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />
|
||||
);
|
||||
const instance = wrapper.dive().instance();
|
||||
const instance = intlWrapper.dive().instance();
|
||||
|
||||
instance.validateEmailRemotelyWithCache('some-email@some-domain.com')
|
||||
.then(response => {
|
||||
|
@ -233,10 +219,10 @@ describe('EmailStep test', () => {
|
|||
});
|
||||
|
||||
test('validateEmailRemotelyWithCache, called twice with same data, only makes one remote request', done => {
|
||||
const wrapper = shallowWithIntl(
|
||||
const intlWrapper = shallowWithIntl(
|
||||
<EmailStep />
|
||||
);
|
||||
const instance = wrapper.dive().instance();
|
||||
const instance = intlWrapper.dive().instance();
|
||||
|
||||
instance.validateEmailRemotelyWithCache('some-email@some-domain.com')
|
||||
.then(response => {
|
||||
|
|
Loading…
Reference in a new issue