summaryrefslogtreecommitdiff
path: root/web-ui/src/backup_account/page.spec.js
blob: 334d3ba8d53de55a9bb3ed443486ae20372cccc5 (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
76
77
78
79
80
import { shallow } from 'enzyme';
import expect from 'expect';
import React from 'react';
import { Page } from 'src/backup_account/page';

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

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

  it('renders backup email page title', () => {
    expect(page.find('h1').text()).toEqual('backup-account.title');
  });

  it('renders backup account email input field', () => {
    expect(page.find('InputField').props().name).toEqual('email');
  });

  it('renders backup account submit button', () => {
    expect(page.find('SubmitButton').props().buttonText).toEqual('backup-account.button');
  });

  describe('Email validation', () => {
    let pageInstance;

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

    it('verify initial state', () => {
      expect(pageInstance.state.error).toEqual('');
      expect(page.find('SubmitButton').props().disabled).toEqual(true);
    });

    context('with invalid email', () => {
      beforeEach(() => {
        pageInstance.validateEmail({ target: { value: 'test' } });
      });

      it('sets error in state', () => {
        expect(pageInstance.state.error).toEqual('backup-account.error.invalid-email');
      });

      it('disables submit button', () => {
        expect(page.find('SubmitButton').props().disabled).toEqual(true);
      });
    });

    context('with valid email', () => {
      beforeEach(() => {
        pageInstance.validateEmail({ target: { value: 'test@test.com' } });
      });

      it('does not set error in state', () => {
        expect(pageInstance.state.error).toEqual('');
      });

      it('submit button is enabled', () => {
        expect(page.find('SubmitButton').props().disabled).toEqual(false);
      });
    });

    context('with empty email', () => {
      beforeEach(() => {
        pageInstance.validateEmail({ target: { value: '' } });
      });

      it('not set error in state', () => {
        expect(pageInstance.state.error).toEqual('');
      });

      it('disables submit button', () => {
        expect(page.find('SubmitButton').props().disabled).toEqual(true);
      });
    });
  });
});