diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/components/Login.spec.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js new file mode 100644 index 0000000000..0f82102d4e --- /dev/null +++ b/test/components/Login.spec.js @@ -0,0 +1,64 @@ +// @flow + +import { expect } from 'chai'; +import React from 'react'; +import { shallow } from 'enzyme'; +import Login from '../../app/components/Login'; +import AccountInput from '../../app/components/AccountInput'; + +import type { ShallowWrapper } from 'enzyme'; + +describe('components/Login', () => { + + it('notifies on the first change after failure', () => { + + let cbCalled = false; + const props = { + onFirstChangeAfterFailure: () => { cbCalled=true; }, + }; + + const component = renderWithProps( props ); + const accountInput = component.find(AccountInput); + + // Change the props to a failed state + component.setProps({ account: { + status: 'failed', + }}); + + + // Write something in the input field + setInputText(accountInput, 'foo'); + expect(cbCalled).to.be.true; + + + // Reset the test state + cbCalled = false; + + // Write some other thing in the input field + setInputText(accountInput, 'bar'); + expect(cbCalled).to.be.false; + }); + +}); + +function renderWithProps(customProps): ShallowWrapper { + const defaultProps = { + account: {accountNumber: null, + paidUntil: null, + status: 'none', + error: null, + }, + onLogin: () => {}, + onSettings: () => {}, + onChange: () => {}, + onFirstChangeAfterFailure: () => {}, + onExternalLink: () => {}, + }; + const props = Object.assign({}, defaultProps, customProps); + + return shallow( <Login { ...props } /> ); +} + +function setInputText(input: ShallowWrapper, text: string) { + input.simulate('change', {target: {value: text}}); +} |
