Skip to content

Commit 2c1a850

Browse files
committed
Added link to code example source.
1 parent 865e5b3 commit 2c1a850

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/react-renderer-demo/src/app/pages/testing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ Always make sure that your **custom components** and their features are tested t
1111

1212
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.
1313

14+
1415
## Testing the renderer
1516

1617
If you want to test your whole form, the easiest way is just to render it as you would normally. Be careful that you will have to mock all your async validations and submissions. Data driven forms have great test coverage so its not necessary to test core features.
1718

1819
Below is an example of a form with an 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.
1920

2021
<CodeExample source="tests/form-renderer.test" />
22+
<br/>
2123

2224
## Testing custom components
2325

@@ -28,12 +30,14 @@ Components that are using `useFieldApi` or `useFormApi` must be children of cont
2830
Set up your renderer to make it easier to test the component-specific features. Use initial values to trigger falsey validation results to avoid unnecessary changes simulation.
2931

3032
<CodeExample source="tests/custom-component-with-renderer.test" />
33+
<br/>
3134

3235
### Outside renderer
3336

34-
Rendering components outside of the renderer will require some additional set up which is not traditionally used when using form renderer and require some additional knowledge of the library. Most notably, you need to wrap the component inside the `Form` component and `RendererContext`. No functionality provided by the renderer like validations or conditions will be provided so it must be configured.
37+
Rendering components outside of the renderer will require some additional set up which is not traditionally used when using form renderer and require some additional knowledge of the library. Most notably, you need to wrap the component inside the `Form` component and `RendererContext`. Be careful, no Data Driven Forms functionality is provided, so you have to configure it manually, if you need need to use it.
3538

3639
<CodeExample source="tests/custom-component-outside-renderer.test" />
40+
<br/>
3741

3842
</Grid>
3943
<Grid item xs={false} md={2}>

packages/react-renderer-demo/src/app/src/components/code-example.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React from 'react';
22
import Grid from '@material-ui/core/Grid';
3+
import { makeStyles } from '@material-ui/core/styles';
4+
import Typography from '@material-ui/core/Typography';
5+
import Link from '@material-ui/core/Link';
6+
import Box from '@material-ui/core/Box';
37

48
import dynamic from 'next/dynamic';
59
import PropTypes from 'prop-types';
@@ -10,11 +14,33 @@ const CodeEditor = dynamic(import('./code-editor'), {
1014

1115
const reqSource = require.context('!raw-loader!@data-driven-forms/examples', true, /\.js/);
1216

17+
const useStyles = makeStyles(() => ({
18+
codeWrapper: {
19+
background: '#1D1F21',
20+
paddingTop: 16,
21+
paddingBottom: 16
22+
}
23+
}));
24+
1325
const CodeExample = ({ source }) => {
1426
const codeSource = reqSource(`./src/${source}.js`).default;
27+
const classes = useStyles();
1528
return (
1629
<Grid container spacing={0} className="DocRawComponent">
1730
<Grid item xs={12}>
31+
<Box display="flex" justifyContent="flex-end">
32+
<Link
33+
href={`https://github.com/data-driven-forms/react-forms/tree/master/packages/examples/src/${source}.js`}
34+
target="_blank"
35+
rel="noopener noreferrer"
36+
>
37+
<Typography variant="subtitle1" component="h1">
38+
View source on github
39+
</Typography>
40+
</Link>
41+
</Box>
42+
</Grid>
43+
<Grid item xs={12} className={classes.codeWrapper}>
1844
<CodeEditor value={codeSource} />
1945
</Grid>
2046
</Grid>

0 commit comments

Comments
 (0)