Skip to content

Commit 668ee73

Browse files
committed
Added example for renderer testing to docs.
1 parent 029083d commit 668ee73

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

packages/mui-component-mapper/demo/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ const compositeMapper = {
2727
}
2828

2929

30+
const schema = {
31+
fields: [{
32+
component: 'switch',
33+
name: 'foo',
34+
label: 'Foo'
35+
}, {
36+
component: 'text-field',
37+
name: 'bar',
38+
label: 'bar',
39+
condition: {
40+
when: 'foo',
41+
is: true
42+
}
43+
}]
44+
}
45+
3046
const App = () => (
3147
<ThemeProvider theme={ theme }>
3248
<Grid
@@ -43,7 +59,7 @@ const App = () => (
4359
onSubmit={console.log}
4460
componentMapper={compositeMapper}
4561
FormTemplate={props => <FormTemplate {...props} />}
46-
schema={demoSchema}
62+
schema={schema}
4763
onCancel={() => console.log('canceling')}
4864
/>
4965
</Grid>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Grid from '@material-ui/core/Grid'
2+
import ListOfContents from '../src/helpers/list-of-contents';
3+
import CodeExample from '../src/components/code-example';
4+
5+
<Grid container item>
6+
<Grid item xs={12} md={10}>
7+
8+
# Testing
9+
10+
Always make sure that your **custom components** and their features are tested to avoid bugs and runtime crashes.
11+
12+
In these examples we will use [Jest](https://jestjs.io/) and [Enzyme](https://enzymejs.github.io/enzyme/docs/api/) but the same rules apply to any other testing libraries.
13+
14+
## Testing the renderer
15+
16+
If you want to test your whole form, the easiest way is just to render it as you would normaly. Be carefoul that you will have to mock all your async validations and submitions. Data driven forms have a great test coverage so its not necessary to test core features.
17+
18+
Bellow is an example of a form with a async validation and a conditional field. All features in the data driven forms packages are tested by the library. It should not be required to tests them most of the time.
19+
20+
<CodeExample source="tests/form-renderer.test" />
21+
22+
</Grid>
23+
<Grid item xs={false} md={2}>
24+
<ListOfContents file="testing" />
25+
</Grid>
26+
</Grid>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import Grid from '@material-ui/core/Grid';
3+
4+
import dynamic from 'next/dynamic';
5+
import PropTypes from 'prop-types';
6+
7+
const CodeEditor = dynamic(import('./code-editor'), {
8+
ssr: false
9+
});
10+
11+
const reqSource = require.context('!raw-loader!@data-driven-forms/examples', true, /\.js/);
12+
13+
const CodeExample = ({ source }) => {
14+
const codeSource = reqSource(`./src/${source}.js`).default;
15+
return (
16+
<Grid container spacing={0} className="DocRawComponent">
17+
<Grid item xs={12}>
18+
<CodeEditor value={codeSource} />
19+
</Grid>
20+
</Grid>
21+
);
22+
};
23+
24+
CodeExample.propTypes = {
25+
source: PropTypes.string.isRequired
26+
};
27+
28+
export default CodeExample;

packages/react-renderer-demo/src/app/src/components/navigation/schema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const schema = [
1919
noRoute: true,
2020
fields: [...baseExamples.sort((a, b) => a.linkText.localeCompare(b.linkText))]
2121
},
22+
{
23+
linkText: 'Testing',
24+
link: 'testing'
25+
},
2226
{
2327
linkText: 'Releases',
2428
link: 'releases'

yarn.lock

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,11 @@
32133213
"@types/d3-voronoi" "*"
32143214
"@types/d3-zoom" "*"
32153215

3216+
"@types/debounce-promise@^3.1.1":
3217+
version "3.1.1"
3218+
resolved "https://registry.yarnpkg.com/@types/debounce-promise/-/debounce-promise-3.1.1.tgz#38fcb523f7d11d521fca2e8ccb43f0982fbf5ce7"
3219+
integrity sha512-eOSiMKpPYI5Cx5tmx4xQ1e0bLz9n56NVv4ao0YQcYtIJYZjdoCDFvZwIQgXDiFHU5SFtKtN2vcqx5ZIXvj1Ccg==
3220+
32163221
"@types/duplexify@^3.6.0":
32173222
version "3.6.0"
32183223
resolved "https://registry.yarnpkg.com/@types/duplexify/-/duplexify-3.6.0.tgz#dfc82b64bd3a2168f5bd26444af165bf0237dcd8"
@@ -4248,6 +4253,28 @@ autoprefixer@^9.6.1:
42484253
postcss "^7.0.21"
42494254
postcss-value-parser "^4.0.2"
42504255

4256+
awesome-debounce-promise@^2.1.0:
4257+
version "2.1.0"
4258+
resolved "https://registry.yarnpkg.com/awesome-debounce-promise/-/awesome-debounce-promise-2.1.0.tgz#7c21cadf2eaa1fa0a29449dd4dfdbd5004811e53"
4259+
integrity sha512-0Dv4j2wKk5BrNZh4jgV2HUdznaeVgEK/WTvcHhZWUElhmQ1RR+iURRoLEwICFyR0S/5VtxfcvY6gR+qSe95jNg==
4260+
dependencies:
4261+
"@types/debounce-promise" "^3.1.1"
4262+
awesome-imperative-promise "^1.0.1"
4263+
awesome-only-resolves-last-promise "^1.0.3"
4264+
debounce-promise "^3.1.0"
4265+
4266+
awesome-imperative-promise@^1.0.1:
4267+
version "1.0.1"
4268+
resolved "https://registry.yarnpkg.com/awesome-imperative-promise/-/awesome-imperative-promise-1.0.1.tgz#be143d89615b9110ac310345457f37e9791ddac9"
4269+
integrity sha512-EmPr3FqbQGqlNh+WxMNcF9pO9uDQJnOC4/3rLBQNH9m4E9qI+8lbfHCmHpVAsmGqPJPKhCjJLHUQzQW/RBHRdQ==
4270+
4271+
awesome-only-resolves-last-promise@^1.0.3:
4272+
version "1.0.3"
4273+
resolved "https://registry.yarnpkg.com/awesome-only-resolves-last-promise/-/awesome-only-resolves-last-promise-1.0.3.tgz#f2dac3ff7df238e48b818b423483031750f13ef0"
4274+
integrity sha512-7q4WPsYiD8Omvi/yHL314DkvsD/lM//Z2/KcU1vWk0xJotiV0GMJTgHTpWl3n90HJqpXKg7qX+VVNs5YbQyPRQ==
4275+
dependencies:
4276+
awesome-imperative-promise "^1.0.1"
4277+
42514278
aws-sign2@~0.7.0:
42524279
version "0.7.0"
42534280
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
@@ -6902,6 +6929,11 @@ dateformat@^3.0.0:
69026929
version "3.0.3"
69036930
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
69046931

6932+
debounce-promise@^3.1.0:
6933+
version "3.1.2"
6934+
resolved "https://registry.yarnpkg.com/debounce-promise/-/debounce-promise-3.1.2.tgz#320fb8c7d15a344455cd33cee5ab63530b6dc7c5"
6935+
integrity sha512-rZHcgBkbYavBeD9ej6sP56XfG53d51CD4dnaw989YX/nZ/ZJfgRx/9ePKmTNiUiyQvh4mtrMoS3OAWW+yoYtpg==
6936+
69056937
[email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
69066938
version "2.6.9"
69076939
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"

0 commit comments

Comments
 (0)