@ukhomeoffice/cop-react-form-renderer 2.6.2 → 2.7.1

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.
@@ -0,0 +1,158 @@
1
+ {
2
+ "id": "userProfile",
3
+ "version": "1",
4
+ "name": "userProfile",
5
+ "title": "Your profile",
6
+ "type": "cya",
7
+ "components": [
8
+ {
9
+ "id": "firstName",
10
+ "fieldId": "firstName",
11
+ "label": "First name",
12
+ "type": "text",
13
+ "readonly": false,
14
+ "source": {
15
+ "field": "currentUser.givenName"
16
+ }
17
+ },
18
+ {
19
+ "id": "surname",
20
+ "fieldId": "surname",
21
+ "label": "Last name",
22
+ "type": "text",
23
+ "readonly": false,
24
+ "source": {
25
+ "field": "currentUser.familyName"
26
+ }
27
+ },
28
+ {
29
+ "id": "dateGroup",
30
+ "fieldId": "dateGroup",
31
+ "label": "Date",
32
+ "type": "date",
33
+ "required": true,
34
+ "readonly": false,
35
+ "source": {
36
+ "field": "dateGroupField"
37
+ }
38
+ },
39
+ {
40
+ "id": "timeGroup",
41
+ "fieldId": "timeGroup",
42
+ "label": "Time",
43
+ "type": "time",
44
+ "required": true,
45
+ "readonly": false,
46
+ "source": {
47
+ "field": "timeGroupField"
48
+ }
49
+ },
50
+ {
51
+ "id": "portGroup",
52
+ "fieldId": "portGroup",
53
+ "label": "Port",
54
+ "type": "text",
55
+ "required": true,
56
+ "readonly": false,
57
+ "source": {
58
+ "field": "portGroupField"
59
+ }
60
+ },
61
+ {
62
+ "id": "whereGroup",
63
+ "fieldId": "whereGroup",
64
+ "label": "Where did you see the incident take place",
65
+ "type": "text",
66
+ "required": true,
67
+ "readonly": false,
68
+ "source": {
69
+ "field": "whereGroupField"
70
+ }
71
+ },
72
+ {
73
+ "id": "extraDetails",
74
+ "fieldId": "extraDetails",
75
+ "label": "Extra details",
76
+ "type": "textarea",
77
+ "readonly": false
78
+ }
79
+ ],
80
+ "pages": [
81
+ {
82
+ "id": "names",
83
+ "name": "names",
84
+ "title": "Name",
85
+ "components": [
86
+ {
87
+ "use": "firstName"
88
+ },
89
+ {
90
+ "use": "surname"
91
+ }
92
+ ],
93
+ "cya_link": {
94
+ "page": "names",
95
+ "aria_suffix": "names"
96
+ },
97
+ "actions": [
98
+ "submit"
99
+ ]
100
+ },
101
+ {
102
+ "id": "dateLocDet",
103
+ "name": "dateLocDetName",
104
+ "title": "Date and location details",
105
+ "components": [
106
+ {
107
+ "use": "dateGroup"
108
+ },
109
+ {
110
+ "use": "timeGroup"
111
+ },
112
+ {
113
+ "use": "portGroup"
114
+ },
115
+ {
116
+ "use": "whereGroup"
117
+ }
118
+ ],
119
+ "cya_link": {
120
+ "page": "dateLocDet",
121
+ "aria_suffix": "Date and location details"
122
+ },
123
+ "actions": [
124
+ "submit"
125
+ ]
126
+ },
127
+ {
128
+ "id": "additional-info",
129
+ "name": "additional-info",
130
+ "title": "Additional Information",
131
+ "components": [
132
+ {
133
+ "use": "extraDetails"
134
+ }
135
+ ],
136
+ "cya_link": {
137
+ "page": "additional-info",
138
+ "aria_suffix": "Additional Information"
139
+ },
140
+ "actions": [
141
+ "submit"
142
+ ]
143
+ }
144
+ ],
145
+ "cya": {
146
+ "hide_page_titles": true,
147
+ "hide_actions": true,
148
+ "groups": [
149
+ {
150
+ "pageId": "dateLocDet"
151
+ },
152
+ {
153
+ "pageId": "names",
154
+ "title": "Names"
155
+ }
156
+ ]
157
+ }
158
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "currentUser": {
3
+ "givenName": "John",
4
+ "familyName": "Smith"
5
+ },
6
+ "businessKey": "123456789",
7
+ "dateGroupField": "01-01-2022",
8
+ "timeGroupField": "14:57",
9
+ "portGroupField": "Glasgow",
10
+ "whereGroupField": "terminal",
11
+ "firstName": "sample",
12
+ "surname": "test",
13
+ "age": "12",
14
+ "extraDetails": "extra notes here"
15
+ }
@@ -7,20 +7,21 @@ exports.default = void 0;
7
7
 
8
8
  var _validateComponent = _interopRequireDefault(require("./validateComponent"));
9
9
 
10
+ var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
11
+
10
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
13
 
12
14
  // Local imports
13
15
 
14
16
  /**
15
17
  * Validate all of the components on a page.
16
- * @param {Array} components The components to validate.
17
- * @param {object} formData The data to use that holds this components' values.
18
+ * @param {object} page The page to validate
18
19
  * @returns An array containing all of the errors.
19
20
  */
