diff options
Diffstat (limited to 'web-ui/src/account_recovery/new_password_form')
-rw-r--r-- | web-ui/src/account_recovery/new_password_form/new_password_form.js | 68 | ||||
-rw-r--r-- | web-ui/src/account_recovery/new_password_form/new_password_form.spec.js | 28 |
2 files changed, 74 insertions, 22 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 f1097b0b..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 @@ -15,39 +15,65 @@ * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. */ +import 'isomorphic-fetch'; import React from 'react'; import { translate } from 'react-i18next'; +import { submitForm } from 'src/common/util'; import InputField from 'src/common/input_field/input_field'; import SubmitButton from 'src/common/submit_button/submit_button'; import BackLink from 'src/common/back_link/back_link'; import './new_password_form.scss'; -export const NewPasswordForm = ({ t, previous }) => ( - <form className='account-recovery-form new-password'> - <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, - previous: React.PropTypes.func.isRequired + previous: React.PropTypes.func.isRequired, + userCode: React.PropTypes.string.isRequired }; export default translate('', { wait: true })(NewPasswordForm); 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 d2bd350c..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 @@ -1,6 +1,7 @@ import { shallow } from 'enzyme'; import expect from 'expect'; import React from 'react'; +import fetchMock from 'fetch-mock'; import { NewPasswordForm } from './new_password_form'; describe('NewPasswordForm', () => { @@ -11,7 +12,7 @@ describe('NewPasswordForm', () => { const mockTranslations = key => key; mockPrevious = expect.createSpy(); newPasswordForm = shallow( - <NewPasswordForm t={mockTranslations} previous={mockPrevious} /> + <NewPasswordForm t={mockTranslations} previous={mockPrevious} userCode='def234' /> ); }); @@ -37,4 +38,29 @@ describe('NewPasswordForm', () => { newPasswordForm.find('BackLink').simulate('click'); expect(mockPrevious).toHaveBeenCalled(); }); + + 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() }); + }); + + it('posts to account recovery', () => { + expect(fetchMock.called('/account-recovery')).toBe(true, 'POST was not called'); + }); + + 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"'); + }); + }); }); |