Browse Source

feature(form tests): fix form reducer tests and add form component tests

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
109d82bc87
  1. 2
      test/components/Channels.spec.js
  2. 60
      test/components/Form.spec.js
  3. 80
      test/reducers/__snapshots__/form.spec.js.snap
  4. 4
      test/reducers/__snapshots__/invoice.spec.js.snap
  5. 67
      test/reducers/form.spec.js

2
test/components/Channels.spec.js

@ -1,4 +1,4 @@
import React from 'react'; import React from 'react'
import { shallow } from 'enzyme' import { shallow } from 'enzyme'
import Channels from '../../app/components/Channels' import Channels from '../../app/components/Channels'

60
test/components/Form.spec.js

@ -0,0 +1,60 @@
import React from 'react'
import { shallow } from 'enzyme'
import Form from '../../app/components/Form'
import PayForm from '../../app/components/Form/PayForm'
import RequestForm from '../../app/components/Form/RequestForm'
const payFormProps = {
payform: {},
currency: 'BTC',
crypto: 'BTC',
isOnchain: false,
isLn: false,
currentAmount: '0',
inputCaption: '',
showPayLoadingScreen: false,
setPayAmount: () => {},
setPayInput: () => {},
fetchInvoice: () => {},
onPaySubmit: () => {}
}
const requestFormProps = {
requestform: {},
currency: '',
crypto: '',
setRequestAmount: () => {},
setRequestMemo: () => {},
onRequestSubmit: () => {}
}
const defaultProps = {
formType: '',
formProps: {},
closeForm: () => {}
}
describe('Form', () => {
describe('should show pay form when formType is PAY_FORM', () => {
const props = { ...defaultProps, formType: 'PAY_FORM', formProps: payFormProps }
const el = shallow(<Form {...props} />)
it('should contain PayForm', () => {
expect(el.find(PayForm)).toHaveLength(1)
})
})
describe('should show request form when formType is REQUEST_FORM', () => {
const props = { ...defaultProps, formType: 'REQUEST_FORM', formProps: requestFormProps }
const el = shallow(<Form {...props} />)
it('should contain RequestForm', () => {
expect(el.find(RequestForm)).toHaveLength(1)
})
})
})

80
test/reducers/__snapshots__/form.spec.js.snap

@ -1,85 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`reducers formReducer should correctly resetForm 1`] = `
Object {
"amount": "0",
"formType": "pay",
"message": "",
"modalOpen": false,
"onchainAmount": "0",
"payment_request": "",
"pubkey": "",
}
`;
exports[`reducers formReducer should correctly setAmount 1`] = `
Object {
"amount": 1,
"formType": "pay",
"message": "",
"modalOpen": false,
"onchainAmount": "0",
"payment_request": "",
"pubkey": "",
}
`;
exports[`reducers formReducer should correctly setForm 1`] = `
Object {
"amount": "0",
"formType": "foo",
"message": "",
"modalOpen": true,
"onchainAmount": "0",
"payment_request": "",
"pubkey": "",
}
`;
exports[`reducers formReducer should correctly setMessage 1`] = `
Object {
"amount": "0",
"formType": "pay",
"message": "foo",
"modalOpen": false,
"onchainAmount": "0",
"payment_request": "",
"pubkey": "",
}
`;
exports[`reducers formReducer should correctly setPaymentRequest 1`] = `
Object {
"amount": "0",
"formType": "pay",
"message": "",
"modalOpen": false,
"onchainAmount": "0",
"payment_request": "foo",
"pubkey": "",
}
`;
exports[`reducers formReducer should correctly setPubkey 1`] = `
Object {
"amount": "0",
"formType": "pay",
"message": "",
"modalOpen": false,
"onchainAmount": "0",
"payment_request": "",
"pubkey": "foo",
}
`;
exports[`reducers formReducer should handle initial state 1`] = ` exports[`reducers formReducer should handle initial state 1`] = `
Object { Object {
"amount": "0", "formType": null,
"formType": "pay",
"message": "",
"modalOpen": false,
"onchainAmount": "0",
"payment_request": "",
"pubkey": "",
} }
`; `;

4
test/reducers/__snapshots__/invoice.spec.js.snap

@ -66,7 +66,9 @@ exports[`reducers invoiceReducer should correctly receiveFormInvoice 1`] = `
Object { Object {
"data": Object {}, "data": Object {},
"formInvoice": Object { "formInvoice": Object {
"payreq": "foo", "amount": "0",
"payreq": "",
"r_hash": "",
}, },
"invoice": null, "invoice": null,
"invoiceLoading": false, "invoiceLoading": false,

67
test/reducers/form.spec.js

@ -1,64 +1,25 @@
import formReducer, { import formReducer, {
SET_FORM, SET_FORM_TYPE
SET_AMOUNT,
SET_MESSAGE,
SET_PUBKEY,
SET_PAYMENT_REQUEST,
RESET_FORM
} from '../../app/reducers/form' } from '../../app/reducers/form'
// describe('reducers', () => {
// describe('formReducer', () => {
// it('should have SET_FORM_TYPE', () => {
// expect(SET_FORM_TYPE).toEqual('SET_FORM_TYPE')
// })
// it('should correctly setFormType', () => {
// expect(formReducer(undefined, { type: SET_FORM_TYPE, formType: 'FOO' })).toMatchSnapshot()
// })
// }
// }
describe('reducers', () => { describe('reducers', () => {
describe('formReducer', () => { describe('formReducer', () => {
it('should handle initial state', () => { it('should handle initial state', () => {
expect(formReducer(undefined, {})).toMatchSnapshot() expect(formReducer(undefined, {})).toMatchSnapshot()
}) })
it('should have SET_FORM', () => {
expect(SET_FORM).toEqual('SET_FORM')
})
it('should have SET_AMOUNT', () => {
expect(SET_AMOUNT).toEqual('SET_AMOUNT')
})
it('should have SET_MESSAGE', () => {
expect(SET_MESSAGE).toEqual('SET_MESSAGE')
})
it('should have SET_PUBKEY', () => {
expect(SET_PUBKEY).toEqual('SET_PUBKEY')
})
it('should have SET_PAYMENT_REQUEST', () => {
expect(SET_PAYMENT_REQUEST).toEqual('SET_PAYMENT_REQUEST')
})
it('should have RESET_FORM', () => {
expect(RESET_FORM).toEqual('RESET_FORM')
})
it('should correctly setForm', () => {
expect(formReducer(undefined, { type: SET_FORM, modalOpen: true, formType: 'foo' })).toMatchSnapshot()
})
it('should correctly setAmount', () => {
expect(formReducer(undefined, { type: SET_AMOUNT, amount: 1 })).toMatchSnapshot()
})
it('should correctly setMessage', () => {
expect(formReducer(undefined, { type: SET_MESSAGE, message: 'foo' })).toMatchSnapshot()
})
it('should correctly setPubkey', () => {
expect(formReducer(undefined, { type: SET_PUBKEY, pubkey: 'foo' })).toMatchSnapshot()
})
it('should correctly setPaymentRequest', () => {
expect(formReducer(undefined, { type: SET_PAYMENT_REQUEST, payment_request: 'foo' })).toMatchSnapshot()
})
it('should correctly resetForm', () => {
expect(formReducer(undefined, { type: RESET_FORM })).toMatchSnapshot()
})
}) })
}) })

Loading…
Cancel
Save