diff options
Diffstat (limited to 'web-ui/src/account_recovery')
16 files changed, 981 insertions, 0 deletions
diff --git a/web-ui/src/account_recovery/account_recovery.html b/web-ui/src/account_recovery/account_recovery.html new file mode 100644 index 00000000..35054455 --- /dev/null +++ b/web-ui/src/account_recovery/account_recovery.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="icon" type="image/png" href="public/images/favicon.png" /> + <meta charset="utf-8"/> + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> + <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/> + <title>Pixelated</title> + </head> + <body> + <div id="root"/> + <script type="text/javascript" src="/public/account_recovery.js"></script> + </body> +</html> diff --git a/web-ui/src/account_recovery/account_recovery.js b/web-ui/src/account_recovery/account_recovery.js new file mode 100644 index 00000000..19b7c19c --- /dev/null +++ b/web-ui/src/account_recovery/account_recovery.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { render } from 'react-dom'; +import a11y from 'react-a11y'; + +import App from 'src/common/app'; +import PageWrapper from './page'; + +require('es6-promise').polyfill(); + +if (process.env.NODE_ENV === 'development') a11y(React); + +render( + <App child={<PageWrapper />} />, + document.getElementById('root') +); diff --git a/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.js b/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.js new file mode 100644 index 00000000..5b9da350 --- /dev/null +++ b/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { translate } from 'react-i18next'; + +import InputField from 'src/common/input_field/input_field'; +import SubmitButton from 'src/common/submit_button/submit_button'; + +import './admin_recovery_code_form.scss'; + +export const AdminRecoveryCodeForm = ({ t, next }) => ( + <form className='account-recovery-form admin-code' onSubmit={next}> + <img + className='account-recovery-progress' + src='/public/images/account-recovery/step_1.svg' + alt={t('account-recovery.admin-form.image-description')} + /> + <h1>{t('account-recovery.admin-form.title')}</h1> + <img + className='admin-code-image' + src='/public/images/account-recovery/admins_contact.svg' + alt='' + /> + <ul> + <li>{t('account-recovery.admin-form.tip1')}</li> + <li>{t('account-recovery.admin-form.tip2')}</li> + <li>{t('account-recovery.admin-form.tip3')}</li> + </ul> + <InputField name='admin-code' label={t('account-recovery.admin-form.input-label')} /> + <SubmitButton buttonText={t('account-recovery.button-next')} /> + </form> +); + +AdminRecoveryCodeForm.propTypes = { + t: React.PropTypes.func.isRequired, + next: React.PropTypes.func.isRequired +}; + +export default translate('', { wait: true })(AdminRecoveryCodeForm); diff --git a/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.scss b/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.scss new file mode 100644 index 00000000..6dcbcc67 --- /dev/null +++ b/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.scss @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +.admin-code-image { + margin: 1em 0; + align-self: center; + height: 2.7em; +} diff --git a/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.spec.js b/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.spec.js new file mode 100644 index 00000000..73c4c1e0 --- /dev/null +++ b/web-ui/src/account_recovery/admin_recovery_code_form/admin_recovery_code_form.spec.js @@ -0,0 +1,38 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import { AdminRecoveryCodeForm } from './admin_recovery_code_form'; + +describe('AdminRecoveryCodeForm', () => { + let adminRecoveryCodeForm; + let mockNext; + + beforeEach(() => { + const mockTranslations = key => key; + mockNext = expect.createSpy(); + adminRecoveryCodeForm = shallow( + <AdminRecoveryCodeForm t={mockTranslations} next={mockNext} /> + ); + }); + + it('renders title for admin recovery code', () => { + expect(adminRecoveryCodeForm.find('h1').text()).toEqual('account-recovery.admin-form.title'); + }); + + it('renders tips for retrieving recovery code', () => { + expect(adminRecoveryCodeForm.find('li').length).toEqual(3); + }); + + it('renders input field for admin code', () => { + expect(adminRecoveryCodeForm.find('InputField').props().name).toEqual('admin-code'); + }); + + it('renders button for next step', () => { + expect(adminRecoveryCodeForm.find('SubmitButton').props().buttonText).toEqual('account-recovery.button-next'); + }); + + it('submits form to next step', () => { + adminRecoveryCodeForm.find('form').simulate('submit'); + expect(mockNext).toHaveBeenCalled(); + }); +}); diff --git a/web-ui/src/account_recovery/backup_account_step/backup_account_step.js b/web-ui/src/account_recovery/backup_account_step/backup_account_step.js new file mode 100644 index 00000000..891b45ec --- /dev/null +++ b/web-ui/src/account_recovery/backup_account_step/backup_account_step.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ +import React from 'react'; +import { translate } from 'react-i18next'; +import LinkButton from 'src/common/link_button/link_button'; + +export const BackupAccountStep = ({ t }) => ( + <div className='account-recovery-form backup-account'> + <img + className='account-recovery-progress' + src='/public/images/account-recovery/step_4.svg' + alt={t('account-recovery.backup-account-step.image-description')} + /> + <h1>{t('account-recovery.backup-account-step.title')}</h1> + <LinkButton + buttonText={t('account-recovery.backup-account-step.buttonText')} + href='/backup-account' + /> + </div> +); + +BackupAccountStep.propTypes = { + t: React.PropTypes.func.isRequired +}; + +export default translate('', { wait: true })(BackupAccountStep); diff --git a/web-ui/src/account_recovery/backup_account_step/backup_account_step.spec.js b/web-ui/src/account_recovery/backup_account_step/backup_account_step.spec.js new file mode 100644 index 00000000..38a5e560 --- /dev/null +++ b/web-ui/src/account_recovery/backup_account_step/backup_account_step.spec.js @@ -0,0 +1,27 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import LinkButton from 'src/common/link_button/link_button'; +import { BackupAccountStep } from './backup_account_step'; + +describe('BackupAccountStep', () => { + let backupAccountStep; + + beforeEach(() => { + const mockTranslations = key => key; + backupAccountStep = shallow(<BackupAccountStep t={mockTranslations} />); + }); + + it('renders title for backup account step', () => { + expect(backupAccountStep.find('h1').text()).toEqual('account-recovery.backup-account-step.title'); + }); + + it('renders submit button with given href', () => { + expect(backupAccountStep.find(LinkButton).props().href).toEqual('/backup-account'); + }); + + it('renders submit button with given button text', () => { + expect(backupAccountStep.find(LinkButton).props().buttonText) + .toEqual('account-recovery.backup-account-step.buttonText'); + }); +}); 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 new file mode 100644 index 00000000..5e1e72c9 --- /dev/null +++ b/web-ui/src/account_recovery/new_password_form/new_password_form.js @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import 'isomorphic-fetch'; +import React from 'react'; +import { translate } from 'react-i18next'; +import validator from 'validator'; + +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 class NewPasswordForm extends React.Component { + + constructor(props) { + super(props); + this.state = { + submitButtonDisabled: true, + password: '', + errorPassword: '', + confirmPassword: '', + errorConfirmPassword: '' + }; + } + + submitHandler = (event) => { + event.preventDefault(); + submitForm(event, '/account-recovery', { + userCode: this.props.userCode, + password: this.state.password, + confirmPassword: this.state.confirmPassword + }).then(() => this.props.next()); + } + + handleChangePassword = (event) => { + this.setState({ password: event.target.value }); + this.validatePassword(event.target.value, this.state.confirmPassword); + }; + + handleChangeConfirmPassword = (event) => { + this.setState({ confirmPassword: event.target.value }); + this.validatePassword(this.state.password, event.target.value); + }; + + validatePassword = (password, confirmPassword) => { + const emptyPassword = validator.isEmpty(password); + const validPassword = validator.isLength(password, { min: 8, max: 9999 }); + const emptyConfirmPassword = validator.isEmpty(confirmPassword); + const validConfirmPassword = confirmPassword === password; + + const t = this.props.t; + + this.setState({ + errorPassword: !emptyPassword && !validPassword ? t('account-recovery.new-password-form.error.invalid-password') : '', + errorConfirmPassword: !emptyConfirmPassword && !validConfirmPassword ? t('account-recovery.new-password-form.error.invalid-confirm-password') : '', + submitButtonDisabled: !validPassword || !validConfirmPassword + }); + }; + + 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' value={this.state.password} + label={t('account-recovery.new-password-form.input-label1')} + errorText={this.state.errorPassword} onChange={this.handleChangePassword} + /> + <InputField + type='password' name='confirm-password' value={this.state.confirmPassword} + label={t('account-recovery.new-password-form.input-label2')} + errorText={this.state.errorConfirmPassword} onChange={this.handleChangeConfirmPassword} + /> + <SubmitButton buttonText={t('account-recovery.button-next')} disabled={this.state.submitButtonDisabled} /> + <BackLink text={t('account-recovery.back')} onClick={previous} /> + </form> + ); + } +} + +NewPasswordForm.propTypes = { + t: React.PropTypes.func.isRequired, + next: 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.scss b/web-ui/src/account_recovery/new_password_form/new_password_form.scss new file mode 100644 index 00000000..77623262 --- /dev/null +++ b/web-ui/src/account_recovery/new_password_form/new_password_form.scss @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +.new-password { + .input-field-group:first-of-type { + margin-bottom: 0; + } +} 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 new file mode 100644 index 00000000..c29487a7 --- /dev/null +++ b/web-ui/src/account_recovery/new_password_form/new_password_form.spec.js @@ -0,0 +1,161 @@ +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', () => { + let newPasswordForm; + let mockPrevious; + let mockNext; + let mockTranslations; + + beforeEach(() => { + mockTranslations = key => key; + mockPrevious = expect.createSpy(); + newPasswordForm = shallow( + <NewPasswordForm t={mockTranslations} previous={mockPrevious} userCode='def234' /> + ); + }); + + it('renders title for new password form', () => { + expect(newPasswordForm.find('h1').text()).toEqual('account-recovery.new-password-form.title'); + }); + + it('renders input for new password', () => { + expect(newPasswordForm.find('InputField').at(0).props().type).toEqual('password'); + expect(newPasswordForm.find('InputField').at(0).props().label).toEqual('account-recovery.new-password-form.input-label1'); + }); + + it('renders input to confirm new password', () => { + expect(newPasswordForm.find('InputField').at(1).props().type).toEqual('password'); + expect(newPasswordForm.find('InputField').at(1).props().label).toEqual('account-recovery.new-password-form.input-label2'); + }); + + it('renders submit button', () => { + expect(newPasswordForm.find('SubmitButton').props().buttonText).toEqual('account-recovery.button-next'); + }); + + it('returns to previous step on link click', () => { + newPasswordForm.find('BackLink').simulate('click'); + expect(mockPrevious).toHaveBeenCalled(); + }); + + describe('Submit', () => { + beforeEach((done) => { + mockNext = expect.createSpy().andCall(() => done()); + newPasswordForm = shallow( + <NewPasswordForm t={mockTranslations} previous={mockPrevious} userCode='def234' next={mockNext} /> + ); + 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 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', () => { + expect(mockNext).toHaveBeenCalled(); + }); + }); +}); diff --git a/web-ui/src/account_recovery/page.js b/web-ui/src/account_recovery/page.js new file mode 100644 index 00000000..94927a16 --- /dev/null +++ b/web-ui/src/account_recovery/page.js @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { translate } from 'react-i18next'; +import DocumentTitle from 'react-document-title'; +import Header from 'src/common/header/header'; +import AdminRecoveryCodeForm from 'src/account_recovery/admin_recovery_code_form/admin_recovery_code_form'; +import UserRecoveryCodeForm from 'src/account_recovery/user_recovery_code_form/user_recovery_code_form'; +import NewPasswordForm from 'src/account_recovery/new_password_form/new_password_form'; +import BackupAccountStep from 'src/account_recovery/backup_account_step/backup_account_step'; +import Footer from 'src/common/footer/footer'; + +import 'font-awesome/scss/font-awesome.scss'; +import './page.scss'; + + +export class Page extends React.Component { + + constructor(props) { + super(props); + this.state = { step: 0, userCode: '' }; + } + + nextStep = (event) => { + if (event) { + event.preventDefault(); + } + this.setState({ step: this.state.step + 1 }); + } + + previousStep = () => { + this.setState({ step: this.state.step - 1 }); + } + + saveUserCode = (event) => { + this.setState({ userCode: event.target.value }); + } + + steps = () => ({ + 0: <AdminRecoveryCodeForm next={this.nextStep} />, + 1: + (<UserRecoveryCodeForm + previous={this.previousStep} + next={this.nextStep} + saveCode={this.saveUserCode} + />), + 2: + (<NewPasswordForm + previous={this.previousStep} + userCode={this.state.userCode} + next={this.nextStep} + />), + 3: <BackupAccountStep /> + }) + + mainContent = () => this.steps()[this.state.step]; + + render() { + const t = this.props.t; + return ( + <DocumentTitle title={t('account-recovery.page-title')}> + <div className='page'> + <Header /> + <section> + <div className='container'> + {this.mainContent()} + </div> + </section> + <Footer /> + </div> + </DocumentTitle> + ); + } +} + +Page.propTypes = { + t: React.PropTypes.func.isRequired +}; + +export default translate('', { wait: true })(Page); diff --git a/web-ui/src/account_recovery/page.scss b/web-ui/src/account_recovery/page.scss new file mode 100644 index 00000000..378bf63c --- /dev/null +++ b/web-ui/src/account_recovery/page.scss @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +@import "~scss/vendor/reset"; +@import "~scss/base/colors"; +@import "~scss/base/fonts"; + +html, body, #root { + height: 100%; +} + +body, #root { + min-height: 100%; +} + +a { + text-decoration: none; +} + +.container { + background: $white; + margin: 3% auto; + box-shadow: 0 2px 3px 0 $shadow; + width: 84%; + padding: 6% 5%; +} + +.page { + font-family: "Open Sans", "Microsoft YaHei", "Hiragino Sans GB", "Hiragino Sans GB W3", "微软雅黑", "Helvetica Neue", Arial, sans-serif; + background: $dark_blue; /* For browsers that do not support gradients */ + background: -webkit-linear-gradient(left top, $dark_blue, $middle_blue); /* For Safari 5.1 to 6.0 */ + background: -o-linear-gradient(bottom right, $dark_blue, $middle_blue); /* For Opera 11.1 to 12.0 */ + background: -moz-linear-gradient(bottom right, $dark_blue, $middle_blue); /* For Firefox 3.6 to 15 */ + background: linear-gradient(to bottom right, $dark_blue, $middle_blue); /* Standard syntax */ + color: $dark_grey_text; + min-height: 100%; + display: flex; + flex-direction: column; +} + +section { + flex: 1 0 auto; +} + +h1 { + font-size: 1.3em; + font-weight: 600; + text-align: center; +} + +p { + margin-top: 0.5em; + margin-bottom: 0.5em; +} + +.account-recovery-form { + display: flex; + flex-direction: column; + + .account-recovery-progress { + align-self: center; + width: 100%; + } + + .input-field-group { + margin-top: 0; + } +} + +@media only screen and (min-width : 500px) { + body { + font-size: 1.3em; + } + + .account-recovery-form { + align-items: center; + + .account-recovery-progress { + margin-bottom: 1.4em; + width: 80%; + } + + h1 { + width: 80%; + } + } +} + +@media only screen and (min-width : 960px) { + .container { + width: 60%; + max-width: 700px; + padding: 3em; + } + + .account-recovery-form { + h1 { + max-width: 80%; + width: auto; + } + + .input-field-group, .submit-button { + width: 60%; + align-self: center; + } + } +} diff --git a/web-ui/src/account_recovery/page.spec.js b/web-ui/src/account_recovery/page.spec.js new file mode 100644 index 00000000..8e4ccc33 --- /dev/null +++ b/web-ui/src/account_recovery/page.spec.js @@ -0,0 +1,91 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; + +import { Page } from 'src/account_recovery/page'; +import Header from 'src/common/header/header'; +import Footer from 'src/common/footer/footer'; + +import AdminRecoveryCodeFormWrapper from './admin_recovery_code_form/admin_recovery_code_form'; +import UserRecoveryCodeFormWrapper from './user_recovery_code_form/user_recovery_code_form'; +import NewPasswordFormWrapper from './new_password_form/new_password_form'; +import BackupAccountStepWrapper from './backup_account_step/backup_account_step'; + +describe('Account Recovery Page', () => { + let page; + let pageInstance; + + beforeEach(() => { + const mockTranslations = key => key; + page = shallow(<Page t={mockTranslations} />); + pageInstance = page.instance(); + }); + + it('renders account recovery page title', () => { + expect(page.props().title).toEqual('account-recovery.page-title'); + }); + + it('renders header without logout button', () => { + expect(page.find(Header).props().renderLogout).toEqual(false); + }); + + it('renders footer', () => { + expect(page.find(Footer).length).toEqual(1); + }); + + it('saves user code', () => { + pageInstance.saveUserCode({ target: { value: '123' } }); + expect(pageInstance.state.userCode).toEqual('123'); + }); + + it('prevents default event before next', () => { + const eventSpy = expect.createSpy(); + pageInstance.nextStep({ preventDefault: eventSpy }); + + expect(eventSpy).toHaveBeenCalled(); + }); + + context('main content', () => { + it('renders admin recovery code form as default form', () => { + expect(page.find(AdminRecoveryCodeFormWrapper).length).toEqual(1); + expect(page.find(UserRecoveryCodeFormWrapper).length).toEqual(0); + expect(page.find(NewPasswordFormWrapper).length).toEqual(0); + }); + + it('renders user recovery code form when admin code submitted', () => { + pageInstance.nextStep(); + + expect(page.find(UserRecoveryCodeFormWrapper).length).toEqual(1); + }); + + it('returns to admin code form on user code form back link', () => { + pageInstance.nextStep(); + pageInstance.previousStep(); + + expect(page.find(AdminRecoveryCodeFormWrapper).length).toEqual(1); + }); + + it('renders new password form when user code submitted', () => { + pageInstance.nextStep(); + pageInstance.nextStep(); + + expect(page.find(NewPasswordFormWrapper).length).toEqual(1); + }); + + it('returns to user code form on new password form back link', () => { + pageInstance.nextStep(); + pageInstance.nextStep(); + pageInstance.previousStep(); + + expect(page.find(UserRecoveryCodeFormWrapper).length).toEqual(1); + }); + + it('renders backup account form after submitting new password', () => { + pageInstance.nextStep(); + pageInstance.nextStep(); + pageInstance.nextStep(); + + expect(page.find(BackupAccountStepWrapper).length).toEqual(1); + }); + }); +}); diff --git a/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.js b/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.js new file mode 100644 index 00000000..c39c894d --- /dev/null +++ b/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { translate } from 'react-i18next'; + +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 './user_recovery_code_form.scss'; + +export const UserRecoveryCodeForm = ({ t, previous, next, saveCode }) => ( + <form className='account-recovery-form user-code' onSubmit={next}> + <img + className='account-recovery-progress' + src='/public/images/account-recovery/step_2.svg' + alt={t('account-recovery.user-form.image-description')} + /> + <h1>{t('account-recovery.user-form.title')}</h1> + <div className='user-code-form-content'> + <img + className='user-code-image' + src='/public/images/account-recovery/codes.svg' + alt='' + /> + <p>{t('account-recovery.user-form.description')}</p> + </div> + <InputField + name='user-code' label={t('account-recovery.user-form.input-label')} + onChange={saveCode} + /> + <SubmitButton buttonText={t('account-recovery.button-next')} /> + <BackLink text={t('account-recovery.back')} onClick={previous} /> + </form> +); + +UserRecoveryCodeForm.propTypes = { + t: React.PropTypes.func.isRequired, + previous: React.PropTypes.func.isRequired, + next: React.PropTypes.func.isRequired, + saveCode: React.PropTypes.func.isRequired +}; + +export default translate('', { wait: true })(UserRecoveryCodeForm); diff --git a/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.scss b/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.scss new file mode 100644 index 00000000..55f5621b --- /dev/null +++ b/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.scss @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +.user-code-form-content { + display: flex; + flex-direction: column; + align-items: center; +} + +.user-code-image { + margin: 1em 0; + align-self: center; + height: 4em; +} + +@media only screen and (min-width : 500px) { + .user-code-form-content { + flex-direction: row; + width: 80%; + } + + .user-code-image { + margin-right: 1.6em; + } +} diff --git a/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.spec.js b/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.spec.js new file mode 100644 index 00000000..386c3a19 --- /dev/null +++ b/web-ui/src/account_recovery/user_recovery_code_form/user_recovery_code_form.spec.js @@ -0,0 +1,55 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import { UserRecoveryCodeForm } from './user_recovery_code_form'; + +describe('UserRecoveryCodeForm', () => { + let userRecoveryCodeForm; + let mockNext; + let mockPrevious; + let mockSaveCode; + + beforeEach(() => { + const mockTranslations = key => key; + mockNext = expect.createSpy(); + mockPrevious = expect.createSpy(); + mockSaveCode = expect.createSpy(); + userRecoveryCodeForm = shallow( + <UserRecoveryCodeForm + t={mockTranslations} next={mockNext} + previous={mockPrevious} saveCode={mockSaveCode} + /> + ); + }); + + it('renders title for user recovery code', () => { + expect(userRecoveryCodeForm.find('h1').text()).toEqual('account-recovery.user-form.title'); + }); + + it('renders description', () => { + expect(userRecoveryCodeForm.find('p').text()).toEqual('account-recovery.user-form.description'); + }); + + it('renders input for user code', () => { + expect(userRecoveryCodeForm.find('InputField').props().label).toEqual('account-recovery.user-form.input-label'); + }); + + it('renders submit button', () => { + expect(userRecoveryCodeForm.find('SubmitButton').props().buttonText).toEqual('account-recovery.button-next'); + }); + + it('submits form to next step', () => { + userRecoveryCodeForm.find('form').simulate('submit'); + expect(mockNext).toHaveBeenCalled(); + }); + + it('returns to previous step on link click', () => { + userRecoveryCodeForm.find('BackLink').simulate('click'); + expect(mockPrevious).toHaveBeenCalled(); + }); + + it('saves code on input change', () => { + userRecoveryCodeForm.find('InputField').simulate('change', '123'); + expect(mockSaveCode).toHaveBeenCalledWith('123'); + }); +}); |