@ukhomeoffice/cop-react-form-renderer 2.0.0 → 2.5.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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +16 -5
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +199 -79
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +44 -0
- package/dist/components/FormComponent/FormComponent.js +6 -1
- package/dist/components/FormComponent/FormComponent.test.js +67 -0
- package/dist/components/FormRenderer/FormRenderer.js +122 -11
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +115 -49
- package/dist/components/FormRenderer/FormRenderer.test.js +275 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
- package/dist/components/FormRenderer/helpers/getPage.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
- package/dist/components/FormRenderer/helpers/index.js +7 -1
- package/dist/components/SummaryList/SummaryList.js +7 -4
- package/dist/components/SummaryList/SummaryList.scss +10 -2
- package/dist/components/SummaryList/SummaryList.stories.mdx +64 -10
- package/dist/components/SummaryList/SummaryList.test.js +54 -0
- package/dist/components/TaskList/Task.js +83 -0
- package/dist/components/TaskList/Task.test.js +112 -0
- package/dist/components/TaskList/TaskList.js +112 -0
- package/dist/components/TaskList/TaskList.scss +70 -0
- package/dist/components/TaskList/TaskList.stories.mdx +57 -0
- package/dist/components/TaskList/TaskList.test.js +223 -0
- package/dist/components/TaskList/TaskState.js +42 -0
- package/dist/components/TaskList/TaskState.test.js +99 -0
- package/dist/components/TaskList/index.js +13 -0
- package/dist/hooks/useHooks.js +5 -1
- package/dist/index.js +8 -0
- package/dist/json/taskList.json +228 -0
- package/dist/json/userProfile.data.json +2 -1
- package/dist/models/ComponentTypes.js +3 -1
- package/dist/models/FormTypes.js +2 -0
- package/dist/models/HubFormats.js +3 -1
- package/dist/models/PageAction.js +5 -0
- package/dist/models/TaskStates.js +41 -0
- package/dist/models/index.js +8 -0
- package/dist/utils/Component/cleanAttributes.js +1 -1
- package/dist/utils/Component/getComponent.js +26 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/FormPage/getPageActions.js +6 -0
- package/dist/utils/Hub/getFormHub.js +4 -0
- package/dist/utils/Hub/getFormHub.test.js +10 -2
- package/dist/utils/Validate/additional/index.js +55 -0
- package/dist/utils/Validate/additional/index.test.js +69 -0
- package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
- package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
- package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
- package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
- package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
- package/dist/utils/Validate/additional/utils.js +66 -0
- package/dist/utils/Validate/validateComponent.js +38 -1
- package/dist/utils/Validate/validateComponent.test.js +48 -2
- package/dist/utils/Validate/validateDate.js +144 -0
- package/dist/utils/Validate/validateDate.test.js +112 -0
- package/dist/utils/Validate/validateRequired.js +11 -0
- package/dist/utils/Validate/validateRequired.test.js +12 -0
- package/dist/utils/Validate/validateTime.js +76 -0
- package/dist/utils/Validate/validateTime.test.js +55 -0
- package/package.json +3 -2
|
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var HUB_FORMAT_CYA = 'CYA';
|
|
8
|
+
var HUB_FORMAT_TASK = 'TASK';
|
|
8
9
|
var HubFormats = {
|
|
9
|
-
CYA: HUB_FORMAT_CYA
|
|
10
|
+
CYA: HUB_FORMAT_CYA,
|
|
11
|
+
TASK: HUB_FORMAT_TASK
|
|
10
12
|
};
|
|
11
13
|
var _default = HubFormats;
|
|
12
14
|
exports.default = _default;
|
|
@@ -11,11 +11,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
11
11
|
|
|
12
12
|
var TYPE_NAVIGATE = 'navigate';
|
|
13
13
|
var TYPE_SAVE_AND_CONTINUE = 'saveAndContinue';
|
|
14
|
+
var TYPE_SAVE_AND_NAVIGATE = 'saveAndNavigate';
|
|
14
15
|
var TYPE_SAVE_AND_RETURN = 'saveAndReturn';
|
|
15
16
|
var TYPE_SUBMIT = 'submit';
|
|
16
17
|
var PageActionTypes = {
|
|
17
18
|
NAVIGATE: TYPE_NAVIGATE,
|
|
18
19
|
SAVE_AND_CONTINUE: TYPE_SAVE_AND_CONTINUE,
|
|
20
|
+
SAVE_AND_NAVIGATE: TYPE_SAVE_AND_NAVIGATE,
|
|
19
21
|
SAVE_AND_RETURN: TYPE_SAVE_AND_RETURN,
|
|
20
22
|
SUBMIT: TYPE_SUBMIT
|
|
21
23
|
};
|
|
@@ -24,6 +26,9 @@ var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPage
|
|
|
24
26
|
type: TYPE_SAVE_AND_CONTINUE,
|
|
25
27
|
validate: true,
|
|
26
28
|
label: 'Save and continue'
|
|
29
|
+
}), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_NAVIGATE, {
|
|
30
|
+
type: TYPE_SAVE_AND_NAVIGATE,
|
|
31
|
+
validate: true
|
|
27
32
|
}), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_RETURN, {
|
|
28
33
|
type: TYPE_SAVE_AND_RETURN,
|
|
29
34
|
validate: false,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.StateTypes = void 0;
|
|
7
|
+
|
|
8
|
+
var _StateDetails;
|
|
9
|
+
|
|
10
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
|
|
12
|
+
var TYPE_COMPLETE = 'complete';
|
|
13
|
+
var TYPE_IN_PROGRESS = 'inProgress';
|
|
14
|
+
var TYPE_NOT_STARTED = 'notStarted';
|
|
15
|
+
var TYPE_CANNOT_START_YET = 'cannotStartYet';
|
|
16
|
+
var StateTypes = {
|
|
17
|
+
COMPLETE: TYPE_COMPLETE,
|
|
18
|
+
IN_PROGRESS: TYPE_IN_PROGRESS,
|
|
19
|
+
NOT_STARTED: TYPE_NOT_STARTED,
|
|
20
|
+
CANNOT_START_YET: TYPE_CANNOT_START_YET
|
|
21
|
+
};
|
|
22
|
+
exports.StateTypes = StateTypes;
|
|
23
|
+
var StateDetails = (_StateDetails = {}, _defineProperty(_StateDetails, TYPE_COMPLETE, {
|
|
24
|
+
label: 'Completed',
|
|
25
|
+
colour: ''
|
|
26
|
+
}), _defineProperty(_StateDetails, TYPE_IN_PROGRESS, {
|
|
27
|
+
label: 'In Progress',
|
|
28
|
+
colour: 'blue'
|
|
29
|
+
}), _defineProperty(_StateDetails, TYPE_NOT_STARTED, {
|
|
30
|
+
label: 'Not Started',
|
|
31
|
+
colour: 'grey'
|
|
32
|
+
}), _defineProperty(_StateDetails, TYPE_CANNOT_START_YET, {
|
|
33
|
+
label: 'Cannot Start Yet',
|
|
34
|
+
colour: 'grey'
|
|
35
|
+
}), _StateDetails);
|
|
36
|
+
var TaskStates = {
|
|
37
|
+
TYPES: StateTypes,
|
|
38
|
+
DETAILS: StateDetails
|
|
39
|
+
};
|
|
40
|
+
var _default = TaskStates;
|
|
41
|
+
exports.default = _default;
|
package/dist/models/index.js
CHANGED
|
@@ -39,6 +39,12 @@ Object.defineProperty(exports, "PageAction", {
|
|
|
39
39
|
return _PageAction.default;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "TaskStates", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _TaskStates.default;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
42
48
|
|
|
43
49
|
var _ComponentTypes = _interopRequireDefault(require("./ComponentTypes"));
|
|
44
50
|
|
|
@@ -52,4 +58,6 @@ var _HubFormats = _interopRequireDefault(require("./HubFormats"));
|
|
|
52
58
|
|
|
53
59
|
var _PageAction = _interopRequireDefault(require("./PageAction"));
|
|
54
60
|
|
|
61
|
+
var _TaskStates = _interopRequireDefault(require("./TaskStates"));
|
|
62
|
+
|
|
55
63
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -19,7 +19,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
19
19
|
|
|
20
20
|
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; }
|
|
21
21
|
|
|
22
|
-
var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options'];
|
|
22
|
+
var JSON_ONLY_PROPERTIES = ['source', 'use', 'show_when', 'options', 'additionalValidation'];
|
|
23
23
|
/**
|
|
24
24
|
* This method removes and properties that are entirely specific to the JSON
|
|
25
25
|
* configuration and that should not be used as HTML attributes.
|
|
@@ -95,6 +95,11 @@ var getTextInput = function getTextInput(config) {
|
|
|
95
95
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextInput, attrs);
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
+
var getTime = function getTime(config) {
|
|
99
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
100
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TimeInput, attrs);
|
|
101
|
+
};
|
|
102
|
+
|
|
98
103
|
var getComponentByType = function getComponentByType(config) {
|
|
99
104
|
switch (config.type) {
|
|
100
105
|
case _models.ComponentTypes.HTML:
|
|
@@ -123,6 +128,9 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
123
128
|
case _models.ComponentTypes.DATE:
|
|
124
129
|
return getDate(config);
|
|
125
130
|
|
|
131
|
+
case _models.ComponentTypes.TIME:
|
|
132
|
+
return getTime(config);
|
|
133
|
+
|
|
126
134
|
case _models.ComponentTypes.CHECKBOXES:
|
|
127
135
|
return getCheckboxes(config);
|
|
128
136
|
|
|
@@ -132,9 +140,27 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* Get a renderable component, based on a configuration object.
|
|
145
|
+
* @param {object} config The configuration object for the component.
|
|
146
|
+
* @param {boolean} wrap Indicates whether or not the component should be wrapped.
|
|
147
|
+
* @param {Function} fnOverride An optional override function for component rendering.
|
|
148
|
+
* @returns A renderable component.
|
|
149
|
+
*/
|
|
150
|
+
|
|
135
151
|
|
|
136
152
|
var getComponent = function getComponent(config) {
|
|
137
153
|
var wrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
154
|
+
var fnOverride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
155
|
+
|
|
156
|
+
if (typeof fnOverride === 'function') {
|
|
157
|
+
var overrideComponent = fnOverride(config, wrap);
|
|
158
|
+
|
|
159
|
+
if (overrideComponent) {
|
|
160
|
+
return overrideComponent;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
138
164
|
var component = getComponentByType(config);
|
|
139
165
|
|
|
140
166
|
if (component && wrap && (0, _isEditable.default)(config)) {
|
|
@@ -8,7 +8,7 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
|
|
10
10
|
// Local imports
|
|
11
|
-
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA];
|
|
11
|
+
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
12
12
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
13
13
|
|
|
14
14
|
var isEditable = function isEditable(options) {
|
|
@@ -50,6 +50,12 @@ var getPageActions = function getPageActions(page) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (a && _typeof(a) === 'object') {
|
|
53
|
+
var _PageAction$DEFAULTS$;
|
|
54
|
+
|
|
55
|
+
if ((_PageAction$DEFAULTS$ = _models.PageAction.DEFAULTS[a.type]) !== null && _PageAction$DEFAULTS$ !== void 0 && _PageAction$DEFAULTS$.validate) {
|
|
56
|
+
a.validate = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
return standardiseAction(a);
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -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: [
|
|
66
|
+
components: ['Opening paragraph', {
|
|
67
67
|
type: 'heading',
|
|
68
68
|
size: 'l',
|
|
69
69
|
content: 'Hub heading'
|
|
70
|
-
},
|
|
70
|
+
}, 'Closing paragraph', {
|
|
71
71
|
use: 'a'
|
|
72
72
|
}]
|
|
73
73
|
};
|
|
@@ -91,6 +91,14 @@ describe('utils', function () {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
describe("when the FormType is \"".concat(_models.FormTypes.TASK, "\""), function () {
|
|
95
|
+
it("should return the string \"".concat(_models.HubFormats.TASK, "\" when the format is set to \"").concat(_models.HubFormats.TASK, "\""), function () {
|
|
96
|
+
var HUB = {
|
|
97
|
+
format: _models.HubFormats.TASK
|
|
98
|
+
};
|
|
99
|
+
expect((0, _getFormHub.default)(_models.FormTypes.TASK, HUB, FORM_COMPONENTS, FORM_DATA)).toEqual(_models.HubFormats.TASK);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
94
102
|
});
|
|
95
103
|
});
|
|
96
104
|
});
|
|
@@ -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
|
+
});
|