Skip to content

Commit

Permalink
Merge branch 'master' into sync-submit
Browse files Browse the repository at this point in the history
  • Loading branch information
dpikt authored Aug 12, 2019
2 parents 20dfeab + 32809e5 commit b7d1e0d
Show file tree
Hide file tree
Showing 5 changed files with 4,752 additions and 3,427 deletions.
11 changes: 10 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"presets": ["@launchpadlab/babel-preset/react"]
"presets": ["@launchpadlab/babel-preset/react"],
"plugins": [
["transform-imports", {
"redux-form": {
// Use CJS import instead of the @launchpadlab/babel-preset default (es)
"transform": "redux-form/lib/${member}",
"preventFullImport": true
}
}]
]
}
19 changes: 0 additions & 19 deletions .codeclimate.yml

This file was deleted.

33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchpadlab/lp-form",
"version": "2.8.2",
"version": "2.8.3",
"description": "Extensions for the reduxForm HOC",
"main": "lib/index.js",
"scripts": {
Expand All @@ -13,8 +13,7 @@
"precommit": "yarn run docs && git add docs.md",
"prepublish": "yarn run lint && yarn run clean && yarn run build",
"test": "jest",
"test:coverage": "jest --coverage",
"report-coverage": "codeclimate-test-reporter < coverage/lcov.info"
"test:coverage": "jest --coverage"
},
"repository": "launchpadlab/lp-form",
"keywords": [
Expand All @@ -29,29 +28,29 @@
"lib/"
],
"devDependencies": {
"@launchpadlab/babel-preset": "^1.0.0",
"@launchpadlab/babel-preset": "^2.1.0",
"@launchpadlab/eslint-config": "^2.2.3",
"babel-cli": "^6.22.2",
"codeclimate-test-reporter": "^0.5.0",
"documentation": "^5.3.2",
"documentation": "^12.1.1",
"enzyme": "^3.1.0",
"enzyme-adapter-react-15": "^1.0.1",
"eslint": "^3.15.0",
"husky": "^0.13.3",
"jest": "^21.2.1",
"react": "^15.6.1",
"react-dom": "^15.5.0",
"react-redux": "^5.0.5",
"react-test-renderer": "^15.5.0",
"redux": "^3.7.2",
"redux-form": "^7.0.3",
"enzyme-adapter-react-16": "^1.14.0",
"eslint": "^6.1.0",
"husky": "^3.0.3",
"jest": "^24.8.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-redux": "^7.1.0",
"react-test-renderer": "^16.9.0",
"redux": "^4.0.4",
"redux-form": "^8.2.5",
"rimraf": "^2.5.4"
},
"peerDependencies": {
"react": ">=15.5.0",
"redux-form": ">=6.0.0"
},
"dependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"is-promise": "^2.1.0",
"lodash": "^4.17.4",
"recompose": "^0.26.0",
Expand Down
41 changes: 24 additions & 17 deletions test/lpForm.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import { configure, mount } from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'
import Adapter from 'enzyme-adapter-react-16'
import debounce from 'lodash/debounce'
import { SubmissionError } from 'redux-form'
import isPromise from 'is-promise'
Expand All @@ -10,6 +12,11 @@ jest.mock('lodash/debounce', () => jest.fn(fn => fn))

configure({ adapter: new Adapter() })

function mountWithProvider (node) {
const mockStore = createStore(() => ({}))
return mount(<Provider store={ mockStore }>{ node }</Provider>)
}

const INITIAL_VALUES = {
name: 'Test Person',
address: {
Expand All @@ -30,7 +37,7 @@ test('lpForm: filters initial values', () => {
const initialValuesFilters = { 'reject': ['name', 'address.zip'] }
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ initialValuesFilters, initialValues: INITIAL_VALUES })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
expect(formConfig.initialValues).toEqual({ address: { street: 'Shady Lane' }})
})
Expand All @@ -40,7 +47,7 @@ test('lpForm: filters submitted values', () => {
const onSubmit = jest.fn()
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ submitFilters, onSubmit })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
formConfig.onSubmit(INITIAL_VALUES)
expect(onSubmit).toHaveBeenCalledWith({ address: { street: 'Shady Lane' }})
Expand All @@ -66,7 +73,7 @@ test('lpForm: wraps rejected promises in a SubmissionError', () => {
const onSubmit = () => Promise.reject({ errors: ERRORS })
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ onSubmit })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()

