@ukhomeoffice/cop-react-form-renderer 1.0.0 → 2.2.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
  6. package/dist/components/FormComponent/FormComponent.js +6 -1
  7. package/dist/components/FormComponent/FormComponent.test.js +67 -0
  8. package/dist/components/FormPage/FormPage.js +8 -2
  9. package/dist/components/FormPage/FormPage.test.js +2 -2
  10. package/dist/components/FormRenderer/FormRenderer.js +43 -15
  11. package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
  12. package/dist/components/FormRenderer/FormRenderer.test.js +40 -0
  13. package/dist/components/FormRenderer/handlers/getPageId.js +1 -10
  14. package/dist/components/FormRenderer/handlers/getPageId.test.js +5 -31
  15. package/dist/components/FormRenderer/handlers/handlers.test.js +2 -2
  16. package/dist/components/FormRenderer/helpers/getNextPageId.js +33 -26
  17. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +89 -7
  18. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +27 -0
  19. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +209 -0
  20. package/dist/components/FormRenderer/helpers/index.js +4 -1
  21. package/dist/components/PageActions/PageActions.stories.mdx +1 -1
  22. package/dist/components/PageActions/PageActions.test.js +2 -2
  23. package/dist/components/SummaryList/RowAction.js +1 -1
  24. package/dist/components/SummaryList/RowAction.test.js +6 -6
  25. package/dist/components/SummaryList/SummaryList.js +8 -5
  26. package/dist/components/SummaryList/SummaryList.scss +10 -2
  27. package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
  28. package/dist/components/SummaryList/SummaryList.test.js +54 -0
  29. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
  30. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
  31. package/dist/hooks/useHooks.js +5 -1
  32. package/dist/index.js +8 -0
  33. package/dist/json/areYouACivilServant.json +7 -0
  34. package/dist/json/firstForm.json +94 -0
  35. package/dist/json/grade.json +108 -0
  36. package/dist/json/saveAndContinue.json +98 -0
  37. package/dist/json/team.json +17351 -0
  38. package/dist/json/userProfile.data.json +14 -0
  39. package/dist/json/userProfile.json +276 -0
  40. package/dist/models/ComponentTypes.js +4 -0
  41. package/dist/utils/CheckYourAnswers/getCYAAction.js +24 -3
  42. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +62 -15
  43. package/dist/utils/CheckYourAnswers/getCYARow.js +8 -2
  44. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -5
  45. package/dist/utils/Component/getComponent.js +42 -0
  46. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +75 -0
  47. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +129 -0
  48. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +129 -0
  49. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +80 -0
  50. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +33 -0
  51. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +45 -0
  52. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +31 -0
  53. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +80 -0
  54. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +125 -0
  55. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +80 -0
  56. package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +76 -0
  57. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +14 -0
  58. package/dist/utils/Component/isEditable.js +1 -1
  59. package/dist/utils/Data/refDataToOptions.js +4 -0
  60. package/dist/utils/Data/refDataToOptions.test.js +30 -0
  61. package/dist/utils/FormPage/getEditableComponents.js +28 -0
  62. package/dist/utils/FormPage/getEditableComponents.test.js +75 -0
  63. package/dist/utils/FormPage/getFormPage.js +5 -1
  64. package/dist/utils/FormPage/getPageActions.js +66 -0
  65. package/dist/utils/FormPage/getPageActions.test.js +89 -0
  66. package/dist/utils/FormPage/index.js +7 -1
  67. package/dist/utils/FormPage/showFormPage.js +81 -0
  68. package/dist/utils/FormPage/showFormPage.test.js +131 -0
  69. package/dist/utils/Validate/validateComponent.js +5 -3
  70. package/dist/utils/Validate/validateRequired.js +11 -0
  71. package/dist/utils/Validate/validateRequired.test.js +12 -0
  72. package/package.json +9 -5
  73. package/dist/utils/Component/getComponent.test.js +0 -361
@@ -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
  });
@@ -13,9 +13,9 @@ var getRowActionAttributes = function getRowActionAttributes(row) {
13
13
  return row.action.onAction(row);
14
14
  }
15
15
  };
16
- } else {
16
+ } else if (row.action.page) {
17
17
  return {
18
- href: row.action.href
18
+ href: "/".concat(row.action.page)
19
19
  };
20
20
  }
21
21
  }
@@ -20,15 +20,15 @@ describe('components', function () {
20
20
  };
21
21
  expect((0, _getRowActionAttributes.default)(ROW)).toEqual({});
22
22
  });
23
- it('should handle a row with an href', function () {
24
- var HREF = 'http://alpha.homeoffice.gov.uk';
23
+ it('should handle a row with a page', function () {
24
+ var PAGE = 'alpha';
25
25
  var ROW = {
26
26
  action: {
27
- href: HREF
27
+ page: PAGE
28
28
  }
29
29
  };
30
30
  expect((0, _getRowActionAttributes.default)(ROW)).toEqual({
31
- href: HREF
31
+ href: "/".concat(PAGE)
32
32
  });
33
33
  });
34
34
  it('should handle a row with an onAction function', function () {
@@ -4,11 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resetHooks = exports.removeHook = exports.default = exports.addHook = exports.ALLOWED_HOOKS = void 0;
7
- var ALLOWED_HOOKS = ['onRequest', 'onFormComplete', 'onFormLoad', 'onPageChange', 'onSubmit'];
7
+ var ALLOWED_HOOKS = ['onFormComplete', 'onFormLoad', 'onGetComponent', 'onPageChange', 'onRequest', 'onSubmit'];
8
8
  exports.ALLOWED_HOOKS = ALLOWED_HOOKS;
9
9
  var DEFAULT_HOOKS = {
10
10
  onFormComplete: function onFormComplete() {},
11
11
  onFormLoad: function onFormLoad() {},
12
+ onGetComponent: function onGetComponent(config, wrap) {
13
+ return null;
14
+ },
12
15
  onPageChange: function onPageChange(pageId) {
13
16
  return pageId;
14
17
  },
@@ -22,6 +25,7 @@ var DEFAULT_HOOKS = {
22
25
  var hooks = {
23
26
  onFormComplete: DEFAULT_HOOKS.onFormComplete,
24
27
  onFormLoad: DEFAULT_HOOKS.onFormLoad,
28
+ onGetComponent: DEFAULT_HOOKS.onGetComponent,
25
29
  onPageChange: DEFAULT_HOOKS.onPageChange,
26
30
  onRequest: DEFAULT_HOOKS.onRequest,
27
31
  onSubmit: DEFAULT_HOOKS.onSubmit
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");
@@ -0,0 +1,7 @@
1
+ {
2
+ "data": [
3
+ { "id": "yes", "name": "Yes" },
4
+ { "id": "no-contractor", "name": "No, I'm a contractor" },
5
+ { "id": "no-agency", "name": "No, I'm agency staff" }
6
+ ]
7
+ }
@@ -0,0 +1,94 @@
1
+ {
2
+ "id": "firstForm",
3
+ "version": "1",
4
+ "name": "firstForm",
5
+ "title": "First form",
6
+ "type": "cya",
7
+ "components": [
8
+ {
9
+ "id": "firstName",
10
+ "fieldId": "firstName",
11
+ "label": "First name",
12
+ "type": "text",
13
+ "required": true
14
+ },
15
+ {
16
+ "id": "surname",
17
+ "fieldId": "surname",
18
+ "label": "Last name",
19
+ "type": "text",
20
+ "required": true
21
+ },
22
+ {
23
+ "id": "age",
24
+ "fieldId": "age",
25
+ "label": "Your age",
26
+ "type": "text",
27
+ "required": true
28
+ }
29
+ ],
30
+ "pages": [
31
+ {
32
+ "id": "before",
33
+ "name": "before",
34
+ "title": "Before you start",
35
+ "components": [
36
+ "This is a sample form to prove out the mechanism for save and continue.",
37
+ "When you click on the Start button, a new business key should be generated for this form.",
38
+ {
39
+ "type": "inset-text",
40
+ "content": "Generating a business key is non-reversible and cancelling the form creation will leave a gap."
41
+ },
42
+ "If you are happy to proceed, click start now."
43
+ ],
44
+ "actions": [
45
+ { "type": "navigate", "page": "firstName", "start": true, "label": "Start now" }
46
+ ],
47
+ "show_on_cya": false
48
+ },
49
+ {
50
+ "id": "firstName",
51
+ "name": "firstName",
52
+ "title": "Enter first name",
53
+ "components": [
54
+ { "use": "firstName", "label": "" }
55
+ ],
56
+ "actions": [ "saveAndContinue", "saveAndReturn" ],
57
+ "cya_link": {
58
+ "page": "firstName",
59
+ "aria_suffix": "your first name"
60
+ }
61
+ },
62
+ {
63
+ "id": "surname",
64
+ "name": "surname",
65
+ "title": "Enter surname",
66
+ "components": [
67
+ { "use": "surname", "label": "" }
68
+ ],
69
+ "actions": [ "saveAndContinue", "saveAndReturn" ],
70
+ "cya_link": {
71
+ "page": "surname",
72
+ "aria_suffix": "your surname"
73
+ }
74
+ },
75
+ {
76
+ "id": "age",
77
+ "name": "age",
78
+ "title": "Enter age",
79
+ "components": [
80
+ { "use": "age", "label": "" }
81
+ ],
82
+ "actions": [ "saveAndContinue", "saveAndReturn" ],
83
+ "cya_link": {
84
+ "page": "age",
85
+ "aria_suffix": "your first name"
86
+ }
87
+ }
88
+ ],
89
+ "cya": {
90
+ "actions": [
91
+ { "type": "submit", "label": "Submit", "validate": true }
92
+ ]
93
+ }
94
+ }
@@ -0,0 +1,108 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "373979c1-2360-46be-b712-0409ac068059",
5
+ "name": "SCS4",
6
+ "parentgradetypeid": null,
7
+ "validfrom": "2019-01-01T00:01:00.000Z",
8
+ "validto": null,
9
+ "updatedby": null
10
+ },
11
+ {
12
+ "id": "36c80dfe-0aae-455b-9445-2e1c09dcafdc",
13
+ "name": "SCS3",
14
+ "parentgradetypeid": "373979c1-2360-46be-b712-0409ac068059",
15
+ "validfrom": "2019-01-01T00:01:00.000Z",
16
+ "validto": null,
17
+ "updatedby": null
18
+ },
19
+ {
20
+ "id": "1b041cda-b151-4769-b76a-d42d67b0b960",
21
+ "name": "Senior Director / SCS2",
22
+ "parentgradetypeid": "36c80dfe-0aae-455b-9445-2e1c09dcafdc",
23
+ "validfrom": "2019-01-01T00:01:00.000Z",
24
+ "validto": null,
25
+ "updatedby": null
26
+ },
27
+ {
28
+ "id": "172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
29
+ "name": "Director / SCS1",
30
+ "parentgradetypeid": "1b041cda-b151-4769-b76a-d42d67b0b960",
31
+ "validfrom": "2019-01-01T00:01:00.000Z",
32
+ "validto": null,
33
+ "updatedby": null
34
+ },
35
+ {
36
+ "id": "39e18b45-0358-4a45-83ec-5a70b74641e8",
37
+ "name": "Deputy Director / Grade 6",
38
+ "parentgradetypeid": "172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
39
+ "validfrom": "2019-01-01T00:01:00.000Z",
40
+ "validto": null,
41
+ "updatedby": null
42
+ },
43
+ {
44
+ "id": "44855085-a36b-42e5-b805-f4ebe209ecf2",
45
+ "name": "Assistant Director / Grade 7",
46
+ "parentgradetypeid": "39e18b45-0358-4a45-83ec-5a70b74641e8",
47
+ "validfrom": "2019-01-01T00:01:00.000Z",
48
+ "validto": null,
49
+ "updatedby": null
50
+ },
51
+ {
52
+ "id": "4fad1115-7d12-4b6f-8d8a-97dbe469a346",
53
+ "name": "Senior Officer / Senior Executive Officer",
54
+ "parentgradetypeid": "44855085-a36b-42e5-b805-f4ebe209ecf2",
55
+ "validfrom": "2019-01-01T00:01:00.000Z",
56
+ "validto": null,
57
+ "updatedby": null
58
+ },
59
+ {
60
+ "id": "b512288d-95e3-4f60-ad4c-4cdfab68d841",
61
+ "name": "Higher Officer / Higher Executive Officer",
62
+ "parentgradetypeid": "4fad1115-7d12-4b6f-8d8a-97dbe469a346",
63
+ "validfrom": "2019-01-01T00:01:00.000Z",
64
+ "validto": null,
65
+ "updatedby": null
66
+ },
67
+ {
68
+ "id": "1c140011-46ad-4a5d-af25-e80a6fcdcdba",
69
+ "name": "Officer / Executive Officer",
70
+ "parentgradetypeid": "b512288d-95e3-4f60-ad4c-4cdfab68d841",
71
+ "validfrom": "2019-01-01T00:01:00.000Z",
72
+ "validto": null,
73
+ "updatedby": null
74
+ },
75
+ {
76
+ "id": "02de92d8-aad1-4663-a37f-a87012f60f1b",
77
+ "name": "Assistant Officer / Administrative Officer",
78
+ "parentgradetypeid": "1c140011-46ad-4a5d-af25-e80a6fcdcdba",
79
+ "validfrom": "2019-01-01T00:01:00.000Z",
80
+ "validto": null,
81
+ "updatedby": null
82
+ },
83
+ {
84
+ "id": "9910a29d-7fbb-451d-8729-f39f4373bbcc",
85
+ "name": "Assistant Office / Messenger",
86
+ "parentgradetypeid": "02de92d8-aad1-4663-a37f-a87012f60f1b",
87
+ "validfrom": "2019-01-01T00:01:00.000Z",
88
+ "validto": null,
89
+ "updatedby": null
90
+ },
91
+ {
92
+ "id": "073b92f8-7208-4026-a090-906c276079f1",
93
+ "name": "Contractor",
94
+ "parentgradetypeid": null,
95
+ "validfrom": "2019-01-01T00:01:00.000Z",
96
+ "validto": null,
97
+ "updatedby": null
98
+ },
99
+ {
100
+ "id": "c27cf914-0b97-4c4e-bb2d-2ae4b886baa5",
101
+ "name": "Agency Staff",
102
+ "parentgradetypeid": null,
103
+ "validfrom": "2019-01-01T00:01:00.000Z",
104
+ "validto": null,
105
+ "updatedby": null
106
+ }
107
+ ]
108
+ }
@@ -0,0 +1,98 @@
1
+ {
2
+ "id": "saveAndContinue",
3
+ "version": "1",
4
+ "name": "saveAndContinue",
5
+ "title": "Save and continue example",
6
+ "type": "hub-and-spoke",
7
+ "components": [
8
+ {
9
+ "id": "firstName",
10
+ "fieldId": "firstName",
11
+ "label": "First name",
12
+ "type": "text",
13
+ "required": true
14
+ },
15
+ {
16
+ "id": "surname",
17
+ "fieldId": "surname",
18
+ "label": "Last name",
19
+ "type": "text",
20
+ "required": true
21
+ },
22
+ {
23
+ "id": "email",
24
+ "fieldId": "email",
25
+ "label": "Your email address",
26
+ "type": "email",
27
+ "required": true
28
+ },
29
+ {
30
+ "id": "location",
31
+ "fieldId": "location",
32
+ "label": "Incident location",
33
+ "type": "text",
34
+ "required": true
35
+ },
36
+ {
37
+ "id": "when",
38
+ "fieldId": "when",
39
+ "label": "Incident date and start time",
40
+ "type": "text",
41
+ "required": true
42
+ },
43
+ {
44
+ "id": "seizedItems",
45
+ "fieldId": "seizedItems",
46
+ "type": "collection",
47
+ "required": true,
48
+ "components": [
49
+ { "use": "type" },
50
+ { "use": "description" },
51
+ {
52
+ "id": "status",
53
+ "fieldId": "status",
54
+ "label": "What is the seized status of this item?",
55
+ "type": "radios",
56
+ "required": true
57
+ }
58
+ ],
59
+ "_description": "Required means at least 1 item"
60
+ }
61
+ ],
62
+ "pages": [
63
+ {
64
+ "id": "details",
65
+ "name": "details",
66
+ "title": "Your details",
67
+ "components": [
68
+ { "use": "firstName" },
69
+ { "use": "surname" },
70
+ { "use": "email" }
71
+ ],
72
+ "actions": [
73
+ { "type": "saveDraft", "validate": true, "label": "Save and continue" },
74
+ { "type": "saveAndReturn", "validate": true, "label": "Save and return later", "classModifiers": "secondary" }
75
+ ],
76
+ "cya_link": {
77
+ "page": "details",
78
+ "aria_suffix": "your details"
79
+ }
80
+ },
81
+ {
82
+ "id": "where-and-when",
83
+ "name": "where-and-when",
84
+ "title": "Where and when",
85
+ "components": [
86
+ { "use": "location" },
87
+ { "use": "when" }
88
+ ],
89
+ "actions": ["submit"],
90
+ "cya_link": {
91
+ "page": "where-and-when",
92
+ "aria_suffix": "where and when"
93
+ }
94
+ }
95
+ ],
96
+ "hub": { "format": "CYA" },
97
+ "cya": {}
98
+ }