20
- var validatePage = function validatePage(components, formData) {
21
- if (Array.isArray(components)) {
22
- return components.reduce(function (errors, component) {
23
- return errors.concat((0, _validateComponent.default)(component, formData));
21
+ var validatePage = function validatePage(page) {
22
+ if ((0, _showFormPage.default)(page, page.formData) && Array.isArray(page.components)) {
23
+ return page.components.reduce(function (errors, component) {
24
+ return errors.concat((0, _validateComponent.default)(component, page.formData));
24
25
  }, []).filter(function (e) {
25
26
  return !!e;
26
27
  }).flat();
@@ -21,20 +21,36 @@ describe('utils', function () {
21
21
  };
22
22
 
23
23
  it('should return no error when the components array is null', function () {
24
- expect((0, _validatePage.default)(null, {}).length).toEqual(0);
24
+ var PAGE = {
25
+ components: null,
26
+ formData: null
27
+ };
28
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
25
29
  });
26
30
  it('should return no error when the components array is empty', function () {
27
- expect((0, _validatePage.default)([], {}).length).toEqual(0);
31
+ var PAGE = {
32
+ components: [],
33
+ formData: null
34
+ };
35
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
28
36
  });
29
37
  describe('when there is no form data', function () {
30
38
  it('should return no errors when no components are required', function () {
31
39
  var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', false), setup('b', _models.ComponentTypes.TEXT, 'Bravo', false)];
32
- expect((0, _validatePage.default)(COMPONENTS, null).length).toEqual(0);
40
+ var PAGE = {
41
+ components: COMPONENTS,
42
+ formData: null
43
+ };
44
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
33
45
  });
34
46
  it('should return an error for each required component', function () {
35
47
  var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false), // The only unrequired one
36
48
  setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
37
- var RESULT = (0, _validatePage.default)(COMPONENTS, null);
49
+ var PAGE = {
50
+ components: COMPONENTS,
51
+ formData: null
52
+ };
53
+ var RESULT = (0, _validatePage.default)(PAGE);
38
54
  expect(RESULT.length).toEqual(4);
39
55
  expect(RESULT[0]).toEqual({
40
56
  id: 'a',
@@ -61,19 +77,35 @@ describe('utils', function () {
61
77
  };
62
78
  it('should return no errors when none of the components are required or email types', function () {
63
79
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
64
- expect((0, _validatePage.default)(COMPONENTS, DATA).length).toEqual(0);
80
+ var PAGE = {
81
+ components: COMPONENTS,
82
+ formData: DATA
83
+ };
84
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
65
85
  });
66
86
  it('should return no errors when all of the components are required but not email types', function () {
67
87
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
68
- expect((0, _validatePage.default)(COMPONENTS, DATA).length).toEqual(0);
88
+ var PAGE = {
89
+ components: COMPONENTS,
90
+ formData: DATA
91
+ };
92
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
69
93
  });
70
94
  it('should return no errors when none of the components are required but are all email types', function () {
71
95
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
72
- expect((0, _validatePage.default)(COMPONENTS, DATA).length).toEqual(0);
96
+ var PAGE = {
97
+ components: COMPONENTS,
98
+ formData: DATA
99
+ };
100
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
73
101
  });
74
102
  it('should return no errors when all of the components are required and email types', function () {
75
103
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
76
- expect((0, _validatePage.default)(COMPONENTS, DATA).length).toEqual(0);
104
+ var PAGE = {
105
+ components: COMPONENTS,
106
+ formData: DATA
107
+ };
108
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
77
109
  });
78
110
  });
79
111
  describe('when the form data has one field missing and includes an invalid email', function () {
@@ -83,11 +115,19 @@ describe('utils', function () {
83
115
  };
84
116
  it('should return no errors when none of the components are required or email types', function () {
85
117
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
86
- expect((0, _validatePage.default)(COMPONENTS, DATA).length).toEqual(0);
118
+ var PAGE = {
119
+ components: COMPONENTS,
120
+ formData: null
121
+ };
122
+ expect((0, _validatePage.default)(PAGE).length).toEqual(0);
87
123
  });
88
124
  it('should return an error for the missing field when all are required but not email types', function () {
89
125
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
90
- var RESULT = (0, _validatePage.default)(COMPONENTS, DATA);
126
+ var PAGE = {
127
+ components: COMPONENTS,
128
+ formData: DATA
129
+ };
130
+ var RESULT = (0, _validatePage.default)(PAGE);
91
131
  expect(RESULT.length).toEqual(1);
92
132
  expect(RESULT[0]).toEqual({
93
133
  id: 'charlie',
@@ -96,7 +136,11 @@ describe('utils', function () {
96
136
  });
97
137
  it('should return an error for the invalid email field when none are required but all email types', function () {
98
138
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
99
- var RESULT = (0, _validatePage.default)(COMPONENTS, DATA);
139
+ var PAGE = {
140
+ components: COMPONENTS,
141
+ formData: DATA
142
+ };
143
+ var RESULT = (0, _validatePage.default)(PAGE);
100
144
  expect(RESULT.length).toEqual(1);
101
145
  expect(RESULT[0]).toEqual({
102
146
  id: 'bravo',
@@ -105,7 +149,11 @@ describe('utils', function () {
105
149
  });
106
150
  it('should return an error for both invalid fields when all are required and email types', function () {
107
151
  var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
108
- var RESULT = (0, _validatePage.default)(COMPONENTS, DATA);
152
+ var PAGE = {
153
+ components: COMPONENTS,
154
+ formData: DATA
155
+ };
156
+ var RESULT = (0, _validatePage.default)(PAGE);
109
157
  expect(RESULT.length).toEqual(2);
110
158
  expect(RESULT[0]).toEqual({
111
159
  id: 'bravo',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "2.6.2",
3
+ "version": "2.7.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",