@ukhomeoffice/cop-react-form-renderer 2.2.0 → 2.6.1-alpha

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 (88) hide show
  1. package/dist/components/FormComponent/Container.test.js +250 -0
  2. package/dist/components/FormComponent/FormComponent.js +101 -22
  3. package/dist/components/FormPage/FormPage.js +2 -1
  4. package/dist/components/FormRenderer/FormRenderer.js +105 -6
  5. package/dist/components/FormRenderer/FormRenderer.test.js +235 -0
  6. package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
  7. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
  8. package/dist/components/FormRenderer/helpers/getPage.js +1 -1
  9. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
  10. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
  11. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
  12. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
  13. package/dist/components/FormRenderer/helpers/index.js +7 -1
  14. package/dist/components/TaskList/Task.js +83 -0
  15. package/dist/components/TaskList/Task.test.js +112 -0
  16. package/dist/components/TaskList/TaskList.js +112 -0
  17. package/dist/components/TaskList/TaskList.scss +70 -0
  18. package/dist/components/TaskList/TaskList.stories.mdx +57 -0
  19. package/dist/components/TaskList/TaskList.test.js +223 -0
  20. package/dist/components/TaskList/TaskState.js +42 -0
  21. package/dist/components/TaskList/TaskState.test.js +99 -0
  22. package/dist/components/TaskList/index.js +13 -0
  23. package/dist/hooks/index.js +19 -1
  24. package/dist/json/taskList.json +228 -0
  25. package/dist/json/userProfile.data.json +2 -1
  26. package/dist/models/ComponentTypes.js +5 -1
  27. package/dist/models/FormTypes.js +2 -0
  28. package/dist/models/HubFormats.js +3 -1
  29. package/dist/models/PageAction.js +5 -0
  30. package/dist/models/TaskStates.js +41 -0
  31. package/dist/models/index.js +8 -0
  32. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +40 -0
  33. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +257 -0
  34. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -1
  35. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +44 -0
  36. package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -0
  37. package/dist/utils/Component/cleanAttributes.js +1 -1
  38. package/dist/utils/Component/getComponent.js +8 -0
  39. package/dist/utils/Component/isEditable.js +1 -1
  40. package/dist/utils/Component/showComponent.js +2 -20
  41. package/dist/utils/Condition/index.js +19 -0
  42. package/dist/utils/Condition/meetsAllConditions.js +40 -0
  43. package/dist/utils/Condition/meetsAllConditions.test.js +62 -0
  44. package/dist/utils/{meetsCondition.js → Condition/meetsCondition.js} +0 -0
  45. package/dist/utils/Condition/meetsCondition.test.js +302 -0
  46. package/dist/utils/Condition/setupConditions.js +47 -0
  47. package/dist/utils/Condition/setupConditions.test.js +35 -0
  48. package/dist/utils/Container/getEditableComponents.js +38 -0
  49. package/dist/utils/Container/getEditableComponents.test.js +157 -0
  50. package/dist/utils/Container/index.js +22 -0
  51. package/dist/utils/Container/setupNesting.js +45 -0
  52. package/dist/utils/Container/setupNesting.test.js +92 -0
  53. package/dist/utils/Container/showContainer.js +61 -0
  54. package/dist/utils/Container/showContainer.test.js +128 -0
  55. package/dist/utils/Data/getDataPath.js +90 -0
  56. package/dist/utils/Data/getDataPath.test.js +52 -0
  57. package/dist/utils/Data/index.js +3 -0
  58. package/dist/utils/FormPage/getFormPage.js +4 -2
  59. package/dist/utils/FormPage/getFormPage.test.js +18 -7
  60. package/dist/utils/FormPage/getFormPages.test.js +5 -2
  61. package/dist/utils/FormPage/getPageActions.js +6 -0
  62. package/dist/utils/FormPage/index.js +0 -3
  63. package/dist/utils/FormPage/showFormPage.js +7 -27
  64. package/dist/utils/Hub/getFormHub.js +4 -0
  65. package/dist/utils/Hub/getFormHub.test.js +15 -4
  66. package/dist/utils/Validate/additional/index.js +55 -0
  67. package/dist/utils/Validate/additional/index.test.js +69 -0
  68. package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
  69. package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
  70. package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
  71. package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
  72. package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
  73. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
  74. package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
  75. package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
  76. package/dist/utils/Validate/additional/utils.js +66 -0
  77. package/dist/utils/Validate/index.js +7 -1
  78. package/dist/utils/Validate/validateComponent.js +57 -0
  79. package/dist/utils/Validate/validateComponent.test.js +92 -2
  80. package/dist/utils/Validate/validateDate.js +155 -0
  81. package/dist/utils/Validate/validateDate.test.js +118 -0
  82. package/dist/utils/Validate/validatePage.js +6 -8
  83. package/dist/utils/Validate/validateTime.js +95 -0
  84. package/dist/utils/Validate/validateTime.test.js +61 -0
  85. package/dist/utils/index.js +6 -3
  86. package/package.json +5 -4
  87. package/dist/utils/FormPage/getEditableComponents.js +0 -28
  88. package/dist/utils/FormPage/getEditableComponents.test.js +0 -75
