From f4229e63e315654032dc3f0c8a69e2892c72758c Mon Sep 17 00:00:00 2001 From: Thais Siqueira Date: Fri, 31 Mar 2017 14:10:30 -0300 Subject: [#927] Implements sending recovery code by email. with @tayanefernandes --- .../src/backup_account/backup_email/backup_email.js | 12 +++++++++--- .../backup_account/backup_email/backup_email.spec.js | 20 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'web-ui') diff --git a/web-ui/src/backup_account/backup_email/backup_email.js b/web-ui/src/backup_account/backup_email/backup_email.js index 9d622d8d..8fa71191 100644 --- a/web-ui/src/backup_account/backup_email/backup_email.js +++ b/web-ui/src/backup_account/backup_email/backup_email.js @@ -31,7 +31,7 @@ export class BackupEmail extends React.Component { constructor(props) { super(props); - this.state = { error: '', submitButtonDisabled: true }; + this.state = { error: '', submitButtonDisabled: true, backupEmail: '' }; } validateEmail = (event) => { @@ -54,7 +54,8 @@ export class BackupEmail extends React.Component { 'Content-Type': 'application/json' }, body: JSON.stringify({ - csrftoken: [browser.getCookie('XSRF-TOKEN')] + csrftoken: [browser.getCookie('XSRF-TOKEN')], + backupEmail: this.state.backupEmail }) }).then((response) => { if (response.ok) { @@ -65,6 +66,11 @@ export class BackupEmail extends React.Component { }); }; + handleChange = (event) => { + this.setState({ backupEmail: event.target.value }); + this.validateEmail(event); + } + render() { const t = this.props.t; return ( @@ -78,7 +84,7 @@ export class BackupEmail extends React.Component {

{t('backup-account.backup-email.title')}

{t('backup-account.backup-email.paragraph1')}

{t('backup-account.backup-email.paragraph2')}

- + { let backupEmail; let mockOnSubmit; let mockTranslations; + let backupEmailInstance; beforeEach(() => { mockOnSubmit = expect.createSpy(); @@ -30,8 +31,6 @@ describe('BackupEmail', () => { }); describe('Email validation', () => { - let backupEmailInstance; - beforeEach(() => { backupEmailInstance = backupEmail.instance(); }); @@ -84,6 +83,17 @@ describe('BackupEmail', () => { }); }); + describe('Email changing handler', () => { + beforeEach(() => { + backupEmailInstance = backupEmail.instance(); + }); + + it('sets user backup email in the state', () => { + backupEmailInstance.handleChange({ target: { value: 'test@test.com' } }); + expect(backupEmailInstance.state.backupEmail).toEqual('test@test.com'); + }); + }); + describe('Submit', () => { let preventDefaultSpy; @@ -98,6 +108,8 @@ describe('BackupEmail', () => { fetchMock.post('/backup-account', 204); backupEmail = shallow(); + + backupEmail.find('InputField').simulate('change', { target: { value: 'test@test.com' } }); backupEmail.find('form').simulate('submit', { preventDefault: preventDefaultSpy }); }); @@ -109,6 +121,10 @@ describe('BackupEmail', () => { expect(fetchMock.lastOptions('/backup-account').body).toContain('"csrftoken":["abc123"]'); }); + it('sends user email as content', () => { + expect(fetchMock.lastOptions('/backup-account').body).toContain('"backupEmail":"test@test.com"'); + }); + it('sends content-type header', () => { expect(fetchMock.lastOptions('/backup-account').headers['Content-Type']).toEqual('application/json'); }); -- cgit v1.2.3