[Ivan Diaz] - FrontEnd - Update form/button unit testing
This commit is contained in:
parent
8e3a40a377
commit
990e5e2dfd
|
@ -1,6 +1,4 @@
|
||||||
let Button = requireUnit('core-components/button', {
|
let Button = require('core-components/button');
|
||||||
'lib-core/callback': function () {}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Button component', function () {
|
describe('Button component', function () {
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,24 @@
|
||||||
/*
|
const Form = require('core-components/form');
|
||||||
jest.dontMock('core-components/form.js');
|
const Input = require('core-components/input');
|
||||||
jest.dontMock('core-components/form.js');
|
|
||||||
|
|
||||||
import React from 'react';
|
describe('Form component', function () {
|
||||||
import Form from 'core-components/form.js';
|
let form, inputs, onSubmit = stub();
|
||||||
import Input from 'core-components/input.js';
|
|
||||||
|
|
||||||
let TestUtils = React.addons.TestUtils;
|
beforeEach(function () {
|
||||||
|
form = TestUtils.renderIntoDocument(
|
||||||
describe('Form', function () {
|
<Form onSubmit={onSubmit}>
|
||||||
let results = TestUtils.renderIntoDocument(
|
<div>
|
||||||
<Form onSubmit={jest.genMockFunction()}>
|
<Input name="first" value="value1"/>
|
||||||
<div>
|
<Input name="second" value="value2" />
|
||||||
<Input name="first" value="value1"/>
|
</div>
|
||||||
<Input name="second" value="value2" />
|
<Input name="third" value="value3" />
|
||||||
</div>
|
</Form>
|
||||||
<Input name="third" value="value3" />
|
);
|
||||||
</Form>
|
inputs = TestUtils.scryRenderedComponentsWithType(form, Input);
|
||||||
);
|
});
|
||||||
let inputs = TestUtils.scryRenderedComponentsWithType(results, Input);
|
|
||||||
|
|
||||||
it('should store input value in form state', function () {
|
it('should store input value in form state', function () {
|
||||||
expect(results.state.form).toEqual({
|
expect(form.state.form).to.deep.equal({
|
||||||
first: 'value1',
|
first: 'value1',
|
||||||
second: 'value2',
|
second: 'value2',
|
||||||
third: 'value3'
|
third: 'value3'
|
||||||
|
@ -31,7 +28,7 @@ describe('Form', function () {
|
||||||
it('should update form state if an input value changes', function () {
|
it('should update form state if an input value changes', function () {
|
||||||
inputs[0].props.onChange({ target: {value: 'value4'}});
|
inputs[0].props.onChange({ target: {value: 'value4'}});
|
||||||
|
|
||||||
expect(results.state.form).toEqual({
|
expect(form.state.form).to.deep.equal({
|
||||||
first: 'value4',
|
first: 'value4',
|
||||||
second: 'value2',
|
second: 'value2',
|
||||||
third: 'value3'
|
third: 'value3'
|
||||||
|
@ -39,7 +36,7 @@ describe('Form', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update input value if state value changes', function () {
|
it('should update input value if state value changes', function () {
|
||||||
results.setState({
|
form.setState({
|
||||||
form: {
|
form: {
|
||||||
first: 'value6',
|
first: 'value6',
|
||||||
second: 'value7',
|
second: 'value7',
|
||||||
|
@ -47,15 +44,14 @@ describe('Form', function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(inputs[0].props.value).toEqual('value6');
|
expect(inputs[0].props.value).to.equal('value6');
|
||||||
expect(inputs[1].props.value).toEqual('value7');
|
expect(inputs[1].props.value).to.equal('value7');
|
||||||
expect(inputs[2].props.value).toEqual('value8');
|
expect(inputs[2].props.value).to.equal('value8');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call onSubmit callback when form is submitted', function () {
|
it('should call onSubmit callback when form is submitted', function () {
|
||||||
TestUtils.Simulate.submit(results.getDOMNode());
|
TestUtils.Simulate.submit(ReactDOM.findDOMNode(form));
|
||||||
|
|
||||||
expect(results.props.onSubmit).toBeCalledWith(results.state.form);
|
expect(form.props.onSubmit).to.have.been.calledWith(form.state.form);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
|
@ -1,7 +1,9 @@
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = function () {
|
||||||
render() {
|
return React.createClass({
|
||||||
return <div />;
|
render() {
|
||||||
}
|
return <div {...this.props} />;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue