@ukhomeoffice/cop-react-form-renderer 2.0.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
- package/dist/components/FormComponent/FormComponent.js +6 -1
- package/dist/components/FormComponent/FormComponent.test.js +67 -0
- package/dist/components/FormRenderer/FormRenderer.js +122 -11
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
- package/dist/components/FormRenderer/FormRenderer.test.js +275 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
- package/dist/components/FormRenderer/helpers/getPage.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
- package/dist/components/FormRenderer/helpers/index.js +7 -1
- package/dist/components/SummaryList/SummaryList.js +7 -4
- package/dist/components/SummaryList/SummaryList.scss +10 -2
- package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
- package/dist/components/SummaryList/SummaryList.test.js +54 -0
- package/dist/components/TaskList/Task.js +83 -0
- package/dist/components/TaskList/Task.test.js +112 -0
- package/dist/components/TaskList/TaskList.js +112 -0
- package/dist/components/TaskList/TaskList.scss +70 -0
- package/dist/components/TaskList/TaskList.stories.mdx +57 -0
- package/dist/components/TaskList/TaskList.test.js +223 -0
- package/dist/components/TaskList/TaskState.js +42 -0
- package/dist/components/TaskList/TaskState.test.js +99 -0
- package/dist/components/TaskList/index.js +13 -0
- package/dist/hooks/useHooks.js +5 -1
- package/dist/index.js +8 -0
- package/dist/json/taskList.json +228 -0
- package/dist/json/userProfile.data.json +2 -1
- package/dist/models/ComponentTypes.js +3 -1
- package/dist/models/FormTypes.js +2 -0
- package/dist/models/HubFormats.js +3 -1
- package/dist/models/PageAction.js +5 -0
- package/dist/models/TaskStates.js +41 -0
- package/dist/models/index.js +8 -0
- package/dist/utils/Component/cleanAttributes.js +1 -1
- package/dist/utils/Component/getComponent.js +26 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/FormPage/getPageActions.js +6 -0
- package/dist/utils/Hub/getFormHub.js +4 -0
- package/dist/utils/Hub/getFormHub.test.js +10 -2
- package/dist/utils/Validate/additional/index.js +55 -0
- package/dist/utils/Validate/additional/index.test.js +69 -0
- package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
- package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
- package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
- package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
- package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
- package/dist/utils/Validate/additional/utils.js +66 -0
- package/dist/utils/Validate/validateComponent.js +38 -1
- package/dist/utils/Validate/validateComponent.test.js +48 -2
- package/dist/utils/Validate/validateDate.js +144 -0
- package/dist/utils/Validate/validateDate.test.js +112 -0
- package/dist/utils/Validate/validateRequired.js +11 -0
- package/dist/utils/Validate/validateRequired.test.js +12 -0
- package/dist/utils/Validate/validateTime.js +76 -0
- package/dist/utils/Validate/validateTime.test.js +55 -0
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -36,3 +36,15 @@ Runs Storybook on [http://localhost:6007](http://localhost:6007), which showcase
|
|
|
36
36
|
### `yarn storybook:build`
|
|
37
37
|
|
|
38
38
|
Builds Storybook for production to the `storybook-static` folder.
|
|
39
|
+
|
|
40
|
+
# Using the Service
|
|
41
|
+
## Versioning
|
|
42
|
+
For versioning this project uses SemVer.
|
|
43
|
+
|
|
44
|
+
## Authors
|
|
45
|
+
This project is authored by the Home Office.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
This project is licensed under the MIT license. For details please see [License](./LICENSE).
|
|
49
|
+
|
|
50
|
+
This project contains public sector information licensed under the Open Government Licence v3.0. (http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/)
|
|
@@ -61,7 +61,10 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
61
61
|
_onAction = _ref.onAction,
|
|
62
62
|
onRowAction = _ref.onRowAction,
|
|
63
63
|
hide_page_titles = _ref.hide_page_titles,
|
|
64
|
-
hide_actions = _ref.hide_actions
|
|
64
|
+
hide_actions = _ref.hide_actions,
|
|
65
|
+
hide_title = _ref.hide_title,
|
|
66
|
+
summaryListClassModifiers = _ref.summaryListClassModifiers,
|
|
67
|
+
noChangeAction = _ref.noChangeAction;
|
|
65
68
|
|
|
66
69
|
var _useState = (0, _react.useState)([]),
|
|
67
70
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -109,7 +112,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
109
112
|
|
|
110
113
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
111
114
|
className: DEFAULT_CLASS
|
|
112
|
-
}, title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, {
|
|
115
|
+
}, title && !hide_title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, {
|
|
113
116
|
key: "heading"
|
|
114
117
|
}, title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
|
|
115
118
|
errors: errors
|
|
@@ -120,7 +123,9 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
120
123
|
key: pageIndex
|
|
121
124
|
}, !hide_page_titles && page.title && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, page.title), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
122
125
|
className: className,
|
|
123
|
-
rows: page.rows
|
|
126
|
+
rows: page.rows,
|
|
127
|
+
classModifiers: summaryListClassModifiers,
|
|
128
|
+
noChangeAction: noChangeAction
|
|
124
129
|
}));
|
|
125
130
|
}), !hide_actions && /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
126
131
|
actions: actions,
|
|
@@ -137,12 +142,18 @@ CheckYourAnswers.propTypes = {
|
|
|
137
142
|
onAction: _propTypes.default.func.isRequired,
|
|
138
143
|
onRowAction: _propTypes.default.func.isRequired,
|
|
139
144
|
hide_page_titles: _propTypes.default.bool,
|
|
140
|
-
hide_actions: _propTypes.default.bool
|
|
145
|
+
hide_actions: _propTypes.default.bool,
|
|
146
|
+
hide_title: _propTypes.default.bool,
|
|
147
|
+
summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
148
|
+
noChangeAction: _propTypes.default.bool
|
|
141
149
|
};
|
|
142
150
|
CheckYourAnswers.defaultProps = {
|
|
143
151
|
title: DEFAULT_TITLE,
|
|
144
152
|
hide_page_titles: false,
|
|
145
|
-
hide_actions: false
|
|
153
|
+
hide_actions: false,
|
|
154
|
+
hide_title: false,
|
|
155
|
+
summaryListClassModifiers: null,
|
|
156
|
+
noChangeAction: false
|
|
146
157
|
};
|
|
147
158
|
var _default = CheckYourAnswers;
|
|
148
159
|
exports.default = _default;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
<!-- Global imports -->
|
|
2
|
+
|
|
2
3
|
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Details,
|
|
6
|
+
Heading,
|
|
7
|
+
Link,
|
|
8
|
+
Tag,
|
|
9
|
+
} from '@ukhomeoffice/cop-react-components';
|
|
4
10
|
import withMock from 'storybook-addon-mock';
|
|
5
11
|
|
|
6
12
|
<!-- Local imports -->
|
|
13
|
+
|
|
7
14
|
import Utils from '../../utils';
|
|
8
15
|
import CheckYourAnswers from './CheckYourAnswers';
|
|
9
16
|
|
|
10
17
|
<!-- JSON documents -->
|
|
18
|
+
|
|
11
19
|
import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
|
|
12
20
|
import GRADE from '../../json/grade.json';
|
|
13
21
|
import TEAMS from '../../json/team.json';
|
|
@@ -15,38 +23,56 @@ import USER_PROFILE_DATA from '../../json/userProfile.data.json';
|
|
|
15
23
|
import USER_PROFILE from '../../json/userProfile.json';
|
|
16
24
|
import FIRST_FORM from '../../json/firstForm.json';
|
|
17
25
|
|
|
18
|
-
<Meta
|
|
26
|
+
<Meta
|
|
27
|
+
title='Components/Check your answers'
|
|
28
|
+
id='D-CheckYourAnswers'
|
|
29
|
+
component={CheckYourAnswers}
|
|
30
|
+
decorators={[withMock]}
|
|
31
|
+
/>
|
|
19
32
|
|
|
20
|
-
<Heading size=
|
|
33
|
+
<Heading size='xl' caption='Components'>
|
|
34
|
+
Check your answers
|
|
35
|
+
</Heading>
|
|
21
36
|
|
|
22
37
|
Renders the **Check your answers** screen for a form.
|
|
23
38
|
|
|
24
39
|
<Canvas withToolbar>
|
|
25
|
-
<Story
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
<Story
|
|
41
|
+
name='Default'
|
|
42
|
+
parameters={{
|
|
43
|
+
mockData: [
|
|
44
|
+
{
|
|
45
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
46
|
+
method: 'GET',
|
|
47
|
+
status: 200,
|
|
48
|
+
response: CIVIL_SERVANT,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
52
|
+
method: 'GET',
|
|
53
|
+
status: 200,
|
|
54
|
+
response: GRADE,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
58
|
+
method: 'GET',
|
|
59
|
+
status: 200,
|
|
60
|
+
response: TEAMS,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
47
65
|
{() => {
|
|
48
|
-
const DATA = Utils.Data.setupForm(
|
|
49
|
-
|
|
66
|
+
const DATA = Utils.Data.setupForm(
|
|
67
|
+
USER_PROFILE.pages,
|
|
68
|
+
USER_PROFILE.components,
|
|
69
|
+
USER_PROFILE_DATA
|
|
70
|
+
);
|
|
71
|
+
const PAGES = Utils.FormPage.getAll(
|
|
72
|
+
USER_PROFILE.pages,
|
|
73
|
+
USER_PROFILE.components,
|
|
74
|
+
{ ...DATA }
|
|
75
|
+
);
|
|
50
76
|
const ON_ACTION = (action, patch, onError) => {
|
|
51
77
|
console.log('action invoked', action, patch);
|
|
52
78
|
};
|
|
@@ -54,45 +80,61 @@ Renders the **Check your answers** screen for a form.
|
|
|
54
80
|
console.log('row action invoked', page);
|
|
55
81
|
};
|
|
56
82
|
return (
|
|
57
|
-
<CheckYourAnswers
|
|
83
|
+
<CheckYourAnswers
|
|
84
|
+
pages={PAGES}
|
|
85
|
+
onAction={ON_ACTION}
|
|
86
|
+
onRowAction={ON_ROW_ACTION}
|
|
87
|
+
/>
|
|
58
88
|
);
|
|
59
89
|
}}
|
|
60
90
|
</Story>
|
|
61
91
|
</Canvas>
|
|
62
92
|
|
|
63
|
-
<Details summary=
|
|
64
|
-
<ArgsTable of={
|
|
93
|
+
<Details summary='Properties' className='no-indent'>
|
|
94
|
+
<ArgsTable of={CheckYourAnswers} />
|
|
65
95
|
</Details>
|
|
66
96
|
|
|
67
97
|
## Variant
|
|
98
|
+
|
|
68
99
|
### Without page titles
|
|
69
100
|
|
|
70
101
|
<Canvas>
|
|
71
|
-
<Story
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
<Story
|
|
103
|
+
name='No page titles'
|
|
104
|
+
parameters={{
|
|
105
|
+
mockData: [
|
|
106
|
+
{
|
|
107
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
108
|
+
method: 'GET',
|
|
109
|
+
status: 200,
|
|
110
|
+
response: CIVIL_SERVANT,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
114
|
+
method: 'GET',
|
|
115
|
+
status: 200,
|
|
116
|
+
response: GRADE,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
120
|
+
method: 'GET',
|
|
121
|
+
status: 200,
|
|
122
|
+
response: TEAMS,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
93
127
|
{() => {
|
|
94
|
-
const DATA = Utils.Data.setupForm(
|
|
95
|
-
|
|
128
|
+
const DATA = Utils.Data.setupForm(
|
|
129
|
+
USER_PROFILE.pages,
|
|
130
|
+
USER_PROFILE.components,
|
|
131
|
+
USER_PROFILE_DATA
|
|
132
|
+
);
|
|
133
|
+
const PAGES = Utils.FormPage.getAll(
|
|
134
|
+
USER_PROFILE.pages,
|
|
135
|
+
USER_PROFILE.components,
|
|
136
|
+
{ ...DATA }
|
|
137
|
+
);
|
|
96
138
|
const ON_ACTION = (action, patch, onError) => {
|
|
97
139
|
console.log('action invoked', action, patch);
|
|
98
140
|
};
|
|
@@ -100,7 +142,12 @@ Renders the **Check your answers** screen for a form.
|
|
|
100
142
|
console.log('row action invoked', page);
|
|
101
143
|
};
|
|
102
144
|
return (
|
|
103
|
-
<CheckYourAnswers
|
|
145
|
+
<CheckYourAnswers
|
|
146
|
+
pages={PAGES}
|
|
147
|
+
hide_page_titles={true}
|
|
148
|
+
onAction={ON_ACTION}
|
|
149
|
+
onRowAction={ON_ROW_ACTION}
|
|
150
|
+
/>
|
|
104
151
|
);
|
|
105
152
|
}}
|
|
106
153
|
</Story>
|
|
@@ -109,31 +156,38 @@ Renders the **Check your answers** screen for a form.
|
|
|
109
156
|
### With actions
|
|
110
157
|
|
|
111
158
|
<Canvas>
|
|
112
|
-
<Story
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
159
|
+
<Story
|
|
160
|
+
name='With actions'
|
|
161
|
+
parameters={{
|
|
162
|
+
mockData: [
|
|
163
|
+
{
|
|
164
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
165
|
+
method: 'GET',
|
|
166
|
+
status: 200,
|
|
167
|
+
response: CIVIL_SERVANT,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
171
|
+
method: 'GET',
|
|
172
|
+
status: 200,
|
|
173
|
+
response: GRADE,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
177
|
+
method: 'GET',
|
|
178
|
+
status: 200,
|
|
179
|
+
response: TEAMS,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
134
184
|
{() => {
|
|
135
185
|
const DATA = { firstName: 'John', surname: 'Smith', age: 41 };
|
|
136
|
-
const PAGES = Utils.FormPage.getAll(
|
|
186
|
+
const PAGES = Utils.FormPage.getAll(
|
|
187
|
+
FIRST_FORM.pages,
|
|
188
|
+
FIRST_FORM.components,
|
|
189
|
+
{ ...DATA }
|
|
190
|
+
);
|
|
137
191
|
const ACTIONS = FIRST_FORM.cya.actions;
|
|
138
192
|
const ON_ACTION = (action, patch, onError) => {
|
|
139
193
|
console.log('action invoked', action, patch);
|
|
@@ -142,7 +196,73 @@ Renders the **Check your answers** screen for a form.
|
|
|
142
196
|
console.log('row action invoked', page);
|
|
143
197
|
};
|
|
144
198
|
return (
|
|
145
|
-
<CheckYourAnswers
|
|
199
|
+
<CheckYourAnswers
|
|
200
|
+
pages={PAGES}
|
|
201
|
+
hide_page_titles={true}
|
|
202
|
+
actions={ACTIONS}
|
|
203
|
+
onAction={ON_ACTION}
|
|
204
|
+
onRowAction={ON_ROW_ACTION}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
}}
|
|
208
|
+
</Story>
|
|
209
|
+
</Canvas>
|
|
210
|
+
|
|
211
|
+
### Read-only style
|
|
212
|
+
|
|
213
|
+
<Canvas>
|
|
214
|
+
<Story
|
|
215
|
+
name='Read-only style'
|
|
216
|
+
parameters={{
|
|
217
|
+
mockData: [
|
|
218
|
+
{
|
|
219
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
220
|
+
method: 'GET',
|
|
221
|
+
status: 200,
|
|
222
|
+
response: CIVIL_SERVANT,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
226
|
+
method: 'GET',
|
|
227
|
+
status: 200,
|
|
228
|
+
response: GRADE,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
232
|
+
method: 'GET',
|
|
233
|
+
status: 200,
|
|
234
|
+
response: TEAMS,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
}}
|
|
238
|
+
>
|
|
239
|
+
{() => {
|
|
240
|
+
const DATA = Utils.Data.setupForm(
|
|
241
|
+
USER_PROFILE.pages,
|
|
242
|
+
USER_PROFILE.components,
|
|
243
|
+
USER_PROFILE_DATA
|
|
244
|
+
);
|
|
245
|
+
const PAGES = Utils.FormPage.getAll(
|
|
246
|
+
USER_PROFILE.pages,
|
|
247
|
+
USER_PROFILE.components,
|
|
248
|
+
{ ...DATA }
|
|
249
|
+
);
|
|
250
|
+
const ON_ACTION = (action, patch, onError) => {
|
|
251
|
+
console.log('action invoked', action, patch);
|
|
252
|
+
};
|
|
253
|
+
const ON_ROW_ACTION = (page) => {
|
|
254
|
+
console.log('row action invoked', page);
|
|
255
|
+
};
|
|
256
|
+
return (
|
|
257
|
+
<CheckYourAnswers
|
|
258
|
+
pages={PAGES}
|
|
259
|
+
hide_page_titles={true}
|
|
260
|
+
onAction={ON_ACTION}
|
|
261
|
+
onRowAction={ON_ROW_ACTION}
|
|
262
|
+
hide_title={true}
|
|
263
|
+
summaryListClassModifiers='no-border'
|
|
264
|
+
noChangeAction={true}
|
|
265
|
+
/>
|
|
146
266
|
);
|
|
147
267
|
}}
|
|
148
268
|
</Story>
|
|
@@ -328,5 +328,49 @@ describe('components', function () {
|
|
|
328
328
|
}
|
|
329
329
|
}, _callee10);
|
|
330
330
|
})));
|
|
331
|
+
it('should show no title if is set to hidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
|
|
332
|
+
var cya, _cya$childNodes4, names, _names$childNodes2, firstName, surname;
|
|
333
|
+
|
|
334
|
+
return regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
335
|
+
while (1) {
|
|
336
|
+
switch (_context12.prev = _context12.next) {
|
|
337
|
+
case 0:
|
|
338
|
+
_context12.next = 2;
|
|
339
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
|
|
340
|
+
return regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
341
|
+
while (1) {
|
|
342
|
+
switch (_context11.prev = _context11.next) {
|
|
343
|
+
case 0:
|
|
344
|
+
(0, _reactDom.render)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
345
|
+
pages: PAGES,
|
|
346
|
+
onRowAction: ON_ROW_ACTION,
|
|
347
|
+
onAction: ON_ACTION,
|
|
348
|
+
hide_title: true
|
|
349
|
+
}), container);
|
|
350
|
+
|
|
351
|
+
case 1:
|
|
352
|
+
case "end":
|
|
353
|
+
return _context11.stop();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}, _callee11);
|
|
357
|
+
})));
|
|
358
|
+
|
|
359
|
+
case 2:
|
|
360
|
+
cya = checkCYA(container);
|
|
361
|
+
_cya$childNodes4 = _slicedToArray(cya.childNodes, 1), names = _cya$childNodes4[0];
|
|
362
|
+
expect(names.tagName).toEqual('DL');
|
|
363
|
+
expect(names.classList).toContain("govuk-!-margin-bottom-".concat(_CheckYourAnswers.DEFAULT_MARGIN_BOTTOM));
|
|
364
|
+
_names$childNodes2 = _slicedToArray(names.childNodes, 2), firstName = _names$childNodes2[0], surname = _names$childNodes2[1];
|
|
365
|
+
checkRow(firstName, 'First name', 'John', false);
|
|
366
|
+
checkRow(surname, 'Last name', 'Smith', false);
|
|
367
|
+
|
|
368
|
+
case 9:
|
|
369
|
+
case "end":
|
|
370
|
+
return _context12.stop();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}, _callee12);
|
|
374
|
+
})));
|
|
331
375
|
});
|
|
332
376
|
});
|
|
@@ -11,6 +11,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _react = require("react");
|
|
13
13
|
|
|
14
|
+
var _useHooks2 = _interopRequireDefault(require("../../hooks/useHooks"));
|
|
15
|
+
|
|
14
16
|
var _useRefData2 = _interopRequireWildcard(require("../../hooks/useRefData"));
|
|
15
17
|
|
|
16
18
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
@@ -52,6 +54,9 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
52
54
|
onChange = _ref.onChange,
|
|
53
55
|
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
54
56
|
|
|
57
|
+
var _useHooks = (0, _useHooks2.default)(),
|
|
58
|
+
hooks = _useHooks.hooks;
|
|
59
|
+
|
|
55
60
|
var _useRefData = (0, _useRefData2.default)(component),
|
|
56
61
|
data = _useRefData.data,
|
|
57
62
|
status = _useRefData.status;
|
|
@@ -72,7 +77,7 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
72
77
|
options: options,
|
|
73
78
|
value: value || '',
|
|
74
79
|
onChange: onChange
|
|
75
|
-
}), wrap);
|
|
80
|
+
}), wrap, hooks.onGetComponent);
|
|
76
81
|
};
|
|
77
82
|
|
|
78
83
|
FormComponent.propTypes = {
|
|
@@ -4,6 +4,8 @@ var _react = require("@testing-library/react");
|
|
|
4
4
|
|
|
5
5
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
6
|
|
|
7
|
+
var _useHooks = require("../../hooks/useHooks");
|
|
8
|
+
|
|
7
9
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -14,6 +16,9 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
14
16
|
|
|
15
17
|
describe('components', function () {
|
|
16
18
|
describe('FormComponent', function () {
|
|
19
|
+
beforeEach(function () {
|
|
20
|
+
(0, _useHooks.resetHooks)();
|
|
21
|
+
});
|
|
17
22
|
it('should render a text component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
18
23
|
var ID, VALUE, COMPONENT, ON_CHANGE, _render, container, formGroup, label, hint, input;
|
|
19
24
|
|
|
@@ -133,5 +138,67 @@ describe('components', function () {
|
|
|
133
138
|
}
|
|
134
139
|
}, _callee3);
|
|
135
140
|
})));
|
|
141
|
+
it('should render an overridden html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
142
|
+
var ID, COMPONENT, _render4, container, div;
|
|
143
|
+
|
|
144
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
145
|
+
while (1) {
|
|
146
|
+
switch (_context4.prev = _context4.next) {
|
|
147
|
+
case 0:
|
|
148
|
+
(0, _useHooks.addHook)('onGetComponent', function (config, wrap) {
|
|
149
|
+
return /*#__PURE__*/_react2.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap));
|
|
150
|
+
});
|
|
151
|
+
ID = 'component';
|
|
152
|
+
COMPONENT = {
|
|
153
|
+
type: 'html',
|
|
154
|
+
tagName: 'p',
|
|
155
|
+
content: 'HTML content'
|
|
156
|
+
};
|
|
157
|
+
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
158
|
+
"data-testid": ID,
|
|
159
|
+
component: COMPONENT
|
|
160
|
+
})), container = _render4.container;
|
|
161
|
+
div = container.childNodes[0];
|
|
162
|
+
expect(div.tagName).toEqual('DIV');
|
|
163
|
+
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
|
|
164
|
+
|
|
165
|
+
case 7:
|
|
166
|
+
case "end":
|
|
167
|
+
return _context4.stop();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}, _callee4);
|
|
171
|
+
})));
|
|
172
|
+
it('should render the correct html component when the override returns null', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
173
|
+
var ID, COMPONENT, _render5, container, p;
|
|
174
|
+
|
|
175
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
176
|
+
while (1) {
|
|
177
|
+
switch (_context5.prev = _context5.next) {
|
|
178
|
+
case 0:
|
|
179
|
+
(0, _useHooks.addHook)('onGetComponent', function () {
|
|
180
|
+
return null;
|
|
181
|
+
});
|
|
182
|
+
ID = 'component';
|
|
183
|
+
COMPONENT = {
|
|
184
|
+
type: 'html',
|
|
185
|
+
tagName: 'p',
|
|
186
|
+
content: 'HTML content'
|
|
187
|
+
};
|
|
188
|
+
_render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
189
|
+
"data-testid": ID,
|
|
190
|
+
component: COMPONENT
|
|
191
|
+
})), container = _render5.container;
|
|
192
|
+
p = container.childNodes[0];
|
|
193
|
+
expect(p.tagName).toEqual('P');
|
|
194
|
+
expect(p.textContent).toEqual(COMPONENT.content);
|
|
195
|
+
|
|
196
|
+
case 7:
|
|
197
|
+
case "end":
|
|
198
|
+
return _context5.stop();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}, _callee5);
|
|
202
|
+
})));
|
|
136
203
|
});
|
|
137
204
|
});
|