diff options
author | Thais Siqueira <thais.siqueira@gmail.com> | 2017-03-15 18:59:08 -0300 |
---|---|---|
committer | Thais Siqueira <thais.siqueira@gmail.com> | 2017-03-16 11:57:23 -0300 |
commit | 965ab52b3d3a7a75347cfa58c4bbbe16ea64b014 (patch) | |
tree | 5328a3b6694e6fe5714bd50d31fbd4d5871688a0 /web-ui/src/backup_account/backup_email | |
parent | 923889645b48feceee1086e5002143631b7bcb1e (diff) |
[#924] Validates success on submit
with @anikarni
Diffstat (limited to 'web-ui/src/backup_account/backup_email')
-rw-r--r-- | web-ui/src/backup_account/backup_email/backup_email.js | 4 | ||||
-rw-r--r-- | web-ui/src/backup_account/backup_email/backup_email.spec.js | 13 |
2 files changed, 10 insertions, 7 deletions
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 32d17935..09863950 100644 --- a/web-ui/src/backup_account/backup_email/backup_email.js +++ b/web-ui/src/backup_account/backup_email/backup_email.js @@ -54,9 +54,7 @@ export class BackupEmail extends React.Component { body: JSON.stringify({ csrftoken: [browser.getCookie('XSRF-TOKEN')] }) - }); - - this.props.onSubmit(); + }).then(() => this.props.onSubmit('success')); } render() { diff --git a/web-ui/src/backup_account/backup_email/backup_email.spec.js b/web-ui/src/backup_account/backup_email/backup_email.spec.js index 66dc8df6..48199738 100644 --- a/web-ui/src/backup_account/backup_email/backup_email.spec.js +++ b/web-ui/src/backup_account/backup_email/backup_email.spec.js @@ -8,10 +8,12 @@ import browser from 'helpers/browser'; describe('BackupEmail', () => { let backupEmail; let mockOnSubmit; + let mockTranslations; beforeEach(() => { mockOnSubmit = expect.createSpy(); - const mockTranslations = key => key; + + mockTranslations = key => key; backupEmail = shallow(<BackupEmail t={mockTranslations} onSubmit={mockOnSubmit} />); }); @@ -85,10 +87,13 @@ describe('BackupEmail', () => { describe('Submit', () => { let preventDefaultSpy; - beforeEach(() => { + beforeEach((done) => { + mockOnSubmit = expect.createSpy().andCall(() => done()); preventDefaultSpy = expect.createSpy(); expect.spyOn(browser, 'getCookie').andReturn('abc123'); + backupEmail = shallow(<BackupEmail t={mockTranslations} onSubmit={mockOnSubmit} />); + fetchMock.post('/backup-account', 204); backupEmail.find('form').simulate('submit', { preventDefault: preventDefaultSpy }); }); @@ -113,8 +118,8 @@ describe('BackupEmail', () => { expect(preventDefaultSpy).toHaveBeenCalled(); }); - it('calls onSubmit from props', () => { - expect(mockOnSubmit).toHaveBeenCalled(); + it('calls onSubmit from props when success', () => { + expect(mockOnSubmit).toHaveBeenCalledWith('success'); }); }); }); |