From a0b3b825d8f563fae2dfbafb11966e5090727da5 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 8 Jan 2018 01:20:18 -0800 Subject: [PATCH] enhance(form-tests): Split a PayForm and RequestForm test out Form.spec just shallow renders the Form, so PayForm and RequestForm were previously only tested insofar as their props were valiated by propTypes. Testing them directly means the form is rendered. --- app/components/Form/PayForm.js | 11 +++++-- app/components/Form/RequestForm.js | 5 ++- test/components/Form.spec.js | 11 +++++-- test/components/Form/Payform.spec.js | 41 ++++++++++++++++++++++++ test/components/Form/RequestForm.spec.js | 28 ++++++++++++++++ 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 test/components/Form/Payform.spec.js create mode 100644 test/components/Form/RequestForm.spec.js diff --git a/app/components/Form/PayForm.js b/app/components/Form/PayForm.js index 725d312e..2f402336 100644 --- a/app/components/Form/PayForm.js +++ b/app/components/Form/PayForm.js @@ -117,7 +117,11 @@ class PayForm extends Component { PayForm.propTypes = { - payform: PropTypes.object.isRequired, + payform: PropTypes.shape({ + amount: PropTypes.string.isRequired, + payInput: PropTypes.string.isRequired, + showErrors: PropTypes.object.isRequired + }).isRequired, currency: PropTypes.string.isRequired, crypto: PropTypes.string.isRequired, @@ -129,7 +133,10 @@ PayForm.propTypes = { ]).isRequired, inputCaption: PropTypes.string.isRequired, showPayLoadingScreen: PropTypes.bool.isRequired, - payFormIsValid: PropTypes.object.isRequired, + payFormIsValid: PropTypes.shape({ + errors: PropTypes.object, + isValid: PropTypes.bool + }).isRequired, setPayAmount: PropTypes.func.isRequired, onPayAmountBlur: PropTypes.func.isRequired, diff --git a/app/components/Form/RequestForm.js b/app/components/Form/RequestForm.js index 0f793e45..9181fd18 100644 --- a/app/components/Form/RequestForm.js +++ b/app/components/Form/RequestForm.js @@ -46,7 +46,10 @@ const RequestForm = ({ ) RequestForm.propTypes = { - requestform: PropTypes.object.isRequired, + requestform: PropTypes.shape({ + amount: PropTypes.string.isRequired, + memo: PropTypes.string + }).isRequired, currency: PropTypes.string.isRequired, crypto: PropTypes.string.isRequired, diff --git a/test/components/Form.spec.js b/test/components/Form.spec.js index d90556ff..ab20f73a 100644 --- a/test/components/Form.spec.js +++ b/test/components/Form.spec.js @@ -6,7 +6,11 @@ import PayForm from '../../app/components/Form/PayForm' import RequestForm from '../../app/components/Form/RequestForm' const payFormProps = { - payform: {}, + payform: { + amount: '', + payInput: '', + showErrors: {} + }, currency: 'BTC', crypto: 'BTC', @@ -28,7 +32,10 @@ const payFormProps = { } const requestFormProps = { - requestform: {}, + requestform: { + amount: '', + memo: '' + }, currency: '', crypto: '', diff --git a/test/components/Form/Payform.spec.js b/test/components/Form/Payform.spec.js new file mode 100644 index 00000000..7ce28039 --- /dev/null +++ b/test/components/Form/Payform.spec.js @@ -0,0 +1,41 @@ +import React from 'react' +import { shallow } from 'enzyme' + +import PayForm from '../../../app/components/Form/PayForm' + +const defaultProps = { + payform: { + amount: '', + payInput: '', + showErrors: {} + }, + currency: 'BTC', + crypto: 'BTC', + + isOnchain: false, + isLn: false, + currentAmount: '0', + inputCaption: '', + showPayLoadingScreen: false, + payFormIsValid: {}, + + setPayAmount: () => {}, + onPayAmountBlur: () => {}, + setPayInput: () => {}, + onPayInputBlur: () => {}, + fetchInvoice: () => {}, + + onPaySubmit: () => {} +} + +describe('Form', () => { + describe('should show the form without an input', () => { + const el = shallow() + + it('should contain PayForm', () => { + expect(el.find('input#paymentRequest').props.value).toBe(undefined) + expect(el.contains('lightning network')).toBe(false) + expect(el.contains('on-chain')).toBe(false) + }) + }) +}) diff --git a/test/components/Form/RequestForm.spec.js b/test/components/Form/RequestForm.spec.js new file mode 100644 index 00000000..a04c655c --- /dev/null +++ b/test/components/Form/RequestForm.spec.js @@ -0,0 +1,28 @@ +import React from 'react' +import { shallow } from 'enzyme' + +import RequestForm from '../../../app/components/Form/RequestForm' + +const defaultProps = { + requestform: { + amount: '', + showErrors: {} + }, + currency: '', + crypto: '', + + setRequestAmount: () => {}, + setRequestMemo: () => {}, + + onRequestSubmit: () => {} +} + +describe('Form', () => { + describe('should show request form when formType is REQUEST_FORM', () => { + const props = { ...defaultProps } + const el = shallow() + it('should contain RequestForm', () => { + expect(el.contains('Request')).toBe(true) + }) + }) +})