@@ -63,11 +63,11 @@ describe('utils', function () {
63
63
  it("should return an appropriate page when the format is not \"".concat(_models.HubFormats.CYA, "\" and hub contains components"), function () {
64
64
  var HUB = {
65
65
  title: 'Hub title',
66
- components: ["Opening paragraph", {
66
+ components: ['Opening paragraph', {
67
67
  type: 'heading',
68
68
  size: 'l',
69
69
  content: 'Hub heading'
70
- }, "Closing paragraph", {
70
+ }, 'Closing paragraph', {
71
71
  use: 'a'
72
72
  }]
73
73
  };
@@ -78,19 +78,30 @@ describe('utils', function () {
78
78
  type: 'html',
79
79
  tagName: 'p',
80
80
  content: HUB.components[0]
81
- }, HUB.components[1], {
81
+ }, _objectSpread(_objectSpread({}, HUB.components[1]), {}, {
82
+ full_path: HUB.components[1].fieldId
83
+ }), {
82
84
  type: 'html',
83
85
  tagName: 'p',
84
86
  content: HUB.components[2]
85
87
  }, _objectSpread(_objectSpread({
86
88
  use: 'a'
87
89
  }, A), {}, {
88
- cya_label: A.label
90
+ cya_label: A.label,
91
+ full_path: A.fieldId
89
92
  })],
90
93
  formData: FORM_DATA
91
94
  });
92
95
  });
93
96
  });
97
+ describe("when the FormType is \"".concat(_models.FormTypes.TASK, "\""), function () {
98
+ it("should return the string \"".concat(_models.HubFormats.TASK, "\" when the format is set to \"").concat(_models.HubFormats.TASK, "\""), function () {
99
+ var HUB = {
100
+ format: _models.HubFormats.TASK
101
+ };
102
+ expect((0, _getFormHub.default)(_models.FormTypes.TASK, HUB, FORM_COMPONENTS, FORM_DATA)).toEqual(_models.HubFormats.TASK);
103
+ });
104
+ });
94
105
  });
95
106
  });
96
107
  });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _mustBeAfter = _interopRequireDefault(require("./mustBeAfter"));
