From 6e83c496c83e0baf7fcb4e75ad79e7a263a155df Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Wed, 23 Oct 2019 10:16:58 -0400 Subject: [PATCH] revise and add registration error step tests --- .../registration-error-step.test.jsx | 65 ++++++++++++++++--- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/test/unit/components/registration-error-step.test.jsx b/test/unit/components/registration-error-step.test.jsx index afad5e63a..e8a74ebd6 100644 --- a/test/unit/components/registration-error-step.test.jsx +++ b/test/unit/components/registration-error-step.test.jsx @@ -9,8 +9,6 @@ describe('RegistrationErrorStep', () => { const getRegistrationErrorStepWrapper = props => { const wrapper = shallowWithIntl( ); @@ -18,31 +16,78 @@ describe('RegistrationErrorStep', () => { .dive(); // unwrap injectIntl() }; - test('when canTryAgain is true, show tryAgain message', () => { - const props = {canTryAgain: true}; + 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(); + const errMsgElement = joinFlowStepInstance.find('#registration-error-msg'); + expect(errMsgElement).toHaveLength(1); + expect(errMsgElement.text()).toEqual('halp there is a errors!!'); + }); + + 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(); + const errMsgElement = joinFlowStepInstance.find('#registration-error-msg'); + expect(errMsgElement).toHaveLength(0); + }); + + test('when canTryAgain is true, show tryAgain message', () => { + const props = { + canTryAgain: true, + errorMsg: 'halp there is a errors!!', + onSubmit: onSubmit + }; const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep); expect(joinFlowStepWrapper).toHaveLength(1); - expect(joinFlowStepWrapper.props().description).toBe('error message'); expect(joinFlowStepWrapper.props().nextButton).toBe('general.tryAgain'); }); test('when canTryAgain is false, show startOver message', () => { - const props = {canTryAgain: false}; + const props = { + canTryAgain: false, + errorMsg: 'halp there is a errors!!', + onSubmit: onSubmit + }; const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep); expect(joinFlowStepWrapper).toHaveLength(1); - expect(joinFlowStepWrapper.props().description).toBe('error message'); expect(joinFlowStepWrapper.props().nextButton).toBe('general.startOver'); }); test('when canTryAgain is missing, show startOver message', () => { - const joinFlowStepWrapper = getRegistrationErrorStepWrapper().find(JoinFlowStep); + const props = { + errorMsg: 'halp there is a errors!!', + onSubmit: onSubmit + }; + const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep); expect(joinFlowStepWrapper).toHaveLength(1); - expect(joinFlowStepWrapper.props().description).toBe('error message'); expect(joinFlowStepWrapper.props().nextButton).toBe('general.startOver'); }); test('when submitted, onSubmit is called', () => { - const joinFlowStepWrapper = getRegistrationErrorStepWrapper().find(JoinFlowStep); + const props = { + canTryAgain: true, + errorMsg: 'halp there is a errors!!', + onSubmit: onSubmit + }; + const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep); joinFlowStepWrapper.props().onSubmit(new Event('event')); // eslint-disable-line no-undef expect(onSubmit).toHaveBeenCalled(); });