return formConfig.onSubmit(INITIAL_VALUES).catch(e => {
Expand All @@ -86,7 +93,7 @@ test('lpForm: retains information about the originating error during submit', ()
}
const Wrapped = () => <div>Hi</div>
const Form = lpForm({ onSubmit })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()

return formConfig.onSubmit(INITIAL_VALUES).catch(e => {
Expand All @@ -101,7 +108,7 @@ test('lpForm: creates submitting onChange if submitOnChange is true', () => {
const submit = jest.fn()
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ onChange, submitOnChange: true })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
const wrappedOnChange = formConfig.onChange
// Call new onChange with typical arguments
Expand All @@ -119,7 +126,7 @@ test('lpForm: passes through given onChange if submitOnChange is false', () => {
const onChange = () => 'result'
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ onChange })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
// Call new onChange with typical arguments
const onChangeArgs = [
Expand All @@ -134,7 +141,7 @@ test('lpForm: provides a default onSubmit that submits successfully', () => {
expect.assertions(1)
const Wrapped = () => <div> Hi </div>
const Form = lpForm()(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()

return formConfig.onSubmit(INITIAL_VALUES).then(values => {
Expand All @@ -147,7 +154,7 @@ test('lpForm: creates validation function with constraints', () => {
const constraints = { 'foo': { presence: true } }
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ constraints })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
const errors = formConfig.validate({})
expect(errors).toEqual({ foo: [ "Foo can't be blank" ] })
Expand All @@ -156,23 +163,23 @@ test('lpForm: creates validation function with constraints', () => {
test('lpForm: aliases "form" with "name"', () => {
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ name: 'foo' })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
expect(formConfig.form).toEqual('foo')
})

test('lpForm: can recieve config as props', () => {
const Wrapped = () => <div> Hi </div>
const Form = lpForm()(Wrapped)
const wrapper = mount(<Form name="foo" />)
const wrapper = mountWithProvider(<Form name="foo" />)
const formConfig = wrapper.find(Wrapped).props()
expect(formConfig.form).toEqual('foo')
})

test('lpForm: props override config', () => {
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ name: 'from-config' })(Wrapped)
const wrapper = mount(<Form name="from-props" />)
const wrapper = mountWithProvider(<Form name="from-props" />)
const formConfig = wrapper.find(Wrapped).props()
expect(formConfig.form).toEqual('from-props')
})
Expand All @@ -181,7 +188,7 @@ test('lpForm: can override validate function', () => {
const Wrapped = () => <div> Hi </div>
const validate = () => 'result'
const Form = lpForm({ validate })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
expect(formConfig.validate()).toEqual(validate())
})
Expand All @@ -190,7 +197,7 @@ test('lpForm: can pass in options through `validationOptions`', () => {
const constraints = { 'foo': { presence: true } }
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ constraints, validationOptions: { fullMessages: false }})(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
const errors = formConfig.validate({})
expect(errors).toEqual({ foo: ["can't be blank"] })
Expand All @@ -203,7 +210,7 @@ test('lpForm: calls `beforeSubmit` with form values and options', () => {
const beforeSubmit = jest.fn(values => ({ ...values, name: 'Rachel' }))
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ onSubmit, beforeSubmit, option })(Wrapped)
const wrapper = mount(<Form prop={ prop } />)
const wrapper = mountWithProvider(<Form prop={ prop } />)
const formConfig = wrapper.find(Wrapped).props()
formConfig.onSubmit(INITIAL_VALUES)
expect(beforeSubmit).toHaveBeenCalledWith(INITIAL_VALUES, { option, prop })
Expand All @@ -215,7 +222,7 @@ test('lpForm: can debounce onSubmit function', () => {
const Wrapped = () => <div> Hi </div>
const onSubmit = jest.fn()
const Form = lpForm({ debounceSubmit: 200, onSubmit })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
formConfig.onSubmit(INITIAL_VALUES)
expect(debounce).toHaveBeenCalledTimes(1)
Expand All @@ -226,7 +233,7 @@ test('lpForm: will ignore onChange when the form is pristine and untouched', ()
const onChange = jest.fn()
const Wrapped = () => <div> Hi </div>
const Form = lpForm({ onChange })(Wrapped)
const wrapper = mount(<Form />)
const wrapper = mountWithProvider(<Form />)
const formConfig = wrapper.find(Wrapped).props()
const wrappedOnChange = formConfig.onChange
// Call new onChange with pristine form arguments
Expand Down
Loading

0 comments on commit b7d1e0d

Please sign in to comment.