summaryrefslogtreecommitdiff
path: root/web-ui/test/integration/account_recovery.spec.js
blob: 708b693f128b55f8a001c7ea76419700bdc4f858 (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
import { mount } from 'enzyme';
import expect from 'expect';
import React from 'react';
import App from 'src/common/app';
import AccountRecoveryPage from 'src/account_recovery/page';
import testI18n from './i18n';

describe('Account Recovery Page', () => {
  context('New password validation', () => {
    let app;
    let accountRecoveryPage;

    beforeEach(() => {
      app = mount(<App i18n={testI18n} child={<AccountRecoveryPage />} />);
      accountRecoveryPage = app.find('Page');
      accountRecoveryPage.find('form').simulate('submit');
      accountRecoveryPage.find('form').simulate('submit');
    });

    it('shows no validation error with valid password', () => {
      accountRecoveryPage.find('input[name="new-password"]').simulate('change', { target: { value: '12345678' } });
      // workaround because of an enzyme bug https://github.com/airbnb/enzyme/issues/534
      const inputField = accountRecoveryPage.findWhere(element => element.props().name === 'new-password').find('InputField');
      expect(inputField.props().errorText).toEqual('');
    });

    it('shows validation error with invalid password', () => {
      accountRecoveryPage.find('input[name="new-password"]').simulate('change', { target: { value: '1234' } });
      const inputField = accountRecoveryPage.findWhere(element => element.props().name === 'new-password').find('InputField');
      expect(inputField.props().errorText).toEqual('A better password has at least 8 characters');
    });

    it('shows no validation error with valid confirm password', () => {
      accountRecoveryPage.find('input[name="new-password"]').simulate('change', { target: { value: '12345678' } });
      accountRecoveryPage.find('input[name="confirm-password"]').simulate('change', { target: { value: '12345678' } });
      const inputField = accountRecoveryPage.findWhere(element => element.props().name === 'confirm-password').find('InputField');
      expect(inputField.props().errorText).toEqual('');
    });

    it('shows validation error with invalid confirm password', () => {
      accountRecoveryPage.find('input[name="new-password"]').simulate('change', { target: { value: '12345678' } });
      accountRecoveryPage.find('input[name="confirm-password"]').simulate('change', { target: { value: '1234' } });
      const inputField = accountRecoveryPage.findWhere(element => element.props().name === 'confirm-password').find('InputField');
      expect(inputField.props().errorText).toEqual('Password and confirmation don\'t match');
    });

    it('disables button if empty fields', () => {
      accountRecoveryPage.find('input[name="new-password"]').simulate('change', { target: { value: '' } });
      accountRecoveryPage.find('input[name="confirm-password"]').simulate('change', { target: { value: '' } });
      expect(accountRecoveryPage.find('SubmitButton').props().disabled).toEqual(true);
    });

    it('enables button if valid fields', () => {
      accountRecoveryPage.find('input[name="new-password"]').simulate('change', { target: { value: '12345678' } });
      accountRecoveryPage.find('input[name="confirm-password"]').simulate('change', { target: { value: '12345678' } });
      expect(accountRecoveryPage.find('SubmitButton').props().disabled).toEqual(false);
    });
  });
});