-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from appfolio/improveErrors
Improve errors
- Loading branch information
Showing
8 changed files
with
192 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import FormRow from './FormRow'; | ||
|
||
const BoundFormRow = (props, { value = {}, errors = {}, onChange }) => ( | ||
<FormRow | ||
value={value[props.name] || ''} | ||
feedback={errors[props.name] || ''} | ||
onChange={onChange(props.name)} | ||
{...props} | ||
/> | ||
); | ||
|
||
BoundFormRow.contextTypes = { | ||
value: React.PropTypes.object, | ||
errors: React.PropTypes.object, | ||
onChange: React.PropTypes.func | ||
}; | ||
|
||
BoundFormRow.propTypes = { | ||
name: React.PropTypes.string.isRequired | ||
}; | ||
|
||
export default BoundFormRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
import assert from 'assert'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import BoundFormRow from '../../src/components/BoundFormRow'; | ||
|
||
describe('<BoundFormRow />', () => { | ||
describe('with context', () => { | ||
const onChange = sinon.stub(); | ||
const component = shallow( | ||
<BoundFormRow name="firstName" />, { | ||
context: { | ||
value: { | ||
firstName: 'First Name', | ||
lastName: 'Last Name' | ||
}, | ||
errors: { | ||
firstName: 'Not Right', | ||
lastName: 'Something Else' | ||
}, | ||
onChange | ||
} | ||
} | ||
); | ||
|
||
it('should forward props', () => { | ||
assert.equal(component.prop('name'), 'firstName'); | ||
}); | ||
|
||
it('should pass the value from context', () => { | ||
assert.equal(component.prop('value'), 'First Name'); | ||
}); | ||
|
||
it('should pass the error from context', () => { | ||
assert.equal(component.prop('feedback'), 'Not Right'); | ||
}); | ||
|
||
it('should pass the onChange handler from context', () => { | ||
assert.equal(component.prop('onChange'), onChange('firstName')); | ||
}); | ||
}); | ||
|
||
describe('with defaults', () => { | ||
const onChange = sinon.stub(); | ||
const component = shallow( | ||
<BoundFormRow name="firstName" />, { context: { onChange } } | ||
); | ||
|
||
it('should set the default context value', () => { | ||
assert.equal(component.prop('value'), ''); | ||
}); | ||
|
||
it('should set the default context errors', () => { | ||
assert.equal(component.prop('feedback'), ''); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.