summaryrefslogtreecommitdiff
path: root/web-ui/src/backup_account/backup_email/backup_email.spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'web-ui/src/backup_account/backup_email/backup_email.spec.js')
-rw-r--r--web-ui/src/backup_account/backup_email/backup_email.spec.js79
1 files changed, 39 insertions, 40 deletions
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 ce357bf7..65fad608 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
@@ -84,61 +84,60 @@ describe('BackupEmail', () => {
});
});
- describe('Submit on success', () => {
+ describe('Submit', () => {
let preventDefaultSpy;
- beforeEach((done) => {
- mockOnSubmit = expect.createSpy().andCall(() => done());
+ beforeEach(() => {
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 });
});
- it('posts backup email', () => {
- expect(fetchMock.called('/backup-account')).toBe(true, 'Backup account POST was not called');
- });
+ context('on success', () => {
+ beforeEach((done) => {
+ mockOnSubmit = expect.createSpy().andCall(() => done());
+ expect.spyOn(browser, 'getCookie').andReturn('abc123');
- it('sends csrftoken as content', () => {
- expect(fetchMock.lastOptions('/backup-account').body).toContain('"csrftoken":["abc123"]');
- });
+ fetchMock.post('/backup-account', 204);
+ backupEmail = shallow(<BackupEmail t={mockTranslations} onSubmit={mockOnSubmit} />);
+ backupEmail.find('form').simulate('submit', { preventDefault: preventDefaultSpy });
+ });
- it('sends content-type header', () => {
- expect(fetchMock.lastOptions('/backup-account').headers['Content-Type']).toEqual('application/json');
- });
+ it('posts backup email', () => {
+ expect(fetchMock.called('/backup-account')).toBe(true, 'Backup account POST was not called');
+ });
- it('sends same origin headers', () => {
- expect(fetchMock.lastOptions('/backup-account').credentials).toEqual('same-origin');
- });
+ it('sends csrftoken as content', () => {
+ expect(fetchMock.lastOptions('/backup-account').body).toContain('"csrftoken":["abc123"]');
+ });
- it('prevents default call to refresh page', () => {
- expect(preventDefaultSpy).toHaveBeenCalled();
- });
+ it('sends content-type header', () => {
+ expect(fetchMock.lastOptions('/backup-account').headers['Content-Type']).toEqual('application/json');
+ });
- it('calls onSubmit from props with success', () => {
- expect(mockOnSubmit).toHaveBeenCalledWith('success');
- });
- });
+ it('sends same origin headers', () => {
+ expect(fetchMock.lastOptions('/backup-account').credentials).toEqual('same-origin');
+ });
- describe('Submit on error', () => {
- let preventDefaultSpy;
+ it('prevents default call to refresh page', () => {
+ expect(preventDefaultSpy).toHaveBeenCalled();
+ });
- beforeEach((done) => {
- mockOnSubmit = expect.createSpy().andCall(() => done());
- preventDefaultSpy = expect.createSpy();
- expect.spyOn(browser, 'getCookie').andReturn('abc123');
+ it('calls onSubmit from props with success', () => {
+ expect(mockOnSubmit).toHaveBeenCalledWith('success');
+ });
+ });
- backupEmail = shallow(<BackupEmail t={mockTranslations} onSubmit={mockOnSubmit} />);
+ context('on error', () => {
+ beforeEach((done) => {
+ mockOnSubmit = expect.createSpy().andCall(() => done());
- fetchMock.post('/backup-account', 500);
- backupEmail.find('form').simulate('submit', { preventDefault: preventDefaultSpy });
- });
+ fetchMock.post('/backup-account', 500);
+ backupEmail = shallow(<BackupEmail t={mockTranslations} onSubmit={mockOnSubmit} />);
+ backupEmail.find('form').simulate('submit', { preventDefault: preventDefaultSpy });
+ });
- it('calls onSubmit from props with error', () => {
- expect(mockOnSubmit).toHaveBeenCalledWith('error');
+ it('calls onSubmit from props with error', () => {
+ expect(mockOnSubmit).toHaveBeenCalledWith('error');
+ });
});
});