-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
11 changed files
with
364 additions
and
19 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
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,64 @@ | ||
import React from 'react'; | ||
import { Input, Icon, Button } from 'antd'; | ||
|
||
import Form from '../src/Form'; | ||
import FormItem from '../src/FormItem'; | ||
|
||
export default class TestSetValue extends React.Component { // eslint-disable-line | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
a: 'a', | ||
b: 'b', | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Form style={{ width: '600px' }} ref={(form) => { this.form = form; }}> | ||
<FormItem | ||
id="a" | ||
hasFeedback | ||
value={this.state.a} | ||
validateTrigger="onBlur" | ||
> | ||
<Input | ||
prefix={<Icon type="mail" style={{ fontSize: 13 }} />} | ||
placeholder="Email" | ||
type="email" | ||
onChange={() => console.log('safadf')} // eslint-disable-line | ||
/> | ||
</FormItem> | ||
<FormItem | ||
id="b" | ||
hasFeedback | ||
value={this.state.b} | ||
validateTrigger="onBlur" | ||
> | ||
<Input | ||
prefix={<Icon type="mail" style={{ fontSize: 13 }} />} | ||
placeholder="Email" | ||
type="email" | ||
onChange={() => console.log('safadf')} // eslint-disable-line | ||
/> | ||
</FormItem> | ||
<Button | ||
onClick={() => { | ||
this.form.setValue('a', `${this.form.getValue('a')}a`); | ||
}} | ||
>set first</Button> | ||
<Button | ||
onClick={() => { | ||
this.form.setValue({ | ||
a: `${this.form.getValue('a')}a`, | ||
b: `${this.form.getValue('b')}b`, | ||
}); | ||
}} | ||
>set all</Button> | ||
</Form> | ||
</div> | ||
); | ||
} | ||
} |
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,48 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Input } from 'antd'; | ||
import FormItem from '../src/FormItem'; | ||
import Form from '../src/Form'; | ||
|
||
describe('getValue from form', () => { | ||
it('getValue by name success', () => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test" value="test" > | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
expect(form.getValue('test')).toBe('test'); | ||
}); | ||
|
||
it('getValue by all', () => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test" value="test" > | ||
<Input /> | ||
</FormItem> | ||
<FormItem id="test1" value="test1" > | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
expect(form.getValue()).toEqual({ | ||
test: 'test', | ||
test1: 'test1', | ||
}); | ||
}); | ||
|
||
it('check id when getValue', () => { | ||
expect(() => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test"> | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.getValue('test1'); | ||
}).toThrow(/component with id: test1 is not exist in form./); | ||
}); | ||
}); |
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,53 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Input } from 'antd'; | ||
import FormItem from '../src/FormItem'; | ||
import Form from '../src/Form'; | ||
|
||
describe('setValue from form', () => { | ||
it('setValue by name success', () => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test" value="test" > | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.setValue('test', 'a'); | ||
expect(form.getValue('test')).toBe('a'); | ||
}); | ||
|
||
it('setValue all', () => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test" value="test" > | ||
<Input /> | ||
</FormItem> | ||
<FormItem id="test1" value="test1" > | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.setValue({ | ||
test: 'a', | ||
test1: 'b', | ||
}); | ||
expect(form.getValue()).toEqual({ | ||
test: 'a', | ||
test1: 'b', | ||
}); | ||
}); | ||
|
||
it('check id when setValue', () => { | ||
expect(() => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test"> | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.setValue('test1'); | ||
}).toThrow(/component with id: test1 is not exist in form./); | ||
}); | ||
}); |
Oops, something went wrong.