@ukhomeoffice/cop-react-form-renderer 2.0.0 → 2.1.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/FormRenderer/FormRenderer.js +17 -5
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
- package/dist/components/FormRenderer/FormRenderer.test.js +40 -0
- 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/index.js +8 -0
- package/dist/utils/Validate/validateComponent.js +1 -1
- package/dist/utils/Validate/validateRequired.js +11 -0
- package/dist/utils/Validate/validateRequired.test.js +12 -0
- package/package.json +1 -1
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
|
});
|
|
@@ -69,7 +69,10 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
69
69
|
_hooks = _ref.hooks,
|
|
70
70
|
classBlock = _ref.classBlock,
|
|
71
71
|
classModifiers = _ref.classModifiers,
|
|
72
|
-
className = _ref.className
|
|
72
|
+
className = _ref.className,
|
|
73
|
+
hide_title = _ref.hide_title,
|
|
74
|
+
summaryListClassModifiers = _ref.summaryListClassModifiers,
|
|
75
|
+
noChangeAction = _ref.noChangeAction;
|
|
73
76
|
|
|
74
77
|
// Set up the initial states.
|
|
75
78
|
var _useState = (0, _react.useState)({}),
|
|
@@ -218,11 +221,14 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
218
221
|
|
|
219
222
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
220
223
|
className: classes()
|
|
221
|
-
}, title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
|
|
224
|
+
}, title && !hide_title && pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, null, title), formState.cya && /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, _extends({
|
|
222
225
|
pages: pages
|
|
223
226
|
}, cya, formState.cya, {
|
|
224
227
|
onAction: onCYAAction,
|
|
225
|
-
onRowAction: onCYARowAction
|
|
228
|
+
onRowAction: onCYARowAction,
|
|
229
|
+
summaryListClassModifiers: summaryListClassModifiers,
|
|
230
|
+
hide_title: hide_title,
|
|
231
|
+
noChangeAction: noChangeAction
|
|
226
232
|
})), formState.page && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
227
233
|
page: formState.page,
|
|
228
234
|
onAction: onPageAction
|
|
@@ -247,14 +253,20 @@ FormRenderer.propTypes = {
|
|
|
247
253
|
}),
|
|
248
254
|
classBlock: _propTypes.default.string,
|
|
249
255
|
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
250
|
-
className: _propTypes.default.string
|
|
256
|
+
className: _propTypes.default.string,
|
|
257
|
+
hide_title: _propTypes.default.bool,
|
|
258
|
+
summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
259
|
+
noChangeAction: _propTypes.default.bool
|
|
251
260
|
};
|
|
252
261
|
FormRenderer.defaultProps = {
|
|
253
262
|
type: _models.FormTypes.HUB,
|
|
254
263
|
components: [],
|
|
255
264
|
pages: [],
|
|
256
265
|
classBlock: DEFAULT_CLASS,
|
|
257
|
-
classModifiers: []
|
|
266
|
+
classModifiers: [],
|
|
267
|
+
hide_title: false,
|
|
268
|
+
summaryListClassModifiers: [],
|
|
269
|
+
noChangeAction: false
|
|
258
270
|
};
|
|
259
271
|
var _default = FormRenderer;
|
|
260
272
|
exports.default = _default;
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
<!-- Global imports -->
|
|
2
|
+
|
|
2
3
|
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Details,
|
|
7
|
+
Heading,
|
|
8
|
+
Link,
|
|
9
|
+
Panel,
|
|
10
|
+
} from '@ukhomeoffice/cop-react-components';
|
|
4
11
|
import { useState } from 'react';
|
|
5
12
|
import withMock from 'storybook-addon-mock';
|
|
6
13
|
|
|
7
14
|
<!-- Local imports -->
|
|
15
|
+
|
|
8
16
|
import { addHook } from '../../hooks/useHooks';
|
|
9
17
|
import FormRenderer from './FormRenderer';
|
|
10
18
|
|
|
11
19
|
<!-- JSON documents -->
|
|
20
|
+
|
|
12
21
|
import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
|
|
13
22
|
import FIRST_FORM from '../../json/firstForm.json';
|
|
14
23
|
import GRADE from '../../json/grade.json';
|
|
@@ -16,52 +25,60 @@ import TEAMS from '../../json/team.json';
|
|
|
16
25
|
import USER_PROFILE_DATA from '../../json/userProfile.data.json';
|
|
17
26
|
import USER_PROFILE from '../../json/userProfile.json';
|
|
18
27
|
|
|
19
|
-
<Meta
|
|
28
|
+
<Meta
|
|
29
|
+
title='Components/Form renderer'
|
|
30
|
+
id='D-FormRenderer'
|
|
31
|
+
component={FormRenderer}
|
|
32
|
+
decorators={[withMock]}
|
|
33
|
+
/>
|
|
20
34
|
|
|
21
|
-
<Heading size=
|
|
35
|
+
<Heading size='xl' caption='Components'>
|
|
36
|
+
Form renderer
|
|
37
|
+
</Heading>
|
|
22
38
|
|
|
23
39
|
Renders a form with <Link href="https://ukhomeoffice.github.io/cop-react-components/?path=/docs/d-alert--default-story">COP React components</Link>,
|
|
24
40
|
on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describes which elements are required.
|
|
25
41
|
|
|
26
42
|
<Canvas withToolbar>
|
|
27
|
-
<Story
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
<Story
|
|
44
|
+
name='Default'
|
|
45
|
+
parameters={{
|
|
46
|
+
mockData: [
|
|
47
|
+
{
|
|
48
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
49
|
+
method: 'GET',
|
|
50
|
+
status: 200,
|
|
51
|
+
response: CIVIL_SERVANT,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
55
|
+
method: 'GET',
|
|
56
|
+
status: 200,
|
|
57
|
+
response: GRADE,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
61
|
+
method: 'GET',
|
|
62
|
+
status: 200,
|
|
63
|
+
response: TEAMS,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
49
68
|
{() => {
|
|
50
|
-
return
|
|
51
|
-
<FormRenderer {...USER_PROFILE} data={USER_PROFILE_DATA} />
|
|
52
|
-
);
|
|
69
|
+
return <FormRenderer {...USER_PROFILE} data={USER_PROFILE_DATA} />;
|
|
53
70
|
}}
|
|
54
71
|
</Story>
|
|
55
72
|
</Canvas>
|
|
56
73
|
|
|
57
|
-
<Details summary=
|
|
58
|
-
<ArgsTable of={
|
|
74
|
+
<Details summary='Properties' className='no-indent'>
|
|
75
|
+
<ArgsTable of={FormRenderer} />
|
|
59
76
|
</Details>
|
|
60
77
|
|
|
61
78
|
## CYA type
|
|
62
79
|
|
|
63
80
|
<Canvas>
|
|
64
|
-
<Story name=
|
|
81
|
+
<Story name='CYA'>
|
|
65
82
|
{() => {
|
|
66
83
|
const [complete, setComplete] = useState(false);
|
|
67
84
|
const [returnLater, setReturnLater] = useState(false);
|
|
@@ -82,7 +99,12 @@ on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describ
|
|
|
82
99
|
setReturnLater(!!pageId === false);
|
|
83
100
|
});
|
|
84
101
|
addHook('onSubmit', (type, payload, onSuccess, onError) => {
|
|
85
|
-
console.log(
|
|
102
|
+
console.log(
|
|
103
|
+
'onSubmit called of type',
|
|
104
|
+
type,
|
|
105
|
+
'called, with the payload',
|
|
106
|
+
payload
|
|
107
|
+
);
|
|
86
108
|
onSuccess();
|
|
87
109
|
});
|
|
88
110
|
const reset = () => {
|
|
@@ -91,25 +113,69 @@ on the basis of a <Link href="/?path=/docs/f-json-form">JSON</Link> that describ
|
|
|
91
113
|
};
|
|
92
114
|
return (
|
|
93
115
|
<>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
{!complete && !returnLater && (
|
|
117
|
+
<FormRenderer {...FIRST_FORM} data={{}} />
|
|
118
|
+
)}
|
|
119
|
+
{complete && (
|
|
120
|
+
<div>
|
|
121
|
+
<Panel title='Submission successful'>
|
|
122
|
+
Your submission was successful.
|
|
123
|
+
</Panel>
|
|
124
|
+
<Button onClick={() => reset()}>Start again</Button>
|
|
125
|
+
</div>
|
|
126
|
+
)}
|
|
127
|
+
{!complete && returnLater && (
|
|
128
|
+
<div>
|
|
129
|
+
<Panel title='Saved to return later'>
|
|
130
|
+
You clicked on "Save and return later".
|
|
131
|
+
</Panel>
|
|
132
|
+
<Button onClick={() => reset()}>Start again</Button>
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
111
135
|
</>
|
|
112
136
|
);
|
|
113
137
|
}}
|
|
114
138
|
</Story>
|
|
115
139
|
</Canvas>
|
|
140
|
+
|
|
141
|
+
## Read-only style
|
|
142
|
+
|
|
143
|
+
<Canvas>
|
|
144
|
+
<Story
|
|
145
|
+
name='Read-only style'
|
|
146
|
+
parameters={{
|
|
147
|
+
mockData: [
|
|
148
|
+
{
|
|
149
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
150
|
+
method: 'GET',
|
|
151
|
+
status: 200,
|
|
152
|
+
response: CIVIL_SERVANT,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
156
|
+
method: 'GET',
|
|
157
|
+
status: 200,
|
|
158
|
+
response: GRADE,
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
162
|
+
method: 'GET',
|
|
163
|
+
status: 200,
|
|
164
|
+
response: TEAMS,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
{() => {
|
|
170
|
+
return (
|
|
171
|
+
<FormRenderer
|
|
172
|
+
{...USER_PROFILE}
|
|
173
|
+
data={USER_PROFILE_DATA}
|
|
174
|
+
summaryListClassModifiers='no-border'
|
|
175
|
+
hide_title={true}
|
|
176
|
+
noChangeAction={true}
|
|
177
|
+
/>
|
|
178
|
+
);
|
|
179
|
+
}}
|
|
180
|
+
</Story>
|
|
181
|
+
</Canvas>
|
|
@@ -467,5 +467,45 @@ describe('components', function () {
|
|
|
467
467
|
}
|
|
468
468
|
}, _callee12);
|
|
469
469
|
})));
|
|
470
|
+
it('should show no title when hide_title is set to true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
|
|
471
|
+
var form, hub;
|
|
472
|
+
return regeneratorRuntime.wrap(function _callee14$(_context14) {
|
|
473
|
+
while (1) {
|
|
474
|
+
switch (_context14.prev = _context14.next) {
|
|
475
|
+
case 0:
|
|
476
|
+
_context14.next = 2;
|
|
477
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
|
|
478
|
+
return regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
479
|
+
while (1) {
|
|
480
|
+
switch (_context13.prev = _context13.next) {
|
|
481
|
+
case 0:
|
|
482
|
+
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
|
|
483
|
+
data: _userProfileData.default,
|
|
484
|
+
hide_title: true
|
|
485
|
+
})), container);
|
|
486
|
+
|
|
487
|
+
case 1:
|
|
488
|
+
case "end":
|
|
489
|
+
return _context13.stop();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}, _callee13);
|
|
493
|
+
})));
|
|
494
|
+
|
|
495
|
+
case 2:
|
|
496
|
+
form = checkForm(container);
|
|
497
|
+
expect(form.childNodes.length).toEqual(1); //Hub page (= CYA)
|
|
498
|
+
|
|
499
|
+
hub = form.childNodes[0];
|
|
500
|
+
expect(hub.tagName).toEqual('DIV');
|
|
501
|
+
expect(hub.classList).toContain(_CheckYourAnswers.DEFAULT_CLASS);
|
|
502
|
+
|
|
503
|
+
case 7:
|
|
504
|
+
case "end":
|
|
505
|
+
return _context14.stop();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}, _callee14);
|
|
509
|
+
})));
|
|
470
510
|
});
|
|
471
511
|
});
|
|
@@ -15,7 +15,7 @@ var _RowAction = _interopRequireDefault(require("./RowAction"));
|
|
|
15
15
|
|
|
16
16
|
require("./SummaryList.scss");
|
|
17
17
|
|
|
18
|
-
var _excluded = ["rows", "classBlock", "classModifiers", "className"];
|
|
18
|
+
var _excluded = ["rows", "noChangeAction", "classBlock", "classModifiers", "className"];
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
@@ -30,6 +30,7 @@ exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
|
30
30
|
|
|
31
31
|
var SummaryList = function SummaryList(_ref) {
|
|
32
32
|
var rows = _ref.rows,
|
|
33
|
+
noChangeAction = _ref.noChangeAction,
|
|
33
34
|
classBlock = _ref.classBlock,
|
|
34
35
|
classModifiers = _ref.classModifiers,
|
|
35
36
|
className = _ref.className,
|
|
@@ -47,7 +48,7 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
47
48
|
className: classes('key')
|
|
48
49
|
}, row.key), /*#__PURE__*/_react.default.createElement("dd", {
|
|
49
50
|
className: classes('value')
|
|
50
|
-
}, row.value), /*#__PURE__*/_react.default.createElement("dd", {
|
|
51
|
+
}, row.value), !noChangeAction && /*#__PURE__*/_react.default.createElement("dd", {
|
|
51
52
|
className: classes('actions')
|
|
52
53
|
}, row.action && /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
53
54
|
row: row
|
|
@@ -70,10 +71,12 @@ SummaryList.propTypes = {
|
|
|
70
71
|
})).isRequired,
|
|
71
72
|
classBlock: _propTypes.default.string,
|
|
72
73
|
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
73
|
-
className: _propTypes.default.string
|
|
74
|
+
className: _propTypes.default.string,
|
|
75
|
+
noChangeAction: _propTypes.default.bool
|
|
74
76
|
};
|
|
75
77
|
SummaryList.defaultProps = {
|
|
76
|
-
classBlock: DEFAULT_CLASS
|
|
78
|
+
classBlock: DEFAULT_CLASS,
|
|
79
|
+
noChangeAction: false
|
|
77
80
|
};
|
|
78
81
|
var _default = SummaryList;
|
|
79
82
|
exports.default = _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@import
|
|
2
|
-
@import
|
|
1
|
+
@import 'node_modules/govuk-frontend/govuk/_base';
|
|
2
|
+
@import 'node_modules/govuk-frontend/govuk/components/summary-list/_summary-list';
|
|
3
3
|
|
|
4
4
|
.govuk-summary-list__actions {
|
|
5
5
|
.govuk-link {
|
|
@@ -7,3 +7,11 @@
|
|
|
7
7
|
cursor: pointer;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
.caseview__key {
|
|
12
|
+
font-weight: normal;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.caseview__value {
|
|
16
|
+
@include govuk-typography-weight-bold;
|
|
17
|
+
}
|
|
@@ -1,36 +1,90 @@
|
|
|
1
1
|
<!-- Global imports -->
|
|
2
|
+
|
|
2
3
|
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
4
|
import { Details, Heading } from '@ukhomeoffice/cop-react-components';
|
|
4
5
|
|
|
5
6
|
<!-- Local imports -->
|
|
7
|
+
|
|
6
8
|
import Utils from '../../utils';
|
|
7
9
|
import SummaryList from './SummaryList';
|
|
8
10
|
|
|
9
|
-
<Meta
|
|
11
|
+
<Meta
|
|
12
|
+
title='Components/Summary list'
|
|
13
|
+
id='D-SummaryList'
|
|
14
|
+
component={SummaryList}
|
|
15
|
+
/>
|
|
10
16
|
|
|
11
|
-
<Heading size=
|
|
17
|
+
<Heading size='xl' caption='Components'>
|
|
18
|
+
Summary list
|
|
19
|
+
</Heading>
|
|
12
20
|
|
|
13
21
|
Renders a list of key-value pairs, most commonly on the **Check your answers** screen, and optionally
|
|
14
22
|
display action links.
|
|
15
23
|
|
|
16
24
|
<Canvas withToolbar>
|
|
17
|
-
<Story name=
|
|
25
|
+
<Story name='Default'>
|
|
18
26
|
{() => {
|
|
19
27
|
const onAction = (row) => {
|
|
20
28
|
console.log('action clicked', row);
|
|
21
29
|
};
|
|
22
30
|
const ROWS = [
|
|
23
|
-
{
|
|
31
|
+
{
|
|
32
|
+
pageId: 'p1',
|
|
33
|
+
fieldId: 'forename',
|
|
34
|
+
key: 'Forename(s)',
|
|
35
|
+
value: 'John',
|
|
36
|
+
},
|
|
24
37
|
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
25
|
-
{
|
|
38
|
+
{
|
|
39
|
+
pageId: 'p2',
|
|
40
|
+
fieldId: 'dob',
|
|
41
|
+
key: 'Date of birth',
|
|
42
|
+
value: '29/08/1993',
|
|
43
|
+
action: { label: 'Change', onAction },
|
|
44
|
+
},
|
|
26
45
|
];
|
|
27
|
-
return
|
|
28
|
-
<SummaryList rows={ROWS} />
|
|
29
|
-
);
|
|
46
|
+
return <SummaryList rows={ROWS} />;
|
|
30
47
|
}}
|
|
31
48
|
</Story>
|
|
32
49
|
</Canvas>
|
|
33
50
|
|
|
34
|
-
<Details summary=
|
|
35
|
-
<ArgsTable of={
|
|
51
|
+
<Details summary='Properties' className='no-indent'>
|
|
52
|
+
<ArgsTable of={SummaryList} />
|
|
36
53
|
</Details>
|
|
54
|
+
|
|
55
|
+
## Variant
|
|
56
|
+
|
|
57
|
+
### Read-only style
|
|
58
|
+
|
|
59
|
+
<Canvas>
|
|
60
|
+
<Story name='Read-only style'>
|
|
61
|
+
{() => {
|
|
62
|
+
const onAction = (row) => {
|
|
63
|
+
console.log('action clicked', row);
|
|
64
|
+
};
|
|
65
|
+
const ROWS = [
|
|
66
|
+
{
|
|
67
|
+
pageId: 'p1',
|
|
68
|
+
fieldId: 'forename',
|
|
69
|
+
key: 'Forename(s)',
|
|
70
|
+
value: 'John',
|
|
71
|
+
},
|
|
72
|
+
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
73
|
+
{
|
|
74
|
+
pageId: 'p2',
|
|
75
|
+
fieldId: 'dob',
|
|
76
|
+
key: 'Date of birth',
|
|
77
|
+
value: '29/08/1993',
|
|
78
|
+
action: { label: 'Change', onAction },
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
return (
|
|
82
|
+
<SummaryList
|
|
83
|
+
classModifiers='no-border'
|
|
84
|
+
rows={ROWS}
|
|
85
|
+
noChangeAction={true}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}}
|
|
89
|
+
</Story>
|
|
90
|
+
</Canvas>
|
|
@@ -54,6 +54,23 @@ describe('components', function () {
|
|
|
54
54
|
return [key, value, actions];
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
var checkRowNoChangeActions = function checkRowNoChangeActions(summaryList, index) {
|
|
58
|
+
var row = summaryList.childNodes[index];
|
|
59
|
+
expect(row.tagName).toEqual('DIV');
|
|
60
|
+
expect(row.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__row"));
|
|
61
|
+
|
|
62
|
+
var _row$childNodes2 = _slicedToArray(row.childNodes, 2),
|
|
63
|
+
key = _row$childNodes2[0],
|
|
64
|
+
value = _row$childNodes2[1];
|
|
65
|
+
|
|
66
|
+
expect(key.tagName).toEqual('DT');
|
|
67
|
+
expect(key.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__key"));
|
|
68
|
+
expect(value.tagName).toEqual('DD');
|
|
69
|
+
expect(value.classList).toContain("".concat(_SummaryList.DEFAULT_CLASS, "__value"));
|
|
70
|
+
expect(row.childNodes.length).toEqual(2);
|
|
71
|
+
return [key, value];
|
|
72
|
+
};
|
|
73
|
+
|
|
57
74
|
it('should handle an empty rows array', function () {
|
|
58
75
|
var ID = 'test-id';
|
|
59
76
|
var ROWS = [];
|
|
@@ -193,5 +210,42 @@ describe('components', function () {
|
|
|
193
210
|
expect(ON_ACTION_CALLS[index]).toEqual(row);
|
|
194
211
|
});
|
|
195
212
|
});
|
|
213
|
+
it('should handle rows with component values and actions set to hidden', function () {
|
|
214
|
+
var ID = 'test-id';
|
|
215
|
+
var VALUES = ['Alpha component value', 'Bravo component value'];
|
|
216
|
+
var ROWS = [{
|
|
217
|
+
pageId: 'p1',
|
|
218
|
+
fieldId: 'a',
|
|
219
|
+
key: 'Alpha',
|
|
220
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[0])
|
|
221
|
+
}, {
|
|
222
|
+
pageId: 'p2',
|
|
223
|
+
fieldId: 'b',
|
|
224
|
+
key: 'Bravo',
|
|
225
|
+
value: /*#__PURE__*/_react2.default.createElement("div", null, VALUES[1])
|
|
226
|
+
}];
|
|
227
|
+
|
|
228
|
+
var _render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryList.default, {
|
|
229
|
+
"data-testid": ID,
|
|
230
|
+
rows: ROWS,
|
|
231
|
+
noChangeAction: true
|
|
232
|
+
})),
|
|
233
|
+
container = _render5.container;
|
|
234
|
+
|
|
235
|
+
var summaryList = checkSummaryList(container, ID);
|
|
236
|
+
expect(summaryList.childNodes.length).toEqual(ROWS.length);
|
|
237
|
+
ROWS.forEach(function (row, index) {
|
|
238
|
+
var _checkRowNoChangeActi = checkRowNoChangeActions(summaryList, index),
|
|
239
|
+
_checkRowNoChangeActi2 = _slicedToArray(_checkRowNoChangeActi, 2),
|
|
240
|
+
key = _checkRowNoChangeActi2[0],
|
|
241
|
+
value = _checkRowNoChangeActi2[1];
|
|
242
|
+
|
|
243
|
+
expect(key.textContent).toEqual(row.key);
|
|
244
|
+
expect(value.childNodes.length).toEqual(1);
|
|
245
|
+
var valueDiv = value.childNodes[0];
|
|
246
|
+
expect(valueDiv.tagName).toEqual('DIV');
|
|
247
|
+
expect(valueDiv.textContent).toEqual(VALUES[index]);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
196
250
|
});
|
|
197
251
|
});
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "HubFormats", {
|
|
|
21
21
|
return _models.HubFormats;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "SummaryList", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _SummaryList.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "Utils", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function get() {
|
|
@@ -31,6 +37,8 @@ exports.intercepts = exports.default = void 0;
|
|
|
31
37
|
|
|
32
38
|
var _FormRenderer = _interopRequireDefault(require("./components/FormRenderer"));
|
|
33
39
|
|
|
40
|
+
var _SummaryList = _interopRequireDefault(require("./components/SummaryList"));
|
|
41
|
+
|
|
34
42
|
var _useHooks = require("./hooks/useHooks");
|
|
35
43
|
|
|
36
44
|
var _models = require("./models");
|
|
@@ -31,7 +31,7 @@ var validateComponent = function validateComponent(component, formData) {
|
|
|
31
31
|
var value = data[component.fieldId];
|
|
32
32
|
|
|
33
33
|
if (component.required) {
|
|
34
|
-
error = (0, _validateRequired.default)(value, component.label);
|
|
34
|
+
error = (0, _validateRequired.default)(value, component.label, component.custom_errors);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (!error && component.type === _models.ComponentTypes.EMAIL) {
|
|
@@ -14,6 +14,7 @@ exports.default = void 0;
|
|
|
14
14
|
*/
|
|
15
15
|
var validateRequired = function validateRequired(value) {
|
|
16
16
|
var label = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
17
|
+
var customErrors = arguments.length > 2 ? arguments[2] : undefined;
|
|
17
18
|
var hasValue = false;
|
|
18
19
|
|
|
19
20
|
if (!!value || value === false || value === 0) {
|
|
@@ -27,6 +28,16 @@ var validateRequired = function validateRequired(value) {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
if (!hasValue) {
|
|
31
|
+
if (Array.isArray(customErrors)) {
|
|
32
|
+
var result = customErrors.filter(function (error) {
|
|
33
|
+
return error.type === 'required';
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (result && result.length > 0 && result[0].message) {
|
|
37
|
+
return result[0].message;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
var name = label ? label : 'Field';
|
|
31
42
|
return "".concat(name, " is required");
|
|
32
43
|
}
|
|
@@ -45,6 +45,18 @@ describe('utils', function () {
|
|
|
45
45
|
it('should use a default label when none is specified', function () {
|
|
46
46
|
expect((0, _validateRequired.default)(undefined, undefined)).toEqual('Field is required');
|
|
47
47
|
});
|
|
48
|
+
it('should use a custom error when one is provided', function () {
|
|
49
|
+
expect((0, _validateRequired.default)(undefined, undefined, [{
|
|
50
|
+
type: 'required',
|
|
51
|
+
message: 'custom error message'
|
|
52
|
+
}])).toEqual('custom error message');
|
|
53
|
+
});
|
|
54
|
+
it('should ignore a custom error when not of type required', function () {
|
|
55
|
+
expect((0, _validateRequired.default)(undefined, undefined, [{
|
|
56
|
+
type: 'genericError',
|
|
57
|
+
message: 'generic error message'
|
|
58
|
+
}])).toEqual('Field is required');
|
|
59
|
+
});
|
|
48
60
|
});
|
|
49
61
|
});
|
|
50
62
|
});
|