@ukhomeoffice/cop-react-form-renderer 6.11.1 → 6.12.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.
Files changed (49) hide show
  1. package/README.md +8 -0
  2. package/dist/components/CheckYourAnswers/Answer.js +1 -1
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +6 -2
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +131 -50
  5. package/dist/components/CollectionPage/CollectionPage.js +2 -1
  6. package/dist/components/CollectionSummary/CollectionSummary.js +6 -4
  7. package/dist/components/CollectionSummary/CollectionSummary.scss +5 -0
  8. package/dist/components/CollectionSummary/CollectionSummary.test.js +60 -36
  9. package/dist/components/CollectionSummary/RenderListView.js +18 -6
  10. package/dist/components/CollectionSummary/RenderListView.scss +9 -0
  11. package/dist/components/CollectionSummary/RenderListView.test.js +42 -5
  12. package/dist/components/CollectionSummary/SummaryCard.js +6 -4
  13. package/dist/components/CollectionSummary/SummaryCard.scss +6 -0
  14. package/dist/components/CollectionSummary/SummaryCard.test.js +5 -5
  15. package/dist/components/CollectionSummary/SummaryCardDetails.js +3 -2
  16. package/dist/components/CollectionSummary/SummaryCardDetails.scss +2 -0
  17. package/dist/components/FormComponent/Collection.js +2 -1
  18. package/dist/components/FormComponent/Collection.scss +1 -1
  19. package/dist/components/FormComponent/Container.js +2 -0
  20. package/dist/components/FormComponent/Container.scss +15 -0
  21. package/dist/components/FormComponent/FormComponent.js +1 -1
  22. package/dist/components/FormPage/FormPage.js +19 -7
  23. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +25 -13
  24. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +59 -1
  25. package/dist/components/FormRenderer/onPageAction.js +5 -1
  26. package/dist/json/actions.json +17 -0
  27. package/dist/json/actionsNoSave.json +17 -0
  28. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +7 -4
  29. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +39 -0
  30. package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
  31. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +2 -1
  32. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -26
  33. package/dist/utils/CollectionPage/setCollectionPageData.js +2 -1
  34. package/dist/utils/Data/deleteValues.js +22 -0
  35. package/dist/utils/Data/deleteValues.test.js +57 -0
  36. package/dist/utils/Data/getAutocompleteSource.test.js +14 -5
  37. package/dist/utils/Data/getOptions.js +2 -1
  38. package/dist/utils/Data/getOptions.test.js +26 -8
  39. package/dist/utils/Data/index.js +2 -0
  40. package/dist/utils/Operate/deleteValueInFormData.js +26 -0
  41. package/dist/utils/Operate/deleteValueInFormData.test.js +60 -0
  42. package/dist/utils/Operate/runPageOperations.js +2 -0
  43. package/dist/utils/Validate/additional/conditionallyPermittedChange.js +25 -0
  44. package/dist/utils/Validate/additional/conditionallyPermittedChange.test.js +33 -0
  45. package/dist/utils/Validate/additional/index.js +6 -1
  46. package/dist/utils/Validate/additional/index.test.js +66 -0
  47. package/dist/utils/Validate/additional/mustBeOneOf.js +21 -0
  48. package/dist/utils/Validate/additional/mustBeOneOf.test.js +36 -0
  49. package/package.json +4 -3
@@ -58,6 +58,72 @@ describe('utils', function () {
58
58
  var VALUE = (0, _dayjs.default)().add(150, 'day').format(_utils.DATE_FORMAT);
59
59
  expect((0, _index.default)(COMPONENT, VALUE)).toEqual(undefined);
60
60
  });
