diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-04-05 11:59:09 -0300 |
---|---|---|
committer | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-04-05 11:59:09 -0300 |
commit | 353014a6bf9c3358a5d44e0411fe08e7f8c621d4 (patch) | |
tree | 14633b9c69463f1693d7d368590cf8ce3dc1cea3 /web-ui/test | |
parent | a13bdf00d628805fbd84690eef9356ad754662f2 (diff) |
[#934] Add integration test for password validation
Diffstat (limited to 'web-ui/test')
-rw-r--r-- | web-ui/test/integration/account_recovery.spec.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/web-ui/test/integration/account_recovery.spec.js b/web-ui/test/integration/account_recovery.spec.js new file mode 100644 index 00000000..708b693f --- /dev/null +++ b/web-ui/test/integration/account_recovery.spec.js @@ -0,0 +1,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); + }); + }); +}); |