From 510906e5384028dbe62ae7c7b0660fc0bc756166 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Wed, 23 Oct 2019 15:33:31 -0400 Subject: [PATCH] removed stray onCaptchaError from bind list --- src/components/join-flow/email-step.jsx | 3 +- test/unit/components/email-step.test.jsx | 114 ++++++++++------------- 2 files changed, 51 insertions(+), 66 deletions(-) diff --git a/src/components/join-flow/email-step.jsx b/src/components/join-flow/email-step.jsx index 772298d81..c70093c74 100644 --- a/src/components/join-flow/email-step.jsx +++ b/src/components/join-flow/email-step.jsx @@ -25,8 +25,7 @@ class EmailStep extends React.Component { 'validateForm', 'setCaptchaRef', 'captchaSolved', - 'onCaptchaLoad', - 'onCaptchaError' + 'onCaptchaLoad' ]); this.state = { captchaIsLoading: true diff --git a/test/unit/components/email-step.test.jsx b/test/unit/components/email-step.test.jsx index 9896d84f9..f74eebc9c 100644 --- a/test/unit/components/email-step.test.jsx +++ b/test/unit/components/email-step.test.jsx @@ -26,23 +26,23 @@ describe('EmailStep test', () => { }); test('send correct props to formik', () => { - const wrapper = shallowWithIntl(); + const intlWrapper = shallowWithIntl(); - 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(); + const intlWrapper = shallowWithIntl(); // 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(); + const intlWrapper = shallowWithIntl(); // 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(); + const intlWrapper = shallowWithIntl(); // 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( ); - 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( ); - 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( - ); - - 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( ); + /> + ); - 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( ); - 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( ); - 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( ); - 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( ); - 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( ); - 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( ); - const instance = wrapper.dive().instance(); + const instance = intlWrapper.dive().instance(); instance.validateEmailRemotelyWithCache('some-email@some-domain.com') .then(response => {