9
+
10
+ var _mustBeBefore = _interopRequireDefault(require("./mustBeBefore"));
11
+
12
+ var _mustBeInThePast = _interopRequireDefault(require("./mustBeInThePast"));
13
+
14
+ var _mustBeInTheFuture = _interopRequireDefault(require("./mustBeInTheFuture"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ // Local imports
19
+ var functions = {
20
+ mustBeAfter: _mustBeAfter.default,
21
+ mustBeBefore: _mustBeBefore.default,
22
+ mustBeInThePast: _mustBeInThePast.default,
23
+ mustBeInTheFuture: _mustBeInTheFuture.default
24
+ };
25
+
26
+ var additionalValidation = function additionalValidation(value, config) {
27
+ var fn = functions[config.function];
28
+
29
+ if (typeof fn === 'function') {
30
+ return fn(value, config) ? undefined : config.message;
31
+ }
32
+
33
+ return undefined;
34
+ };
35
+
36
+ var runAdditionalComponentValidation = function runAdditionalComponentValidation(component, value) {
37
+ // We only care when we have a value - if we don't have one but want one, set `required: true`.
38
+ if (!!value) {
39
+ if (Array.isArray(component.additionalValidation)) {
40
+ var error = undefined;
41
+ component.additionalValidation.forEach(function (config) {
42
+ // If we've already encountered an error, don't run any more validators.
43
+ if (!error) {
44
+ error = additionalValidation(value, config);
45
+ }
46
+ });
47
+ return error;
48
+ }
49
+ }
50
+
51
+ return undefined;
52
+ };
53
+
54
+ var _default = runAdditionalComponentValidation;
55
+ exports.default = _default;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _dayjs = _interopRequireDefault(require("dayjs"));
4
+
5
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
6
+
7
+ var _utils = require("./utils");
8
+
9
+ var _index = _interopRequireDefault(require("./index"));
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ _dayjs.default.extend(_customParseFormat.default);
14
+
15
+ describe('utils', function () {
16
+ describe('Validate', function () {
17
+ describe('additional', function () {
18
+ it('should apply optional validators when specified', function () {
19
+ var COMPONENT = {
20
+ additionalValidation: [{
21
+ function: 'mustBeAfter',
22
+ value: 3,
23
+ unit: 'day',
24
+ message: 'Date must be more than 3 days in the future'
25
+ }]
26
+ };
27
+ var VALUE = (0, _dayjs.default)().add(1, 'day').format(_utils.DATE_FORMAT);
28
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual('Date must be more than 3 days in the future');
29
+ });
30
+ it('should apply multiple optional validators when specified', function () {
31
+ var COMPONENT = {
32
+ additionalValidation: [{
33
+ function: 'mustBeAfter',
34
+ value: 100,
35
+ unit: 'day',
36
+ message: 'Date must be more than 100 days in the future'
37
+ }, {
38
+ function: 'mustBeBefore',
39
+ value: 200,
40
+ unit: 'day',
41
+ message: 'Date must be less than 200 days in the future'
42
+ }]
43
+ };
44
+ var VALUE = (0, _dayjs.default)().add(250, 'day').format(_utils.DATE_FORMAT);
45
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual('Date must be less than 200 days in the future');
46
+ });
47
+ it('should apply multiple optional validators when specified and return undefined if all are passed', function () {
48
+ var COMPONENT = {
49
+ additionalValidation: [{
50
+ function: 'mustBeAfter',
51
+ value: 100,
52
+ unit: 'day',
53
+ message: 'Date must be more than 100 days in the future'
54
+ }, {
55
+ function: 'mustBeBefore',
56
+ value: 200,
57
+ unit: 'day',
58
+ message: 'Date must be less than 200 days in the future'
59
+ }, {
60
+ function: 'mustBeInTheFuture',
61
+ message: 'Date must be in the future'
62
+ }]
63
+ };
64
+ var VALUE = (0, _dayjs.default)().add(150, 'day').format(_utils.DATE_FORMAT);
65
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual(undefined);
66
+ });
67
+ });
68
+ });
69
+ });
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _dayjs = _interopRequireDefault(require("dayjs"));
9
+
10
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
11
+
12
+ var _utils = require("./utils");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ // Global imports
17
+ // Local imports
18
+ _dayjs.default.extend(_customParseFormat.default);
19
+ /**
20
+ * Function returns true if the date string parameter is for a date more than ('is before') N months
21
+ * in the past, where N is the number of months parameter
22
+ * NOTE: the one minute reduction on the threshold date is a workaround for as apparent bug in the
23
+ * day.js isBefore() function when checking on 'same dates'
24
+ * @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
25
+ * @param {string} config.unit - day, month or year
26
+ * @param {number} config.value - number of the unit to be after
27
+ * @returns false if date is NOT after the no of months in the past.
28
+ */
29
+
30
+
31
+ var mustBeAfter = function mustBeAfter(date, config) {
32
+ var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
33
+ return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isAfter(dateToCompare);
34
+ };
35
+
36
+ var _default = mustBeAfter;
37
+ exports.default = _default;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _dayjs = _interopRequireDefault(require("dayjs"));
4
+
5
+ var _mustBeAfter = _interopRequireDefault(require("./mustBeAfter"));
6
+
7
+ var _utils = require("./utils");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('utils', function () {
12
+ describe('Validate', function () {
13
+ describe('additional', function () {
14
+ describe('mustBeAfter', function () {
15
+ test('should return true given a date after the given number of months in the future', function () {
16
+ var date = (0, _dayjs.default)().add(3, 'month').format(_utils.DATE_FORMAT);
17
+ var result = (0, _mustBeAfter.default)(date, {
18
+ value: 1,
19
+ unit: 'month'
20
+ });
21
+ expect(result).toEqual(true);
22
+ });
23
+ test('should return false given a date before the given number of months in the future', function () {
24
+ var date = (0, _dayjs.default)().add(3, 'month').format(_utils.DATE_FORMAT);
25
+ var result = (0, _mustBeAfter.default)(date, {
26
+ value: 5,
27
+ unit: 'month'
28
+ });
29
+ expect(result).toEqual(false);
30
+ });
31
+ test('should return true given a date after the given number of months in the past', function () {
32
+ var date = (0, _dayjs.default)().add(-3, 'month').format(_utils.DATE_FORMAT);
33
+ var result = (0, _mustBeAfter.default)(date, {
34
+ value: -5,
35
+ unit: 'month'
36
+ });
37
+ expect(result).toEqual(true);
38
+ });
39
+ test('should return false given a date before the given number of months in the past', function () {
40
+ var date = (0, _dayjs.default)().add(-10, 'month').format(_utils.DATE_FORMAT);
41
+ var result = (0, _mustBeAfter.default)(date, {
42
+ value: -5,
43
+ unit: 'month'
44
+ });
45
+ expect(result).toEqual(false);
46
+ });
47
+ test('should return true given a date after the given number of years in the future', function () {
48
+ var date = (0, _dayjs.default)().add(3, 'year').format(_utils.DATE_FORMAT);
49
+ var result = (0, _mustBeAfter.default)(date, {
50
+ value: 1,
51
+ unit: 'year'
52
+ });
53
+ expect(result).toEqual(true);
54
+ });
55
+ test('should return false given a date before the given number of years in the future', function () {
56
+ var date = (0, _dayjs.default)().add(15, 'year').format(_utils.DATE_FORMAT);
57
+ var result = (0, _mustBeAfter.default)(date, {
58
+ value: 20,
59
+ unit: 'year'
60
+ });
61
+ expect(result).toEqual(false);
62
+ });
63
+ test('should return true given a date after the given number of years in the past', function () {
64
+ var date = (0, _dayjs.default)().add(-15, 'year').format(_utils.DATE_FORMAT);
65
+ var result = (0, _mustBeAfter.default)(date, {
66
+ value: -20,
67
+ unit: 'year'
68
+ });
69
+ expect(result).toEqual(true);
70
+ });
71
+ test('should return false given a date before the given number of years in the past', function () {
72
+ var date = (0, _dayjs.default)().add(-25, 'year').format(_utils.DATE_FORMAT);
73
+ var result = (0, _mustBeAfter.default)(date, {
74
+ value: -20,
75
+ unit: 'year'
76
+ });
77
+ expect(result).toEqual(false);
78
+ });
79
+ test('should return true given a date after the given number of days in the future', function () {
80
+ var date = (0, _dayjs.default)().add(3, 'day').format(_utils.DATE_FORMAT);
81
+ var result = (0, _mustBeAfter.default)(date, {
82
+ value: 1,
83
+ unit: 'day'
84
+ });
85
+ expect(result).toEqual(true);
86
+ });
87
+ test('should return true given a date before the given number of days in the future', function () {
88
+ var date = (0, _dayjs.default)().add(250, 'day').format(_utils.DATE_FORMAT);
89
+ var result = (0, _mustBeAfter.default)(date, {
90
+ value: 275,
91
+ unit: 'day'
92
+ });
93
+ expect(result).toEqual(false);
94
+ });
95
+ });
96
+ });
97
+ });
98
+ });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _dayjs = _interopRequireDefault(require("dayjs"));
9
+
10
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
11
+
12
+ var _utils = require("./utils");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ // Global imports
17
+ // Local imports
18
+ _dayjs.default.extend(_customParseFormat.default);
19
+ /**
20
+ * Function returns false if the date string parameter is for a date more than N in the future
21
+ * where N is the number of months parameter
22
+ * @param {string} dateToCheck - date string in a valid date format e.g. DD-MM-YYYY
23
+ * @param {string} config.unit - day, month or year
24
+ * @param {number} config.value - number of the unit to be before
25
+ * @returns true if date is not after the no of months in future.
26
+ */
27
+
28
+
29
+ var mustBeBefore = function mustBeBefore(date, config) {
30
+ var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
31
+ return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isBefore(dateToCompare);
32
+ };
33
+
34
+ var _default = mustBeBefore;
35
+ exports.default = _default;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _dayjs = _interopRequireDefault(require("dayjs"));
4
+
5
+ var _mustBeBefore = _interopRequireDefault(require("./mustBeBefore"));
6
+
7
+ var _utils = require("./utils");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ describe('utils', function () {
12
+ describe('Validate', function () {
13
+ describe('additional', function () {
14
+ describe('mustBeBefore', function () {
15
+ test('should return true given a date before the given number of months in the future', function () {
16
+ var date = (0, _dayjs.default)().add(1, 'month').format(_utils.DATE_FORMAT);
17
+ var result = (0, _mustBeBefore.default)(date, {
18
+ value: 3,
19
+ unit: 'month'
20
+ });
21
+ expect(result).toEqual(true);
22
+ });
23
+ test('should return false given a date after the given number of months in the future', function () {
24
+ var date = (0, _dayjs.default)().add(5, 'month').format(_utils.DATE_FORMAT);
25
+ var result = (0, _mustBeBefore.default)(date, {
26
+ value: 3,
27
+ unit: 'month'
28
+ });
29
+ expect(result).toEqual(false);
30
+ });
31
+ test('should return true given a date before the given number of years in the future', function () {
32
+ var date = (0, _dayjs.default)().add(1, 'year').format(_utils.DATE_FORMAT);
33
+ var result = (0, _mustBeBefore.default)(date, {
34
+ value: 3,
35
+ unit: 'year'
36
+ });
37
+ expect(result).toEqual(true);
38
+ });
39
+ test('should return false given a date after the given number of years in the future', function () {
40
+ var date = (0, _dayjs.default)().add(20, 'year').format(_utils.DATE_FORMAT);
41
+ var result = (0, _mustBeBefore.default)(date, {
42
+ value: 15,
43
+ unit: 'year'
44
+ });
45
+ expect(result).toEqual(false);
46
+ });
47
+ test('should return true given a date before the given number of days in the future', function () {
48
+ var date = (0, _dayjs.default)().add(1, 'day').format(_utils.DATE_FORMAT);
49
+ var result = (0, _mustBeBefore.default)(date, {
50
+ value: 3,
51
+ unit: 'day'
52
+ });
53
+ expect(result).toEqual(true);
54
+ });
55
+ test('should return true given a date after the given number of days in the future', function () {
56
+ var date = (0, _dayjs.default)().add(275, 'day').format(_utils.DATE_FORMAT);
57
+ var result = (0, _mustBeBefore.default)(date, {
58
+ value: 250,
59
+ unit: 'day'
60
+ });
61
+ expect(result).toEqual(false);
62
+ });
63
+ });
64
+ });
65
+ });
66
+ });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _dayjs = _interopRequireDefault(require("dayjs"));
9
+
10
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
11
+
12
+ var _isToday = _interopRequireDefault(require("dayjs/plugin/isToday"));
13
+
14
+ var _utils = require("./utils");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ // Global Imports
19
+ //Local imports
20
+ _dayjs.default.extend(_customParseFormat.default);
21
+
22
+ _dayjs.default.extend(_isToday.default);
23
+ /**
24
+ * Function returns true if the date parameter is a date after today, else returns false
25
+ * @param {string} date - date string e.g. '03-12-2021'
26
+ * @param {boolean} config.todayAllowed - true if today should be a valid date
27
+ * @returns true if date is after current date
28
+ */
29
+
30
+
31
+ var mustBeInTheFuture = function mustBeInTheFuture(date, config) {
32
+ var afterToday = (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isAfter((0, _dayjs.default)());
33
+
34
+ if (afterToday) {
35
+ return true;
36
+ }
37
+
38
+ return !!(config !== null && config !== void 0 && config.todayAllowed) && (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isToday();
39
+ };
40
+
41
+ var _default = mustBeInTheFuture;
42
+ exports.default = _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _dayjs = _interopRequireDefault(require("dayjs"));
4
+
5
+ var _mustBeInTheFuture = _interopRequireDefault(require("./mustBeInTheFuture"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ describe('utils', function () {
10
+ describe('Validate', function () {
11
+ describe('additional', function () {
12
+ describe('mustBeInTheFuture', function () {
13
+ test('should return false given a date in the past', function () {
14
+ var result = (0, _mustBeInTheFuture.default)((0, _dayjs.default)().subtract(1, 'day').format('DD-MM-YYYY'));
15
+ expect(result).toEqual(false);
16
+ });
17
+ test('should return true given a date in the future', function () {
18
+ var result = (0, _mustBeInTheFuture.default)((0, _dayjs.default)().add(1, 'day').format('DD-MM-YYYY'));
19
+ expect(result).toEqual(true);
20
+ });
21
+ test('should return false given todays date', function () {
22
+ var result = (0, _mustBeInTheFuture.default)((0, _dayjs.default)().format('DD-MM-YYYY'));
23
+ expect(result).toEqual(false);
24
+ });
25
+ test('should return true given todays date if todayAllowed is true', function () {
26
+ var result = (0, _mustBeInTheFuture.default)((0, _dayjs.default)().format('DD-MM-YYYY'), {
27
+ todayAllowed: true
28
+ });
29
+ expect(result).toEqual(true);
30
+ });
31
+ });
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _dayjs = _interopRequireDefault(require("dayjs"));
9
+
10
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
11
+
12
+ var _isToday = _interopRequireDefault(require("dayjs/plugin/isToday"));
13
+
14
+ var _utils = require("./utils");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ // Global imports
19
+ //Local imports
20
+ _dayjs.default.extend(_customParseFormat.default);
21
+
22
+ _dayjs.default.extend(_isToday.default);
23
+ /**
24
+ * Function returns true if the date parameter is a date before today, else returns false
25
+ * dayjs counts today as before today so also cover same day inputs
26
+ * @param {string} date - date string e.g. '03-12-2021'
27
+ * @param {boolean} config.todayAllowed - true if today should be a valid date
28
+ * @returns true if date is before current date
29
+ */
30
+
31
+
32
+ var mustBeInThePast = function mustBeInThePast(date, config) {
33
+ var beforeToday = (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isBefore((0, _dayjs.default)());
34
+ var isToday = (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isToday(); //dayjs classifies the current day as in the past so exclude it here
35
+
36
+ if (beforeToday && !isToday) {
37
+ return true;
38
+ }
39
+
40
+ return isToday && !!(config !== null && config !== void 0 && config.todayAllowed);
41
+ };
42
+
43
+ var _default = mustBeInThePast;
44
+ exports.default = _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _dayjs = _interopRequireDefault(require("dayjs"));
4
+
5
+ var _mustBeInThePast = _interopRequireDefault(require("./mustBeInThePast"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ describe('utils', function () {
10
+ describe('Validate', function () {
11
+ describe('additional', function () {
12
+ describe('mustBeInThePast', function () {
13
+ test('should return true given a date in the past', function () {
14
+ var result = (0, _mustBeInThePast.default)((0, _dayjs.default)().subtract(1, 'day').format('DD-MM-YYYY'));
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false given a date in the future', function () {
18
+ var result = (0, _mustBeInThePast.default)((0, _dayjs.default)().add(1, 'day').format('DD-MM-YYYY'));
19
+ expect(result).toEqual(false);
20
+ });
21
+ test('should return false given todays date', function () {
22
+ var result = (0, _mustBeInThePast.default)((0, _dayjs.default)().format('DD-MM-YYYY'));
23
+ expect(result).toEqual(false);
24
+ });
25
+ test('should return true given todays date if todayAllowed is true', function () {
26
+ var result = (0, _mustBeInThePast.default)((0, _dayjs.default)().format('DD-MM-YYYY'), {
27
+ todayAllowed: true
28
+ });
29
+ expect(result).toEqual(true);
30
+ });
31
+ });
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formattedTime = exports.formatString = exports.DATE_FORMAT = void 0;
7
+
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
+
16
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
+
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+
20
+ var isNumeric = function isNumeric(value) {
21
+ return /^-?\d+$/.test(value);
22
+ };
23
+
24
+ var formatString = function formatString(date) {
25
+ var _date$split = date.split('-'),
26
+ _date$split2 = _slicedToArray(_date$split, 3),
27
+ day = _date$split2[0],
28
+ month = _date$split2[1],
29
+ year = _date$split2[2];
30
+
31
+ return "".concat(formatInTwoDigits(day), "-").concat(formatInTwoDigits(month), "-").concat(year);
32
+ };
33
+
34
+ exports.formatString = formatString;
35
+
36
+ var formattedTime = function formattedTime(time) {
37
+ var _time$split = time.split(':'),
38
+ _time$split2 = _slicedToArray(_time$split, 2),
39
+ hour = _time$split2[0],
40
+ minute = _time$split2[1];
41
+
42
+ return "".concat(formatInTwoDigits(hour), ":").concat(formatInTwoDigits(minute));
43
+ };
44
+ /**
45
+
46
+ /**
47
+ * Prepends a leading zero if the 'date component' parameter contains only a single digit.
48
+ * if the parameter contains more than one digit it is returned unchanged.
49
+ * If the parameter contains a non-numeric value it returned as an empty string.
50
+ * @param {string} dateComponent - the value representing a day or month.
51
+ * @returns the value (appended with a leading zero, if the value passed in was a single digit)
52
+ */
53
+
54
+
55
+ exports.formattedTime = formattedTime;
56
+
57
+ var formatInTwoDigits = function formatInTwoDigits(dateComponent) {
58
+ if (isNumeric(dateComponent)) {
59
+ return dateComponent.padStart(2, '0');
60
+ }
61
+
62
+ return '';
63
+ };
64
+
65
+ var DATE_FORMAT = 'DD-MM-YYYY';
66
+ exports.DATE_FORMAT = DATE_FORMAT;
@@ -7,20 +7,26 @@ exports.default = void 0;
7
7
 
8
8
  var _validateComponent = _interopRequireDefault(require("./validateComponent"));
9
9
 
10
+ var _validateDate = _interopRequireDefault(require("./validateDate"));
11
+
10
12
  var _validateEmail = _interopRequireDefault(require("./validateEmail"));
11
13
 
12
14
  var _validatePage = _interopRequireDefault(require("./validatePage"));
13
15
 
14
16
  var _validateRequired = _interopRequireDefault(require("./validateRequired"));
15
17
 
18
+ var _validateTime = _interopRequireDefault(require("./validateTime"));
19
+
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
18
22
  // Local imports
19
23
  var Validate = {
20
24
  component: _validateComponent.default,
21
25
  email: _validateEmail.default,
26
+ date: _validateDate.default,
22
27
  page: _validatePage.default,
23
- required: _validateRequired.default
28
+ required: _validateRequired.default,
29
+ time: _validateTime.default
24
30
  };
25
31
  var _default = Validate;
26
32
  exports.default = _default;