diff options
author | Anike Arni <aarni@thoughtworks.com> | 2017-03-31 17:31:32 -0300 |
---|---|---|
committer | Anike Arni <aarni@thoughtworks.com> | 2017-03-31 18:36:57 -0300 |
commit | d7914b9b5640c3d85c6230a032180b2e64520bca (patch) | |
tree | 9427cca56b58a4df98dd1ce6df88a79f72d6f0c5 | |
parent | 7be03150100d319c6d373241f614a29b374cb74d (diff) |
[#935] Submits password to account recovery endpoint
-rw-r--r-- | web-ui/src/account_recovery/new_password_form/new_password_form.js | 67 | ||||
-rw-r--r-- | web-ui/src/account_recovery/new_password_form/new_password_form.spec.js | 10 |
2 files changed, 53 insertions, 24 deletions
diff --git a/web-ui/src/account_recovery/new_password_form/new_password_form.js b/web-ui/src/account_recovery/new_password_form/new_password_form.js index b18bc8ff..4c418900 100644 --- a/web-ui/src/account_recovery/new_password_form/new_password_form.js +++ b/web-ui/src/account_recovery/new_password_form/new_password_form.js @@ -26,30 +26,49 @@ import BackLink from 'src/common/back_link/back_link'; import './new_password_form.scss'; -const submitHandler = code => event => ( - submitForm(event, '/account-recovery', { userCode: code }) -); - -export const NewPasswordForm = ({ t, previous, userCode }) => ( - <form className='account-recovery-form new-password' onSubmit={submitHandler(userCode)}> - <img - className='account-recovery-progress' - src='/public/images/account-recovery/step_3.svg' - alt={t('account-recovery.new-password-form.image-description')} - /> - <h1>{t('account-recovery.new-password-form.title')}</h1> - <InputField - type='password' name='new-password' - label={t('account-recovery.new-password-form.input-label1')} - /> - <InputField - type='password' name='confirm-password' - label={t('account-recovery.new-password-form.input-label2')} - /> - <SubmitButton buttonText={t('account-recovery.button-next')} /> - <BackLink text={t('account-recovery.back')} onClick={previous} /> - </form> -); +export class NewPasswordForm extends React.Component { + submitHandler = (event) => { + submitForm(event, '/account-recovery', { + userCode: this.props.userCode, + password: this.state.password, + confirmation: this.state.confirmation + }); + } + + handlePasswordChange = (event) => { + this.setState({ password: event.target.value }); + } + + handlePasswordConfirmationChange = (event) => { + this.setState({ confirmation: event.target.value }); + } + + render() { + const { t, previous } = this.props; + return ( + <form className='account-recovery-form new-password' onSubmit={this.submitHandler}> + <img + className='account-recovery-progress' + src='/public/images/account-recovery/step_3.svg' + alt={t('account-recovery.new-password-form.image-description')} + /> + <h1>{t('account-recovery.new-password-form.title')}</h1> + <InputField + type='password' name='new-password' + label={t('account-recovery.new-password-form.input-label1')} + onChange={this.handlePasswordChange} + /> + <InputField + type='password' name='confirm-password' + label={t('account-recovery.new-password-form.input-label2')} + onChange={this.handlePasswordConfirmationChange} + /> + <SubmitButton buttonText={t('account-recovery.button-next')} /> + <BackLink text={t('account-recovery.back')} onClick={previous} /> + </form> + ); + } +} NewPasswordForm.propTypes = { t: React.PropTypes.func.isRequired, 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 5ffd9720..26b8651c 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 @@ -42,6 +42,8 @@ describe('NewPasswordForm', () => { describe('Submit', () => { beforeEach(() => { fetchMock.post('/account-recovery', 200); + newPasswordForm.find('InputField[name="new-password"]').simulate('change', { target: { value: '123' } }); + newPasswordForm.find('InputField[name="confirm-password"]').simulate('change', { target: { value: '456' } }); newPasswordForm.find('form').simulate('submit', { preventDefault: expect.createSpy() }); }); @@ -52,5 +54,13 @@ describe('NewPasswordForm', () => { it('sends user code as content', () => { expect(fetchMock.lastOptions('/account-recovery').body).toContain('"userCode":"def234"'); }); + + it('sends password as content', () => { + expect(fetchMock.lastOptions('/account-recovery').body).toContain('"password":"123"'); + }); + + it('sends password confirmation as content', () => { + expect(fetchMock.lastOptions('/account-recovery').body).toContain('"confirmation":"456"'); + }); }); }); |