Skip to content

Commit 35bf541

Browse files
authored
chore: Full test coverage (#10)
* list coverage * fix list render logic * context test * onFinish check * fix changedValues logic * rest test
1 parent 9d7236e commit 35bf541

26 files changed

+506
-83
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module.exports = {
77
'no-template-curly-in-string': 0,
88
'prefer-promise-reject-errors': 0,
99
'react/no-array-index-key': 0,
10+
'react/sort-comp': 0,
1011
},
1112
};

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open http://localhost:9001/
3737
```js
3838
import Form, { Field } from 'rc-field-form';
3939

40-
<StateForm
40+
<Form
4141
onFinish={values => {
4242
console.log('Finish:', values);
4343
}}
@@ -50,7 +50,7 @@ import Form, { Field } from 'rc-field-form';
5050
</Field>
5151

5252
<button>Submit</button>
53-
</StateForm>;
53+
</Form>;
5454

5555
export default Demo;
5656
```

examples/StateForm-basic.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import StateForm, { Field } from '../src/';
2+
import Form, { Field } from '../src/';
33
import Input from './components/Input';
44

55

@@ -12,7 +12,7 @@ export default class Demo extends React.Component {
1212
return (
1313
<div>
1414
<h3>State Form ({list.length} inputs)</h3>
15-
<StateForm>
15+
<Form>
1616
<Field name="username">
1717
<Input placeholder="Username" />
1818
</Field>
@@ -48,7 +48,7 @@ export default class Demo extends React.Component {
4848
<Input placeholder={`field_${index}`} />
4949
</Field>
5050
))}
51-
</StateForm>
51+
</Form>
5252
</div>
5353
);
5454
}

examples/StateForm-context.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react/prop-types */
22

33
import React from 'react';
4-
import StateForm, { FormProvider } from '../src';
4+
import Form, { FormProvider } from '../src';
55
import Input from './components/Input';
66
import LabelField from './components/LabelField';
77
import { ValidateMessages } from '../src/interface';
@@ -16,10 +16,10 @@ const formStyle: React.CSSProperties = {
1616
};
1717

