-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c5cc12
commit b1ca0d6
Showing
24 changed files
with
103 additions
and
351 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
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 |
---|---|---|
|
@@ -3,13 +3,13 @@ import TestUtils from 'react-dom/test-utils'; | |
import PureRenderMixin from 'react-addons-pure-render-mixin'; | ||
import sinon from 'sinon'; | ||
|
||
import Formsy, { withFormsy, Wrapper } from './..'; | ||
import Formsy, { withFormsy } from './..'; | ||
import TestInput, { InputFactory } from './utils/TestInput'; | ||
import immediate from './utils/immediate'; | ||
|
||
export default { | ||
|
||
'should return passed and setValue() value when using getValue()': function (test) { | ||
'should pass down correct value prop after using setValue()': function (test) { | ||
|
||
const form = TestUtils.renderIntoDocument( | ||
<Formsy> | ||
|
@@ -33,34 +33,7 @@ export default { | |
this.props.setValue(event.target.value, false); | ||
} | ||
render() { | ||
return <input type="text" value={this.props.getValue()} onChange={this.updateValue}/>; | ||
} | ||
}) | ||
const form = TestUtils.renderIntoDocument( | ||
<Formsy> | ||
<Input name="foo" value="foo" innerRef="comp" /> | ||
</Formsy> | ||
); | ||
const inputComponent = TestUtils.findRenderedComponentWithType(form, Input); | ||
const setStateSpy = sinon.spy(inputComponent, 'setState'); | ||
const inputElement = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT'); | ||
|
||
test.equal(setStateSpy.called, false); | ||
TestUtils.Simulate.change(inputElement, {target: {value: 'foobar'}}); | ||
test.equal(setStateSpy.calledOnce, true); | ||
test.equal(setStateSpy.calledWithExactly({ value: 'foobar' }), true); | ||
test.done(); | ||
|
||
}, | ||
|
||
'Wrapper: should only set the value and not validate when calling setValue(val, false)': function (test) { | ||
|
||
const Input = Wrapper(class TestInput extends React.Component { | ||
updateValue = (event) => { | ||
this.props.setValue(event.target.value, false); | ||
} | ||
render() { | ||
return <input type="text" value={this.props.getValue()} onChange={this.updateValue}/>; | ||
return <input type="text" value={this.props.value} onChange={this.updateValue}/>; | ||
} | ||
}) | ||
const form = TestUtils.renderIntoDocument( | ||
|
@@ -105,10 +78,10 @@ export default { | |
|
||
'should return error message passed when calling getErrorMessage()': function (test) { | ||
|
||
let getErrorMessage = null; | ||
let errorMessage = null; | ||
const Input = InputFactory({ | ||
componentDidMount: function() { | ||
getErrorMessage = this.props.getErrorMessage; | ||
errorMessage = this.props.errorMessage; | ||
} | ||
}); | ||
TestUtils.renderIntoDocument( | ||
|
@@ -117,7 +90,7 @@ export default { | |
</Formsy> | ||
); | ||
|
||
test.equal(getErrorMessage(), 'Has to be email'); | ||
test.equal(errorMessage, 'Has to be email'); | ||
|
||
test.done(); | ||
|
||
|
@@ -127,8 +100,8 @@ export default { | |
|
||
let isValid = null; | ||
const Input = InputFactory({ | ||
componentDidMount: function() { | ||
isValid = this.props.isValid; | ||
componentWillReceiveProps: function(nextProps) { | ||
isValid = nextProps.isValid; | ||
} | ||
}); | ||
const form = TestUtils.renderIntoDocument( | ||
|
@@ -137,10 +110,10 @@ export default { | |
</Formsy> | ||
); | ||
|
||
test.equal(isValid(), false); | ||
test.equal(isValid, false); | ||
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT'); | ||
TestUtils.Simulate.change(input, {target: {value: '[email protected]'}}); | ||
test.equal(isValid(), true); | ||
test.equal(isValid, true); | ||
|
||
test.done(); | ||
|
||
|
@@ -162,9 +135,9 @@ export default { | |
</Formsy> | ||
); | ||
|
||
test.equal(isRequireds[0](), false); | ||
test.equal(isRequireds[1](), true); | ||
test.equal(isRequireds[2](), true); | ||
test.equal(isRequireds[0], false); | ||
test.equal(isRequireds[1], true); | ||
test.equal(isRequireds[2], true); | ||
|
||
test.done(); | ||
|
||
|
@@ -186,9 +159,9 @@ export default { | |
</Formsy> | ||
); | ||
|
||
test.equal(showRequireds[0](), false); | ||
test.equal(showRequireds[1](), true); | ||
test.equal(showRequireds[2](), false); | ||
test.equal(showRequireds[0], false); | ||
test.equal(showRequireds[1], true); | ||
test.equal(showRequireds[2], false); | ||
|
||
test.done(); | ||
|
||
|
@@ -198,8 +171,8 @@ export default { | |
|
||
let isPristine = null; | ||
const Input = InputFactory({ | ||
componentDidMount: function() { | ||
isPristine = this.props.isPristine; | ||
componentWillReceiveProps: function(nextProps) { | ||
isPristine = nextProps.isPristine; | ||
} | ||
}); | ||
const form = TestUtils.renderIntoDocument( | ||
|
@@ -208,10 +181,10 @@ export default { | |
</Formsy> | ||
); | ||
|
||
test.equal(isPristine(), true); | ||
test.equal(isPristine, true); | ||
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT'); | ||
TestUtils.Simulate.change(input, {target: {value: 'foo'}}); | ||
test.equal(isPristine(), false); | ||
test.equal(isPristine, false); | ||
|
||
test.done(); | ||
|
||
|
@@ -618,7 +591,7 @@ export default { | |
shouldComponentUpdate: function() { return false }, | ||
render: function() { | ||
renderSpy(); | ||
return <input type={this.props.type} value={this.props.getValue()} onChange={this.updateValue}/>; | ||
return <input type={this.props.type} value={this.props.value} onChange={this.updateValue}/>; | ||
} | ||
}); | ||
|
||
|
@@ -637,21 +610,10 @@ export default { | |
'binds all necessary methods': function (test) { | ||
const onInputRef = input => { | ||
[ | ||
'getErrorMessage', | ||
'getErrorMessages', | ||
'getValue', | ||
'hasValue', | ||
'isFormDisabled', | ||
'isValid', | ||
'isPristine', | ||
'isFormSubmitted', | ||
'isRequired', | ||
'isValidValue', | ||
'resetValue', | ||
'setValidations', | ||
'setValue', | ||
'showRequired', | ||
'showError', | ||
].forEach(fnName => { | ||
const fn = input[fnName]; | ||
try { | ||
|
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
Oops, something went wrong.