From 353014a6bf9c3358a5d44e0411fe08e7f8c621d4 Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Wed, 5 Apr 2017 11:59:09 -0300 Subject: [#934] Add integration test for password validation --- web-ui/test/integration/account_recovery.spec.js | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 web-ui/test/integration/account_recovery.spec.js 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(} />); + 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); + }); + }); +}); -- cgit v1.2.3