1818
const Form1 = () => {
19-
const [form] = StateForm.useForm();
19+
const [form] = Form.useForm();
2020

2121
return (
22-
<StateForm form={form} style={{ ...formStyle, border: '1px solid #000' }} name="first">
22+
<Form form={form} style={{ ...formStyle, border: '1px solid #000' }} name="first">
2323
<h4>Form 1</h4>
2424
<p>Change me!</p>
2525
<LabelField name="username" rules={[{ required: true }]}>
@@ -30,15 +30,15 @@ const Form1 = () => {
3030
</LabelField>
3131

3232
<button type="submit">Submit</button>
33-
</StateForm>
33+
</Form>
3434
);
3535
};
3636

3737
const Form2 = () => {
38-
const [form] = StateForm.useForm();
38+
const [form] = Form.useForm();
3939

4040
return (
41-
<StateForm form={form} style={{ ...formStyle, border: '1px solid #F00' }} name="second">
41+
<Form form={form} style={{ ...formStyle, border: '1px solid #F00' }} name="second">
4242
<h4>Form 2</h4>
4343
<p>Will follow Form 1 but not sync back</p>
4444
<LabelField name="username" rules={[{ required: true }]}>
@@ -49,7 +49,7 @@ const Form2 = () => {
4949
</LabelField>
5050

5151
<button type="submit">Submit</button>
52-
</StateForm>
52+
</Form>
5353
);
5454
};
5555

examples/StateForm-layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable jsx-a11y/label-has-associated-control, react/prop-types */
22

33
import React from 'react';
4-
import StateForm from '../src';
4+
import Form from '../src';
55
import Input from './components/Input';
66
import LabelField from './components/LabelField';
77

@@ -14,7 +14,7 @@ export default class Demo extends React.Component {
1414
return (
1515
<div>
1616
<h3>State Form ({list.length} inputs)</h3>
17-
<StateForm>
17+
<Form>
1818
<LabelField name="username">
1919
<Input placeholder="Username" />
2020
</LabelField>
@@ -24,7 +24,7 @@ export default class Demo extends React.Component {
2424
<LabelField name={['path1', 'path2']} label="Nest Path" rules={[ { required: true } ]}>
2525
<Input placeholder="nest" />
2626
</LabelField>
27-
</StateForm>
27+
</Form>
2828
</div>
2929
);
3030
}

examples/StateForm-list.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable react/prop-types */
22

33
import React from 'react';
4-
import StateForm from '../src/';
4+
import Form from '../src/';
55
import Input from './components/Input';
66
import LabelField from './components/LabelField';
77

8-
const { List, useForm } = StateForm;
8+
const { List, useForm } = Form;
99

1010
const Demo = () => {
1111
const [form] = useForm();
@@ -15,7 +15,7 @@ const Demo = () => {
1515
<h3>List of Form</h3>
1616
<p>You can set Field as List</p>
1717

18-
<StateForm
18+
<Form
1919
form={form}
2020
onValuesChange={(_, values) => {
2121
console.log('values:', values);
@@ -62,7 +62,7 @@ const Demo = () => {
6262
);
6363
}}
6464
</List>
65-
</StateForm>
65+
</Form>
6666

6767
<div style={{ border: '1px solid #000', padding: 15 }}>
6868
<h4>Out Of Form</h4>

examples/StateForm-redux.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React from 'react';
44
import { connect, Provider } from 'react-redux';
55
import { createStore } from 'redux';
6-
import StateForm from '../src/';
6+
import Form from '../src/';
77
import Input from './components/Input';
88
import LabelField from './components/LabelField';
99

@@ -22,7 +22,7 @@ let App: any = ({ dispatch, fields }) => {
2222
console.log('=>', fields);
2323

2424
return (
25-
<StateForm
25+
<Form
2626
fields={fields}
2727
onValuesChange={(changedValues, allValues) => {
2828
console.log('Value Change:', changedValues, allValues);
@@ -42,8 +42,8 @@ let App: any = ({ dispatch, fields }) => {
4242
<Input />
4343
</LabelField>
4444

45-
<LabelField name="required" placeholder="required" rules={[{ required: true }]}>
46-
<Input />
45+
<LabelField name="required" rules={[{ required: true }]}>
46+
<Input placeholder="required" />
4747
</LabelField>
4848

4949
<button
@@ -71,7 +71,7 @@ let App: any = ({ dispatch, fields }) => {
7171
>
7272
dispatch to change
7373
</button>
74-
</StateForm>
74+
</Form>
7575
);
7676
};
7777
App = connect((fields: any) => ({ fields }))(App);

examples/StateForm-renderProps.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable jsx-a11y/label-has-associated-control */
22
import React from 'react';
3-
import StateForm from '../src';
3+
import Form from '../src';
44
import Input from './components/Input';
55

6-
const { Field } = StateForm;
6+
const { Field } = Form;
77

88
const list = new Array(1111).fill(() => undefined);
99

@@ -15,7 +15,7 @@ export default class Demo extends React.Component {
1515
<div>
1616
<h3>Render Props ({list.length} inputs)</h3>
1717
<p>Render Props is easy to use but bad performance</p>
18-
<StateForm>
18+
<Form>
1919
{(values) => {
2020
return (
2121
<React.Fragment>
@@ -55,7 +55,7 @@ export default class Demo extends React.Component {
5555
</React.Fragment>
5656
);
5757
}}
58-
</StateForm>
58+
</Form>
5959
</div>
6060
);
6161
}

examples/StateForm-reset.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable react/prop-types */
22
import React from 'react';
3-
import StateForm from '../src';
3+
import Form from '../src';
44
import Input from './components/Input';
55

6-
const { Field } = StateForm;
6+
const { Field } = Form;
77

88
function Item({ children, ...restProps }) {
99
return (
@@ -24,11 +24,11 @@ function Item({ children, ...restProps }) {
2424
}
2525

2626
const Demo = () => {
27-
const [form] = StateForm.useForm();
27+
const [form] = Form.useForm();
2828
return (
2929
<div>
3030
<h3>Reset / Set Form</h3>
31-
<StateForm form={form} initialValues={{ username: 'strange', path1: { path2: '233' } }}>
31+
<Form form={form} initialValues={{ username: 'strange', path1: { path2: '233' } }}>
3232
<Item name="username" rules={[{ required: true }]}>
3333
<Input placeholder="Username" />
3434
</Item>
@@ -64,7 +64,7 @@ const Demo = () => {
6464
>
6565
Set Password with Errors
6666
</button>
67-
</StateForm>
67+
</Form>
6868
</div>
6969
);
7070
};

examples/StateForm-useForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
2-
import StateForm from '../src';
2+
import Form from '../src';
33
import Input from './components/Input';
44

5-
const { Field, useForm } = StateForm;
5+
const { Field, useForm } = Form;
66

77
const list = new Array(0).fill(() => undefined);
88

@@ -22,7 +22,7 @@ export default () => {
2222
Fill Values
2323
</button>
2424

25-
<StateForm form={form}>
25+
<Form form={form}>
2626
<React.Fragment>
2727
<Field name="username">
2828
<Input placeholder="Username" />
@@ -43,7 +43,7 @@ export default () => {
4343
</Field>
4444
))}
4545
</React.Fragment>
46-
</StateForm>
46+
</Form>
4747
</div>
4848
);
4949
};

0 commit comments

Comments
 (0)