@ukhomeoffice/cop-react-form-renderer 5.20.0 → 5.23.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/dist/components/CheckYourAnswers/Answer.test.js +1 -1
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +1 -1
- package/dist/components/CollectionPage/CollectionPage.js +26 -10
- package/dist/components/CollectionPage/CollectionPage.test.js +256 -107
- package/dist/components/FormComponent/Collection.js +1 -1
- package/dist/components/FormComponent/Collection.test.js +1 -1
- package/dist/components/FormComponent/Container.test.js +1 -1
- package/dist/components/FormComponent/FormComponent.test.js +1 -1
- package/dist/components/FormPage/FormPage.test.js +1 -1
- package/dist/components/FormRenderer/FormRenderer.test.js +1 -1
- package/dist/components/FormRenderer/onCYAAction.js +59 -60
- package/dist/components/FormRenderer/onCYAAction.test.js +31 -0
- package/dist/components/FormRenderer/onPageAction.js +1 -1
- package/dist/components/FormRenderer/onPageAction.test.js +12 -0
- package/dist/components/PageActions/ActionButton.test.js +1 -1
- package/dist/components/PageActions/PageActions.test.js +1 -1
- package/dist/context/HooksContext/HooksContext.test.js +1 -1
- package/dist/context/ValidationContext/ValidationContext.js +1 -1
- package/dist/context/ValidationContext/ValidationContext.test.js +1 -1
- package/dist/hooks/useAxios.js +1 -1
- package/dist/hooks/useGetRequest.js +1 -1
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +22 -0
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +16 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +9 -4
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +30 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveId.js +24 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +25 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +35 -15
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +34 -0
- package/dist/utils/CollectionPage/getCollectionPageData.js +57 -0
- package/dist/utils/CollectionPage/getCollectionPageData.test.js +102 -0
- package/dist/utils/CollectionPage/index.js +9 -1
- package/dist/utils/CollectionPage/setCollectionPageData.js +52 -0
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +112 -0
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +1 -1
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +1 -1
- package/dist/utils/Validate/validatePage.js +2 -2
- package/dist/utils/Validate/validatePage.test.js +268 -18
- package/package.json +2 -2
|
@@ -100,6 +100,33 @@ describe('utils.Validate.Page', function () {
|
|
|
100
100
|
error: 'Echo is required'
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
|
+
it('should return an error for each required component on a nested collection page', function () {
|
|
104
|
+
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
105
|
+
// The only unrequired one
|
|
106
|
+
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
107
|
+
var PAGE = {
|
|
108
|
+
components: COMPONENTS,
|
|
109
|
+
collection: {
|
|
110
|
+
name: 'parent.child'
|
|
111
|
+
},
|
|
112
|
+
formData: null
|
|
113
|
+
};
|
|
114
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
115
|
+
expect(RESULT.length).toEqual(4);
|
|
116
|
+
expect(RESULT).toEqual([{
|
|
117
|
+
id: 'a',
|
|
118
|
+
error: 'Alpha is required'
|
|
119
|
+
}, {
|
|
120
|
+
id: 'b',
|
|
121
|
+
error: 'Bravo is required'
|
|
122
|
+
}, {
|
|
123
|
+
id: 'd',
|
|
124
|
+
error: 'Delta is required'
|
|
125
|
+
}, {
|
|
126
|
+
id: 'e',
|
|
127
|
+
error: 'Echo is required'
|
|
128
|
+
}]);
|
|
129
|
+
});
|
|
103
130
|
it('should return an error for each required component with interpolated label', function () {
|
|
104
131
|
var COMPONENTS = [
|
|
105
132
|
// eslint-disable-next-line no-template-curly-in-string
|
|
@@ -124,26 +151,22 @@ describe('utils.Validate.Page', function () {
|
|
|
124
151
|
};
|
|
125
152
|
var RESULT = (0, _validatePage.default)(PAGE);
|
|
126
153
|
expect(RESULT.length).toEqual(5);
|
|
127
|
-
expect(RESULT
|
|
154
|
+
expect(RESULT).toEqual([{
|
|
128
155
|
id: 'a',
|
|
129
156
|
error: "Alpha ".concat(PAGE.formData.tiger, " is required")
|
|
130
|
-
}
|
|
131
|
-
expect(RESULT[1]).toEqual({
|
|
157
|
+
}, {
|
|
132
158
|
id: 'b',
|
|
133
159
|
error: "Bravo ".concat(PAGE.formData.panther, " is required")
|
|
134
|
-
}
|
|
135
|
-
expect(RESULT[2]).toEqual({
|
|
160
|
+
}, {
|
|
136
161
|
id: 'c',
|
|
137
162
|
error: "Charlie ".concat(PAGE.formData.eagle, " is required")
|
|
138
|
-
}
|
|
139
|
-
expect(RESULT[3]).toEqual({
|
|
163
|
+
}, {
|
|
140
164
|
id: 'd',
|
|
141
165
|
error: "Delta ".concat(PAGE.formData.lion, " is required")
|
|
142
|
-
}
|
|
143
|
-
expect(RESULT[4]).toEqual({
|
|
166
|
+
}, {
|
|
144
167
|
id: 'e',
|
|
145
168
|
error: "Echo ".concat(PAGE.formData.zoo, " is required")
|
|
146
|
-
});
|
|
169
|
+
}]);
|
|
147
170
|
});
|
|
148
171
|
});
|
|
149
172
|
describe('when the form data is fully valid', function () {
|
|
@@ -337,22 +360,19 @@ describe('utils.Validate.Page', function () {
|
|
|
337
360
|
};
|
|
338
361
|
var RESULT = (0, _validatePage.default)(PAGE);
|
|
339
362
|
expect(RESULT.length).toEqual(4);
|
|
340
|
-
expect(RESULT
|
|
363
|
+
expect(RESULT).toEqual([{
|
|
341
364
|
id: 'a',
|
|
342
365
|
error: 'Alpha is required'
|
|
343
|
-
}
|
|
344
|
-
expect(RESULT[1]).toEqual({
|
|
366
|
+
}, {
|
|
345
367
|
id: 'b',
|
|
346
368
|
error: 'Bravo is required'
|
|
347
|
-
}
|
|
348
|
-
expect(RESULT[2]).toEqual({
|
|
369
|
+
}, {
|
|
349
370
|
id: 'd',
|
|
350
371
|
error: 'Delta is required'
|
|
351
|
-
}
|
|
352
|
-
expect(RESULT[3]).toEqual({
|
|
372
|
+
}, {
|
|
353
373
|
id: 'e',
|
|
354
374
|
error: 'Echo is required'
|
|
355
|
-
});
|
|
375
|
+
}]);
|
|
356
376
|
});
|
|
357
377
|
it('should return no errors on a collection page with a show_when that is false', function () {
|
|
358
378
|
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
@@ -469,4 +489,234 @@ describe('utils.Validate.Page', function () {
|
|
|
469
489
|
});
|
|
470
490
|
});
|
|
471
491
|
});
|
|
492
|
+
describe('with a nested CollectionPage', function () {
|
|
493
|
+
var COLLECTION = {
|
|
494
|
+
name: 'parent.child'
|
|
495
|
+
};
|
|
496
|
+
describe('when the form data is fully valid', function () {
|
|
497
|
+
var DATA = {
|
|
498
|
+
parentActiveId: '01',
|
|
499
|
+
childActiveId: '01',
|
|
500
|
+
parent: [{
|
|
501
|
+
id: '01',
|
|
502
|
+
child: [{
|
|
503
|
+
id: '01',
|
|
504
|
+
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
505
|
+
bravo: 'bravo.jones@digital.homeoffice.gov.uk'
|
|
506
|
+
}]
|
|
507
|
+
}]
|
|
508
|
+
};
|
|
509
|
+
it('should return no errors when none of the components are required or email types', function () {
|
|
510
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false)];
|
|
511
|
+
var PAGE = {
|
|
512
|
+
collection: COLLECTION,
|
|
513
|
+
components: COMPONENTS,
|
|
514
|
+
formData: DATA
|
|
515
|
+
};
|
|
516
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
517
|
+
});
|
|
518
|
+
it('should return no errors when all of the components are required but not email types', function () {
|
|
519
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true)];
|
|
520
|
+
var PAGE = {
|
|
521
|
+
collection: COLLECTION,
|
|
522
|
+
components: COMPONENTS,
|
|
523
|
+
formData: DATA
|
|
524
|
+
};
|
|
525
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
526
|
+
});
|
|
527
|
+
it('should return no errors when none of the components are required but are all email types', function () {
|
|
528
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false)];
|
|
529
|
+
var PAGE = {
|
|
530
|
+
collection: COLLECTION,
|
|
531
|
+
components: COMPONENTS,
|
|
532
|
+
formData: DATA
|
|
533
|
+
};
|
|
534
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
535
|
+
});
|
|
536
|
+
it('should return no errors when all of the components are required and email types', function () {
|
|
537
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true)];
|
|
538
|
+
var PAGE = {
|
|
539
|
+
collection: COLLECTION,
|
|
540
|
+
components: COMPONENTS,
|
|
541
|
+
formData: DATA
|
|
542
|
+
};
|
|
543
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
544
|
+
});
|
|
545
|
+
it('should return an error for each required component on a collection page with a show_when that is true', function () {
|
|
546
|
+
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
547
|
+
// The only unrequired one
|
|
548
|
+
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
549
|
+
var PAGE = {
|
|
550
|
+
components: COMPONENTS,
|
|
551
|
+
collection: {
|
|
552
|
+
name: 'parent.child'
|
|
553
|
+
},
|
|
554
|
+
show_when: {
|
|
555
|
+
field: 'isShown',
|
|
556
|
+
op: '=',
|
|
557
|
+
value: true
|
|
558
|
+
},
|
|
559
|
+
formData: {
|
|
560
|
+
parentActiveId: '01',
|
|
561
|
+
childActiveId: '01',
|
|
562
|
+
parent: [{
|
|
563
|
+
id: '01',
|
|
564
|
+
child: [{
|
|
565
|
+
id: '01',
|
|
566
|
+
isShown: true
|
|
567
|
+
}]
|
|
568
|
+
}]
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
572
|
+
expect(RESULT.length).toEqual(4);
|
|
573
|
+
expect(RESULT).toEqual([{
|
|
574
|
+
id: 'a',
|
|
575
|
+
error: 'Alpha is required'
|
|
576
|
+
}, {
|
|
577
|
+
id: 'b',
|
|
578
|
+
error: 'Bravo is required'
|
|
579
|
+
}, {
|
|
580
|
+
id: 'd',
|
|
581
|
+
error: 'Delta is required'
|
|
582
|
+
}, {
|
|
583
|
+
id: 'e',
|
|
584
|
+
error: 'Echo is required'
|
|
585
|
+
}]);
|
|
586
|
+
});
|
|
587
|
+
it('should return no errors on a collection page with a show_when that is false', function () {
|
|
588
|
+
var COMPONENTS = [setup('a', _models.ComponentTypes.TEXT, 'Alpha', true), setup('b', _models.ComponentTypes.TEXT, 'Bravo', true), setup('c', _models.ComponentTypes.TEXT, 'Charlie', false),
|
|
589
|
+
// The only unrequired one
|
|
590
|
+
setup('d', _models.ComponentTypes.TEXT, 'Delta', true), setup('e', _models.ComponentTypes.TEXT, 'Echo', true)];
|
|
591
|
+
var PAGE = {
|
|
592
|
+
components: COMPONENTS,
|
|
593
|
+
collection: {
|
|
594
|
+
name: 'parent.child'
|
|
595
|
+
},
|
|
596
|
+
show_when: {
|
|
597
|
+
field: 'isShown',
|
|
598
|
+
op: '=',
|
|
599
|
+
value: true
|
|
600
|
+
},
|
|
601
|
+
formData: {
|
|
602
|
+
parentActiveId: '01',
|
|
603
|
+
childActiveId: '01',
|
|
604
|
+
parent: [{
|
|
605
|
+
id: '01',
|
|
606
|
+
child: [{
|
|
607
|
+
id: '01',
|
|
608
|
+
isShown: false
|
|
609
|
+
}]
|
|
610
|
+
}]
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
614
|
+
expect(RESULT.length).toEqual(0);
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
describe('when the form data has one field missing and includes an invalid email', function () {
|
|
618
|
+
var DATA = {
|
|
619
|
+
parentActiveId: '01',
|
|
620
|
+
childActiveId: '01',
|
|
621
|
+
parent: [{
|
|
622
|
+
id: '01',
|
|
623
|
+
child: [{
|
|
624
|
+
id: '01',
|
|
625
|
+
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
626
|
+
bravo: 'bravo.jones@hotmail.com'
|
|
627
|
+
}]
|
|
628
|
+
}]
|
|
629
|
+
};
|
|
630
|
+
it('should return no errors when none of the components are required or email types', function () {
|
|
631
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', false), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', false), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', false)];
|
|
632
|
+
var PAGE = {
|
|
633
|
+
collection: COLLECTION,
|
|
634
|
+
components: COMPONENTS,
|
|
635
|
+
formData: null
|
|
636
|
+
};
|
|
637
|
+
expect((0, _validatePage.default)(PAGE).length).toEqual(0);
|
|
638
|
+
});
|
|
639
|
+
it('should return an error for the missing field when all are required but not email types', function () {
|
|
640
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.TEXT, 'Alpha', true), setup('bravo', _models.ComponentTypes.TEXT, 'Bravo', true), setup('charlie', _models.ComponentTypes.TEXT, 'Charlie', true)];
|
|
641
|
+
var PAGE = {
|
|
642
|
+
collection: COLLECTION,
|
|
643
|
+
components: COMPONENTS,
|
|
644
|
+
formData: DATA
|
|
645
|
+
};
|
|
646
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
647
|
+
expect(RESULT.length).toEqual(1);
|
|
648
|
+
expect(RESULT[0]).toEqual({
|
|
649
|
+
id: 'charlie',
|
|
650
|
+
error: 'Charlie is required'
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
it('should return an error for the invalid email field when none are required but all email types', function () {
|
|
654
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', false), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', false), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', false)];
|
|
655
|
+
var PAGE = {
|
|
656
|
+
collection: COLLECTION,
|
|
657
|
+
components: COMPONENTS,
|
|
658
|
+
formData: DATA
|
|
659
|
+
};
|
|
660
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
661
|
+
expect(RESULT.length).toEqual(1);
|
|
662
|
+
expect(RESULT[0]).toEqual({
|
|
663
|
+
id: 'bravo',
|
|
664
|
+
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
it('should return an error for both invalid fields when all are required and email types', function () {
|
|
668
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true), setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo', true), setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie', true)];
|
|
669
|
+
var PAGE = {
|
|
670
|
+
collection: COLLECTION,
|
|
671
|
+
components: COMPONENTS,
|
|
672
|
+
formData: DATA
|
|
673
|
+
};
|
|
674
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
675
|
+
expect(RESULT.length).toEqual(2);
|
|
676
|
+
expect(RESULT[0]).toEqual({
|
|
677
|
+
id: 'bravo',
|
|
678
|
+
error: 'Enter bravo in the correct format, like jane.doe@homeoffice.gov.uk'
|
|
679
|
+
});
|
|
680
|
+
expect(RESULT[1]).toEqual({
|
|
681
|
+
id: 'charlie',
|
|
682
|
+
error: 'Charlie is required'
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
it('should return an interpolated error for both invalid fields when all are required and email types', function () {
|
|
686
|
+
var COMPONENTS = [setup('alpha', _models.ComponentTypes.EMAIL, 'Alpha', true),
|
|
687
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
688
|
+
setup('bravo', _models.ComponentTypes.EMAIL, 'Bravo ${lion}', true),
|
|
689
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
690
|
+
setup('charlie', _models.ComponentTypes.EMAIL, 'Charlie ${panther}', true)];
|
|
691
|
+
var PAGE = {
|
|
692
|
+
collection: COLLECTION,
|
|
693
|
+
components: COMPONENTS,
|
|
694
|
+
formData: {
|
|
695
|
+
parentActiveId: '01',
|
|
696
|
+
childActiveId: '01',
|
|
697
|
+
parent: [{
|
|
698
|
+
id: '01',
|
|
699
|
+
child: [{
|
|
700
|
+
id: '01',
|
|
701
|
+
alpha: 'alpha.smith@digital.homeoffice.gov.uk',
|
|
702
|
+
bravo: 'bravo.jones@hotmail.com',
|
|
703
|
+
lion: 'Lion',
|
|
704
|
+
panther: 'Panther'
|
|
705
|
+
}]
|
|
706
|
+
}]
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
var RESULT = (0, _validatePage.default)(PAGE);
|
|
710
|
+
expect(RESULT.length).toEqual(2);
|
|
711
|
+
expect(RESULT[0]).toEqual({
|
|
712
|
+
id: 'bravo',
|
|
713
|
+
error: "Enter bravo Lion in the correct format, like jane.doe@homeoffice.gov.uk"
|
|
714
|
+
});
|
|
715
|
+
expect(RESULT[1]).toEqual({
|
|
716
|
+
id: 'charlie',
|
|
717
|
+
error: "Charlie Panther is required"
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
});
|
|
472
722
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.23.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "^3.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "^3.9.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|