61
+ it('should apply optional validators that fail when the value is an object', function () {
62
+ var COMPONENT = {
63
+ fieldId: 'container',
64
+ components: [{
65
+ id: 'eventDate',
66
+ fieldId: 'eventDate'
67
+ }, {
68
+ id: 'eventTime',
69
+ fieldId: 'eventTime'
70
+ }],
71
+ additionalValidation: [{
72
+ function: 'mustBeEarlierDateTime',
73
+ date: 'eventDate',
74
+ time: 'eventTime',
75
+ message: 'The date and time cannot be in the future'
76
+ }]
77
+ };
78
+ var VALUE = {
79
+ container: {
80
+ eventDate: '01-07-4024',
81
+ eventTime: '1:1'
82
+ }
83
+ };
84
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual('The date and time cannot be in the future');
85
+ });
86
+ it('should apply optional validators that pass when the value is an object', function () {
87
+ var COMPONENT = {
88
+ fieldId: 'container',
89
+ components: [{
90
+ id: 'eventDate',
91
+ fieldId: 'eventDate'
92
+ }, {
93
+ id: 'eventTime',
94
+ fieldId: 'eventTime'
95
+ }],
96
+ additionalValidation: [{
97
+ function: 'mustBeEarlierDateTime',
98
+ date: 'eventDate',
99
+ time: 'eventTime',
100
+ message: 'The date and time cannot be in the future'
101
+ }]
102
+ };
103
+ var VALUE = {
104
+ container: {
105
+ eventDate: '01-07-1024',
106
+ eventTime: '1:1'
107
+ }
108
+ };
109
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual(undefined);
110
+ });
111
+ it('should apply optional validators when the value is within an object', function () {
112
+ var COMPONENT = {
113
+ additionalValidation: [{
114
+ function: 'mustBeAfter',
115
+ value: 3,
116
+ unit: 'day',
117
+ objectValueToUse: "date",
118
+ message: 'Date must be more than 3 days in the future'
119
+ }]
120
+ };
121
+ var VALUE = {
122
+ testValue: "",
123
+ date: (0, _dayjs.default)().add(1, 'day').format(_utils.DATE_FORMAT)
124
+ };
125
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual('Date must be more than 3 days in the future');
126
+ });
61
127
  });
62
128
  });
63
129
  });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * Function returns true if the string parameter is contained in the passed in array.
9
+ * @param {string} string - the string to check.
10
+ * @param {array} config.array - the array that the string will be checked against.
11
+ * @returns true if string is contained in config.array, false if not.
12
+ */
13
+ var mustBeOneOf = function mustBeOneOf(string, config) {
14
+ if (!string) {
15
+ // null, undefined and empty strings should be picked up by the required flag
16
+ // and not considered here as they would be valid for optional fields.
17
+ return true;
18
+ }
19
+ return config.array.includes(string);
20
+ };
21
+ var _default = exports.default = mustBeOneOf;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _mustBeOneOf = _interopRequireDefault(require("./mustBeOneOf"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ describe('utils', function () {
6
+ describe('Validate', function () {
7
+ describe('additional', function () {
8
+ describe('mustBeShorterThan', function () {
9
+ test('should return true given the string is in the array', function () {
10
+ var result = (0, _mustBeOneOf.default)('test2', {
11
+ array: ["test1", "test2", "test3", "test4"]
12
+ });
13
+ expect(result).toEqual(true);
14
+ });
15
+ test('should return false given the string is not in the array', function () {
16
+ var result = (0, _mustBeOneOf.default)('test5', {
17
+ array: ["test1", "test2", "test3", "test4"]
18
+ });
19
+ expect(result).toEqual(false);
20
+ });
21
+ test('should return false given the array is empty', function () {
22
+ var result = (0, _mustBeOneOf.default)('test1', {
23
+ array: []
24
+ });
25
+ expect(result).toEqual(false);
26
+ });
27
+ test('should return false when only the partial string is in the array', function () {
28
+ var result = (0, _mustBeOneOf.default)('test', {
29
+ array: ["test1", "test2", "test3", "test4"]
30
+ });
31
+ expect(result).toEqual(false);
32
+ });
33
+ });
34
+ });
35
+ });
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "6.11.1",
3
+ "version": "6.12.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,11 +16,12 @@
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": "^4.0.0",
19
+ "@ukhomeoffice/cop-react-components": "4.7.2",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^5.0.0",
23
- "web-vitals": "^1.0.1"
23
+ "web-vitals": "^1.0.1",
24
+ "uuid": "^8.1.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@babel/cli": "^7.15.4",