@ukhomeoffice/cop-react-form-renderer 5.77.2 → 5.77.4
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.
|
@@ -32,6 +32,7 @@ var createMasterPage = function createMasterPage(page) {
|
|
|
32
32
|
return {
|
|
33
33
|
id: page.id,
|
|
34
34
|
name: page.name,
|
|
35
|
+
orderInForm: page.orderInForm,
|
|
35
36
|
collection: _objectSpread({
|
|
36
37
|
masterPage: true
|
|
37
38
|
}, page.collection),
|
|
@@ -68,6 +69,12 @@ var nestUnderParent = function nestUnderParent(childPage, masterPages) {
|
|
|
68
69
|
return false;
|
|
69
70
|
}
|
|
70
71
|
parentPage.childPages.push(childPage);
|
|
72
|
+
|
|
73
|
+
// Sort the pages to make sure they're in the same order
|
|
74
|
+
// they were in on the form.
|
|
75
|
+
parentPage.childPages.sort(function (a, b) {
|
|
76
|
+
return a.orderInForm - b.orderInForm;
|
|
77
|
+
});
|
|
71
78
|
return true;
|
|
72
79
|
};
|
|
73
80
|
|
|
@@ -84,8 +91,9 @@ var nestUnderParent = function nestUnderParent(childPage, masterPages) {
|
|
|
84
91
|
*/
|
|
85
92
|
var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
86
93
|
var masterPages = {};
|
|
87
|
-
var pagesWithMasters = pages.map(function (page) {
|
|
94
|
+
var pagesWithMasters = pages.map(function (page, index) {
|
|
88
95
|
var _page$collection;
|
|
96
|
+
page.orderInForm = index;
|
|
89
97
|
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
90
98
|
if (!masterPages[page.collection.name]) {
|
|
91
99
|
// If no master page exists for this collection.name, then
|
|
@@ -104,6 +112,7 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
|
104
112
|
}).filter(function (page) {
|
|
105
113
|
return !!page;
|
|
106
114
|
});
|
|
115
|
+
|
|
107
116
|
// We nest any child master pages under their parents here to
|
|
108
117
|
// ensure that all parent master pages have been created by the
|
|
109
118
|
// above code first.
|
|
@@ -131,7 +131,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
131
131
|
masterPage: true
|
|
132
132
|
},
|
|
133
133
|
formData: {},
|
|
134
|
-
childPages: [
|
|
134
|
+
childPages: [{
|
|
135
135
|
id: 'page1',
|
|
136
136
|
collection: {
|
|
137
137
|
name: 'parent.child',
|
|
@@ -139,7 +139,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
139
139
|
},
|
|
140
140
|
formData: {},
|
|
141
141
|
childPages: [PAGES[0], PAGES[1]]
|
|
142
|
-
}]
|
|
142
|
+
}, PAGES[2], PAGES[3]]
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
it('should leave non-collection pages unaffected', function () {
|
|
@@ -160,7 +160,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
160
160
|
}];
|
|
161
161
|
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
162
162
|
expect(RESULT.length).toEqual(2);
|
|
163
|
-
expect(RESULT[0]).
|
|
163
|
+
expect(RESULT[0]).toMatchObject({
|
|
164
164
|
id: 'page1',
|
|
165
165
|
collection: {
|
|
166
166
|
name: 'collection',
|
|
@@ -169,7 +169,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
169
169
|
formData: {},
|
|
170
170
|
childPages: [PAGES[0], PAGES[1]]
|
|
171
171
|
});
|
|
172
|
-
expect(RESULT[1]).
|
|
172
|
+
expect(RESULT[1]).toMatchObject({
|
|
173
173
|
id: 'page3'
|
|
174
174
|
});
|
|
175
175
|
});
|
|
@@ -201,7 +201,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
201
201
|
}];
|
|
202
202
|
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
203
203
|
expect(RESULT.length).toEqual(2);
|
|
204
|
-
expect(RESULT[0]).
|
|
204
|
+
expect(RESULT[0]).toMatchObject({
|
|
205
205
|
id: 'page1',
|
|
206
206
|
collection: {
|
|
207
207
|
name: 'collection1',
|
|
@@ -210,7 +210,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
210
210
|
formData: {},
|
|
211
211
|
childPages: [PAGES[0], PAGES[1]]
|
|
212
212
|
});
|
|
213
|
-
expect(RESULT[1]).
|
|
213
|
+
expect(RESULT[1]).toMatchObject({
|
|
214
214
|
id: 'page3',
|
|
215
215
|
collection: {
|
|
216
216
|
name: 'collection2',
|
|
@@ -39,6 +39,11 @@ var validateTime = function validateTime(time) {
|
|
|
39
39
|
var intMinute = parseInt(minute, 10);
|
|
40
40
|
var badProps = [];
|
|
41
41
|
var messages = [];
|
|
42
|
+
var numericRegex = /^\d{0,2}:\d{0,2}$/;
|
|
43
|
+
if (!numericRegex.test(time)) {
|
|
44
|
+
badProps.push('invalid');
|
|
45
|
+
messages.push('Enter a valid time');
|
|
46
|
+
}
|
|
42
47
|
if (hour.length === 0) {
|
|
43
48
|
badProps.push('hour');
|
|
44
49
|
messages.push('Time must include a hour');
|
|
@@ -61,6 +66,9 @@ var validateTime = function validateTime(time) {
|
|
|
61
66
|
if (badProps.includes('minute')) {
|
|
62
67
|
propsInError.minute = true;
|
|
63
68
|
}
|
|
69
|
+
if (badProps.includes('invalid')) {
|
|
70
|
+
propsInError.invalid = true;
|
|
71
|
+
}
|
|
64
72
|
return {
|
|
65
73
|
message: badProps.length > 1 ? 'Enter a valid time' : messages[0],
|
|
66
74
|
propsInError: propsInError
|
|
@@ -64,6 +64,52 @@ describe('utils', function () {
|
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
+
test('should return an error if the time string contains non-numeric characters', function () {
|
|
68
|
+
var output = (0, _validateTime.default)('14:3A');
|
|
69
|
+
expect(output).toEqual({
|
|
70
|
+
message: 'Enter a valid time',
|
|
71
|
+
propsInError: {
|
|
72
|
+
invalid: true,
|
|
73
|
+
minute: true
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
test('should return an error if the time string contains more than two digits in hour', function () {
|
|
78
|
+
var output = (0, _validateTime.default)('144:30');
|
|
79
|
+
expect(output).toEqual({
|
|
80
|
+
message: 'Enter a valid time',
|
|
81
|
+
propsInError: {
|
|
82
|
+
invalid: true,
|
|
83
|
+
hour: true
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
test('should return an error if the time string contains more than two digits in minute', function () {
|
|
88
|
+
var output = (0, _validateTime.default)('14:309');
|
|
89
|
+
expect(output).toEqual({
|
|
90
|
+
message: 'Enter a valid time',
|
|
91
|
+
propsInError: {
|
|
92
|
+
invalid: true,
|
|
93
|
+
minute: true
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
test('should return an error if there is an additional colon in the time string', function () {
|
|
98
|
+
var output = (0, _validateTime.default)('14:30:');
|
|
99
|
+
expect(output).toEqual({
|
|
100
|
+
message: 'Enter a valid time',
|
|
101
|
+
propsInError: {
|
|
102
|
+
invalid: true
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
test('should return no error if there is a single digit for both hour and minute', function () {
|
|
107
|
+
var output = (0, _validateTime.default)('1:1');
|
|
108
|
+
expect(output).toEqual({
|
|
109
|
+
message: undefined,
|
|
110
|
+
propsInError: undefined
|
|
111
|
+
});
|
|
112
|
+
});
|
|
67
113
|
});
|
|
68
114
|
});
|
|
69
115
|
});
|