Browse Source

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.
renovate/lint-staged-8.x
Ben Woosley 7 years ago
parent
commit
a0b3b825d8
No known key found for this signature in database GPG Key ID: 6EE5F3785F78B345
  1. 11
      app/components/Form/PayForm.js
  2. 5
      app/components/Form/RequestForm.js
  3. 11
      test/components/Form.spec.js
  4. 41
      test/components/Form/Payform.spec.js
  5. 28
      test/components/Form/RequestForm.spec.js

11
app/components/Form/PayForm.js

@ -117,7 +117,11 @@ class PayForm extends Component {
PayForm.propTypes = { 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, currency: PropTypes.string.isRequired,
crypto: PropTypes.string.isRequired, crypto: PropTypes.string.isRequired,
@ -129,7 +133,10 @@ PayForm.propTypes = {
]).isRequired, ]).isRequired,
inputCaption: PropTypes.string.isRequired, inputCaption: PropTypes.string.isRequired,
showPayLoadingScreen: PropTypes.bool.isRequired, showPayLoadingScreen: PropTypes.bool.isRequired,
payFormIsValid: PropTypes.object.isRequired, payFormIsValid: PropTypes.shape({
errors: PropTypes.object,
isValid: PropTypes.bool
}).isRequired,
setPayAmount: PropTypes.func.isRequired, setPayAmount: PropTypes.func.isRequired,
onPayAmountBlur: PropTypes.func.isRequired, onPayAmountBlur: PropTypes.func.isRequired,

5
app/components/Form/RequestForm.js

@ -46,7 +46,10 @@ const RequestForm = ({
) )
RequestForm.propTypes = { RequestForm.propTypes = {
requestform: PropTypes.object.isRequired, requestform: PropTypes.shape({
amount: PropTypes.string.isRequired,
memo: PropTypes.string
}).isRequired,
currency: PropTypes.string.isRequired, currency: PropTypes.string.isRequired,
crypto: PropTypes.string.isRequired, crypto: PropTypes.string.isRequired,

11
test/components/Form.spec.js

@ -6,7 +6,11 @@ import PayForm from '../../app/components/Form/PayForm'
import RequestForm from '../../app/components/Form/RequestForm' import RequestForm from '../../app/components/Form/RequestForm'
const payFormProps = { const payFormProps = {
payform: {}, payform: {
amount: '',
payInput: '',
showErrors: {}
},
currency: 'BTC', currency: 'BTC',
crypto: 'BTC', crypto: 'BTC',
@ -28,7 +32,10 @@ const payFormProps = {
} }
const requestFormProps = { const requestFormProps = {
requestform: {}, requestform: {
amount: '',
memo: ''
},
currency: '', currency: '',
crypto: '', crypto: '',

41
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(<PayForm {...defaultProps} />)
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)
})
})
})

28
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(<RequestForm {...props} />)
it('should contain RequestForm', () => {
expect(el.contains('Request')).toBe(true)
})
})
})
Loading…
Cancel
Save