summaryrefslogtreecommitdiff
path: root/web-ui/src/backup_account/page.spec.js
blob: 8c014ee45c7edd0e2cfa0324291aae6c60b8c5d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { shallow } from 'enzyme';
import expect from 'expect';
import React from 'react';
import { Page } from 'src/backup_account/page';
import BackupEmail from 'src/backup_account/backup_email/backup_email';
import Confirmation from 'src/backup_account/confirmation/confirmation';
import SnackbarNotification from 'src/common/snackbar_notification/snackbar_notification';
import Header from 'src/common/header/header';

describe('BackupAccount', () => {
  let page;

  beforeEach(() => {
    const mockTranslations = key => key;
    page = shallow(<Page t={mockTranslations} />);
  });

  it('renders backup account page title', () => {
    expect(page.props().title).toEqual('backup-account.page-title');
  });

  it('renders header with logout button', () => {
    expect(page.find(Header).props().renderLogout).toEqual(true);
  });

  describe('save backup email', () => {
    let pageInstance;

    beforeEach(() => {
      pageInstance = page.instance();
    });

    it('verifies initial state', () => {
      expect(pageInstance.state.status).toEqual('');
    });

    it('changes state', () => {
      pageInstance.saveBackupEmail('success');
      expect(pageInstance.state.status).toEqual('success');
    });

    it('renders backup email component', () => {
      expect(page.find(BackupEmail).length).toEqual(1);
    });

    it('renders confirmation component', () => {
      pageInstance.saveBackupEmail('success');
      expect(page.find(Confirmation).length).toEqual(1);
    });

    context('on submit error', () => {
      beforeEach(() => {
        pageInstance.saveBackupEmail('error');
      });

      it('returns snackbar component on error', () => {
        const snackbar = pageInstance.showSnackbarOnError(pageInstance.props.t);
        expect(snackbar).toEqual(<SnackbarNotification message='backup-account.error.submit-error' isError />);
      });

      it('returns nothing when there is no error', () => {
        pageInstance.saveBackupEmail('success');
        const snackbar = pageInstance.showSnackbarOnError(pageInstance.props.t);
        expect(snackbar).toEqual(undefined);
      });

      it('renders snackbar notification on error', () => {
        const snackbar = page.find(SnackbarNotification);
        expect(snackbar).toExist();
        expect(snackbar.props().message).toEqual('backup-account.error.submit-error');
        expect(snackbar.props().isError).toEqual(true);
      });
    });
  });
});