@ukhomeoffice/cop-react-form-renderer 3.5.3 → 3.7.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.
@@ -101,7 +101,7 @@ var FormPage = function FormPage(_ref) {
101
101
  component: component,
102
102
  onChange: onPageChange,
103
103
  value: page.formData[component.fieldId] || patch[component.fieldId],
104
- formData: page.formData
104
+ formData: _objectSpread(_objectSpread({}, page.formData), patch)
105
105
  });
106
106
  }), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
107
107
  actions: page.actions,
@@ -13,6 +13,10 @@ var _mustBeInThePast = _interopRequireDefault(require("./mustBeInThePast"));
13
13
 
14
14
  var _mustBeInTheFuture = _interopRequireDefault(require("./mustBeInTheFuture"));
15
15
 
16
+ var _mustBeLongerThan = _interopRequireDefault(require("./mustBeLongerThan"));
17
+
18
+ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
19
+
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
18
22
  // Local imports
@@ -20,7 +24,9 @@ var functions = {
20
24
  mustBeAfter: _mustBeAfter.default,
21
25
  mustBeBefore: _mustBeBefore.default,
22
26
  mustBeInThePast: _mustBeInThePast.default,
23
- mustBeInTheFuture: _mustBeInTheFuture.default
27
+ mustBeInTheFuture: _mustBeInTheFuture.default,
28
+ mustBeLongerThan: _mustBeLongerThan.default,
29
+ mustBeShorterThan: _mustBeShorterThan.default
24
30
  };
25
31
 
26
32
  var additionalValidation = function additionalValidation(value, config) {
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Function returns true if the string parameter is longer than a given length, false
10
+ * if it is not.
11
+ * @param {string} string - the string to check the length of.
12
+ * @param {number} config.value - the length that string.length must be greater than.
13
+ * @returns true if string.length is greater than config.value, false if not.
14
+ */
15
+ var mustBeLongerThan = function mustBeLongerThan(string, config) {
16
+ if (!string) {
17
+ // null, undefined and empty strings should be picked up by the required flag
18
+ // and not considered here as they would be valid for optional fields.
19
+ return true;
20
+ }
21
+
22
+ return string.length > config.value;
23
+ };
24
+
25
+ var _default = mustBeLongerThan;
26
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _mustBeLongerThan = _interopRequireDefault(require("./mustBeLongerThan"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ describe('utils', function () {
8
+ describe('Validate', function () {
9
+ describe('additional', function () {
10
+ describe('mustBeLongerThan', function () {
11
+ test('should return true given a string longer than the given length', function () {
12
+ var result = (0, _mustBeLongerThan.default)('test', {
13
+ value: 3
14
+ });
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false given a string shorter than the given length', function () {
18
+ var result = (0, _mustBeLongerThan.default)('to', {
19
+ value: 3
20
+ });
21
+ expect(result).toEqual(false);
22
+ });
23
+ test('should return false given a string equal to the given length', function () {
24
+ var result = (0, _mustBeLongerThan.default)('dog', {
25
+ value: 3
26
+ });
27
+ expect(result).toEqual(false);
28
+ });
29
+ test('should return true when string is undefined', function () {
30
+ var result = (0, _mustBeLongerThan.default)(undefined, {
31
+ value: 3
32
+ });
33
+ expect(result).toEqual(true);
34
+ });
35
+ test('should return true when string is empty', function () {
36
+ var result = (0, _mustBeLongerThan.default)('', {
37
+ value: 3
38
+ });
39
+ expect(result).toEqual(true);
40
+ });
41
+ test('should return true when string is null', function () {
42
+ var result = (0, _mustBeLongerThan.default)(null, {
43
+ value: 3
44
+ });
45
+ expect(result).toEqual(true);
46
+ });
47
+ });
48
+ });
49
+ });
50
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Function returns true if the string parameter is shorter than a given length, false
10
+ * if it is not.
11
+ * @param {string} string - the string to check the length of.
12
+ * @param {number} config.value - the length that string.length must be less than.
13
+ * @returns true if string.length is greater than config.value, false if not.
14
+ */
15
+ var mustBeShorterThan = function mustBeShorterThan(string, config) {
16
+ if (!string) {
17
+ // null, undefined and empty strings should be picked up by the required flag
18
+ // and not considered here as they would be valid for optional fields.
19
+ return true;
20
+ }
21
+
22
+ return string.length < config.value;
23
+ };
24
+
25
+ var _default = mustBeShorterThan;
26
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ describe('utils', function () {
8
+ describe('Validate', function () {
9
+ describe('additional', function () {
10
+ describe('mustBeShorterThan', function () {
11
+ test('should return true given a string shorter than the given length', function () {
12
+ var result = (0, _mustBeShorterThan.default)('to', {
13
+ value: 3
14
+ });
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false given a string longer than the given length', function () {
18
+ var result = (0, _mustBeShorterThan.default)('test', {
19
+ value: 3
20
+ });
21
+ expect(result).toEqual(false);
22
+ });
23
+ test('should return false given a string equal to the given length', function () {
24
+ var result = (0, _mustBeShorterThan.default)('dog', {
25
+ value: 3
26
+ });
27
+ expect(result).toEqual(false);
28
+ });
29
+ test('should return true when string is undefined', function () {
30
+ var result = (0, _mustBeShorterThan.default)(undefined, {
31
+ value: 3
32
+ });
33
+ expect(result).toEqual(true);
34
+ });
35
+ test('should return true when string is empty', function () {
36
+ var result = (0, _mustBeShorterThan.default)('', {
37
+ value: 3
38
+ });
39
+ expect(result).toEqual(true);
40
+ });
41
+ test('should return true when string is null', function () {
42
+ var result = (0, _mustBeShorterThan.default)(null, {
43
+ value: 3
44
+ });
45
+ expect(result).toEqual(true);
46
+ });
47
+ });
48
+ });
49
+ });
50
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.5.3",
3
+ "version": "3.7.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,8 +16,8 @@
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": "^1.9.5",
20
- "axios": "^0.21.1",
19
+ "@ukhomeoffice/cop-react-components": "1.9.5",
20
+ "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^3.13.0",
23
23
  "web-vitals": "^1.0.1"