99 lines
2.8 KiB
JavaScript
99 lines
2.8 KiB
JavaScript
import React from 'react';
|
|
import TestUtils from 'react-addons-test-utils';
|
|
|
|
import Formsy from './..';
|
|
import { InputFactory } from './utils/TestInput';
|
|
|
|
const TestInput = InputFactory({
|
|
render() {
|
|
return <input value={this.getValue()} readOnly/>;
|
|
}
|
|
});
|
|
|
|
const TestForm = React.createClass({
|
|
render() {
|
|
return (
|
|
<Formsy.Form>
|
|
<TestInput name="foo" validations="isAlphanumeric" value={this.props.inputValue}/>
|
|
</Formsy.Form>
|
|
);
|
|
}
|
|
});
|
|
|
|
export default {
|
|
|
|
'should pass with a default value': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should pass with a string is only latin letters': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue="myValue"/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should fail with a string with numbers': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue="myValue42"/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should pass with an undefined': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue={undefined}/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should pass with a null': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue={null}/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should pass with an empty string': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue={''}/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should pass with a number': function (test) {
|
|
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue={42}/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), true);
|
|
test.done();
|
|
|
|
},
|
|
|
|
'should fail with a non alpha and number symbols': function (test) {
|
|
|
|
const value = '!@#$%^&*()';
|
|
const form = TestUtils.renderIntoDocument(<TestForm inputValue={value}/>);
|
|
const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
|
|
test.equal(inputComponent.isValid(), false);
|
|
test.done();
|
|
|
|
}
|
|
|
|
};
|