diff options
Diffstat (limited to 'web-ui/src/account_recovery/new_password_form/new_password_form.spec.js')
-rw-r--r-- | web-ui/src/account_recovery/new_password_form/new_password_form.spec.js | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/web-ui/src/account_recovery/new_password_form/new_password_form.spec.js b/web-ui/src/account_recovery/new_password_form/new_password_form.spec.js index b57dd42e..c29487a7 100644 --- a/web-ui/src/account_recovery/new_password_form/new_password_form.spec.js +++ b/web-ui/src/account_recovery/new_password_form/new_password_form.spec.js @@ -65,8 +65,93 @@ describe('NewPasswordForm', () => { expect(fetchMock.lastOptions('/account-recovery').body).toContain('"password":"123"'); }); - it('sends password confirmation as content', () => { - expect(fetchMock.lastOptions('/account-recovery').body).toContain('"confirmation":"456"'); + it('sends confirm password as content', () => { + expect(fetchMock.lastOptions('/account-recovery').body).toContain('"confirmPassword":"456"'); + }); + }); + + describe('Password validation', () => { + let newPasswordFormInstance; + + beforeEach(() => { + newPasswordFormInstance = newPasswordForm.instance(); + }); + + it('verifies initial state', () => { + expect(newPasswordFormInstance.state.errorPassword).toEqual(''); + expect(newPasswordFormInstance.state.errorConfirmPassword).toEqual(''); + expect(newPasswordForm.find('SubmitButton').props().disabled).toBe(true); + }); + + context('with valid fields', () => { + beforeEach(() => { + newPasswordFormInstance.validatePassword('12345678', '12345678'); + }); + + it('does not set error in state', () => { + expect(newPasswordFormInstance.state.errorPassword).toEqual(''); + expect(newPasswordFormInstance.state.errorConfirmPassword).toEqual(''); + }); + + it('enables submit button', () => { + expect(newPasswordForm.find('SubmitButton').props().disabled).toBe(false); + }); + }); + + context('with invalid password', () => { + beforeEach(() => { + newPasswordFormInstance.validatePassword('1234', ''); + }); + + it('sets password error in state', () => { + expect(newPasswordFormInstance.state.errorPassword).toEqual('account-recovery.new-password-form.error.invalid-password'); + }); + + it('disables submit button', () => { + expect(newPasswordForm.find('SubmitButton').props().disabled).toBe(true); + }); + }); + + context('with invalid confirm password', () => { + beforeEach(() => { + newPasswordFormInstance.validatePassword('12345678', '1234'); + }); + + it('sets confirm password error in state', () => { + expect(newPasswordFormInstance.state.errorConfirmPassword).toEqual('account-recovery.new-password-form.error.invalid-confirm-password'); + }); + + it('disables submit button', () => { + expect(newPasswordForm.find('SubmitButton').props().disabled).toBe(true); + }); + }); + + context('with empty fields', () => { + it('does not set error in state if both empty', () => { + newPasswordFormInstance.validatePassword('', ''); + expect(newPasswordFormInstance.state.errorPassword).toEqual(''); + expect(newPasswordFormInstance.state.errorConfirmPassword).toEqual(''); + }); + + it('does not set confirm password error in state if empty', () => { + newPasswordFormInstance.validatePassword('12345678', ''); + expect(newPasswordFormInstance.state.errorConfirmPassword).toEqual(''); + }); + + it('sets confirm password error in state if not empty', () => { + newPasswordFormInstance.validatePassword('', '12345678'); + expect(newPasswordFormInstance.state.errorConfirmPassword).toEqual('account-recovery.new-password-form.error.invalid-confirm-password'); + }); + + it('disables submit button if empty confirm password', () => { + newPasswordFormInstance.validatePassword('12345678', ''); + expect(newPasswordForm.find('SubmitButton').props().disabled).toBe(true); + }); + + it('disables submit button if empty password', () => { + newPasswordFormInstance.validatePassword('', '12345678'); + expect(newPasswordForm.find('SubmitButton').props().disabled).toBe(true); + }); }); it('calls next handler on success', () => { |