@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.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.js +18 -7
- package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
- package/dist/components/CollectionPage/CollectionPage.js +15 -10
- package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
- package/dist/components/FormComponent/Collection.js +91 -48
- package/dist/components/FormComponent/Collection.scss +2 -1
- package/dist/components/FormComponent/Collection.test.js +807 -0
- package/dist/components/FormComponent/Container.js +35 -16
- package/dist/components/FormComponent/Container.test.js +370 -0
- package/dist/components/FormComponent/FormComponent.js +39 -13
- package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
- package/dist/components/FormComponent/FormComponent.test.js +226 -0
- package/dist/components/FormComponent/helpers/addLabel.js +5 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
- package/dist/components/FormComponent/helpers/index.js +8 -1
- package/dist/components/FormPage/FormPage.js +69 -30
- package/dist/components/FormPage/FormPage.stories.mdx +155 -0
- package/dist/components/FormPage/FormPage.test.js +330 -0
- package/dist/components/FormRenderer/FormRenderer.js +142 -228
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
- package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
- package/dist/components/FormRenderer/handlers/index.js +1 -2
- package/dist/components/FormRenderer/handlers/navigate.js +3 -1
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
- package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
- package/dist/components/FormRenderer/helpers/index.js +1 -2
- package/dist/components/FormRenderer/onCYAAction.js +108 -0
- package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
- package/dist/components/FormRenderer/onPageAction.js +145 -0
- package/dist/components/FormRenderer/onPageAction.test.js +678 -0
- package/dist/components/FormRenderer/onTaskAction.js +48 -0
- package/dist/components/FormRenderer/onTaskAction.test.js +217 -0
- package/dist/components/PageActions/ActionButton.js +0 -3
- package/dist/components/PageActions/ActionButton.test.js +93 -0
- package/dist/components/PageActions/PageActions.js +2 -2
- package/dist/components/PageActions/PageActions.stories.mdx +74 -0
- package/dist/components/PageActions/PageActions.test.js +132 -0
- package/dist/components/SummaryList/GroupAction.js +2 -2
- package/dist/components/SummaryList/GroupAction.test.js +80 -0
- package/dist/components/SummaryList/RowAction.js +2 -2
- package/dist/components/SummaryList/RowAction.test.js +80 -0
- package/dist/components/SummaryList/SummaryList.js +29 -12
- package/dist/components/SummaryList/SummaryList.scss +19 -0
- package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
- package/dist/components/SummaryList/SummaryList.test.js +400 -0
- package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
- package/dist/components/SummaryList/SummaryListRow.js +5 -2
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
- package/dist/components/TaskList/Task.js +3 -3
- package/dist/components/TaskList/Task.test.js +167 -0
- package/dist/components/TaskList/TaskList.js +73 -22
- package/dist/components/TaskList/TaskList.stories.mdx +164 -0
- package/dist/components/TaskList/TaskList.test.js +389 -0
- package/dist/components/TaskList/TaskState.js +2 -2
- package/dist/components/TaskList/TaskState.test.js +86 -0
- package/dist/components/index.js +14 -0
- package/dist/context/HooksContext/HooksContext.js +72 -8
- package/dist/context/HooksContext/HooksContext.test.js +44 -0
- package/dist/context/ValidationContext/ValidationContext.js +38 -28
- package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
- package/dist/hooks/useAxios.js +10 -12
- package/dist/hooks/useGetRequest.js +48 -49
- package/dist/hooks/useRefData.js +7 -4
- package/dist/index.js +34 -1
- package/dist/json/addressDetails.json +149 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/group.data.json +21 -0
- package/dist/json/group.json +402 -0
- package/dist/json/groupOfRow.json +137 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/json/port.json +346 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/taskList.json +265 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/terminal.json +81 -0
- package/dist/json/userProfile.data.json +21 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +8 -0
- package/dist/models/PageAction.js +4 -1
- package/dist/models/TaskStates.js +10 -2
- package/dist/models/index.js +16 -1
- package/dist/setupTests.js +46 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
- package/dist/utils/Component/addShowWhen.js +44 -0
- package/dist/utils/Component/addShowWhen.test.js +216 -0
- package/dist/utils/Component/applyToComponentTree.js +71 -0
- package/dist/utils/Component/applyToComponentTree.test.js +127 -0
- package/dist/utils/Component/cleanAttributes.js +8 -2
- package/dist/utils/Component/cleanAttributes.test.js +68 -0
- package/dist/utils/Component/elevateNestedComponents.js +4 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
- package/dist/utils/Component/getComponent.js +80 -11
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
- package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
- package/dist/utils/Component/getDefaultValue.js +4 -1
- package/dist/utils/Component/getDefaultValue.test.js +50 -0
- package/dist/utils/Component/index.js +2 -0
- package/dist/utils/Component/isEditable.js +2 -2
- package/dist/utils/Component/isEditable.test.js +43 -0
- package/dist/utils/Component/optionIsSelected.js +22 -0
- package/dist/utils/Component/optionIsSelected.test.js +42 -0
- package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
- package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
- package/dist/utils/Component/showComponent.test.js +156 -0
- package/dist/utils/Component/wrapInFormGroup.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
- package/dist/utils/Condition/meetsCondition.js +74 -4
- package/dist/utils/Condition/meetsCondition.test.js +763 -0
- package/dist/utils/Condition/meetsOneCondition.js +1 -1
- package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
- package/dist/utils/Condition/setupConditions.js +6 -3
- package/dist/utils/Condition/setupConditions.test.js +33 -0
- package/dist/utils/Container/getEditableComponents.test.js +135 -0
- package/dist/utils/Container/setupNesting.js +21 -2
- package/dist/utils/Container/setupNesting.test.js +145 -0
- package/dist/utils/Container/showContainer.test.js +178 -0
- package/dist/utils/Data/applyFormula.js +20 -11
- package/dist/utils/Data/applyFormula.test.js +263 -0
- package/dist/utils/Data/getAutocompleteSource.js +6 -2
- package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
- package/dist/utils/Data/getDataPath.test.js +48 -0
- package/dist/utils/Data/getOptions.js +17 -3
- package/dist/utils/Data/getOptions.test.js +140 -0
- package/dist/utils/Data/getSourceData.js +2 -2
- package/dist/utils/Data/getSourceData.test.js +153 -0
- package/dist/utils/Data/refDataToOptions.js +4 -1
- package/dist/utils/Data/refDataToOptions.test.js +196 -0
- package/dist/utils/Data/setDataItem.test.js +110 -0
- package/dist/utils/Data/setupFormData.js +39 -16
- package/dist/utils/Data/setupFormData.test.js +410 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
- package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
- package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
- package/dist/utils/FormPage/getFormPage.js +5 -2
- package/dist/utils/FormPage/getFormPage.test.js +206 -0
- package/dist/utils/FormPage/getFormPages.js +4 -1
- package/dist/utils/FormPage/getFormPages.test.js +97 -0
- package/dist/utils/FormPage/getPageActions.js +8 -4
- package/dist/utils/FormPage/getPageActions.test.js +114 -0
- package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
- package/dist/utils/FormPage/index.js +2 -0
- package/dist/utils/FormPage/showFormPage.js +2 -2
- package/dist/utils/FormPage/showFormPage.test.js +180 -0
- package/dist/utils/FormPage/showFormPageCYA.js +1 -0
- package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
- package/dist/utils/FormPage/useComponent.js +29 -14
- package/dist/utils/FormPage/useComponent.test.js +167 -0
- package/dist/utils/Format/formatData.test.js +45 -0
- package/dist/utils/Format/formatDataForComponent.js +2 -1
- package/dist/utils/Format/formatDataForComponent.test.js +142 -0
- package/dist/utils/Format/formatDataForForm.js +4 -1
- package/dist/utils/Format/formatDataForForm.test.js +81 -0
- package/dist/utils/Format/formatDataForPage.test.js +99 -0
- package/dist/utils/Hub/getFormHub.test.js +105 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
- package/dist/utils/Meta/documents/index.js +2 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
- package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
- package/dist/utils/Operate/getFirstOf.js +31 -0
- package/dist/utils/Operate/getFirstOf.test.js +86 -0
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
- package/dist/utils/Operate/persistValueInFormData.js +2 -1
- package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
- package/dist/utils/Operate/runPageOperations.js +3 -1
- package/dist/utils/Operate/runPageOperations.test.js +105 -0
- package/dist/utils/Operate/setValueInFormData.test.js +44 -0
- package/dist/utils/Operate/shouldRun.js +16 -13
- package/dist/utils/Operate/shouldRun.test.js +66 -0
- package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
- package/dist/utils/Validate/additional/index.js +13 -4
- package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
- package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
- package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
- package/dist/utils/Validate/additional/utils.js +18 -18
- package/dist/utils/Validate/index.js +6 -0
- package/dist/utils/Validate/validateCollection.js +20 -5
- package/dist/utils/Validate/validateCollection.test.js +125 -0
- package/dist/utils/Validate/validateComponent.js +36 -20
- package/dist/utils/Validate/validateComponent.test.js +365 -0
- package/dist/utils/Validate/validateContainer.js +9 -3
- package/dist/utils/Validate/validateContainer.test.js +75 -0
- package/dist/utils/Validate/validateDate.js +4 -3
- package/dist/utils/Validate/validateDate.test.js +114 -0
- package/dist/utils/Validate/validateEmail.js +14 -1
- package/dist/utils/Validate/validateEmail.test.js +74 -0
- package/dist/utils/Validate/validateMultifile.js +32 -0
- package/dist/utils/Validate/validateMultifile.test.js +47 -0
- package/dist/utils/Validate/validatePage.js +12 -6
- package/dist/utils/Validate/validatePage.test.js +472 -0
- package/dist/utils/Validate/validateRegex.js +2 -5
- package/dist/utils/Validate/validateRegex.test.js +42 -0
- package/dist/utils/Validate/validateRequired.js +2 -4
- package/dist/utils/Validate/validateRequired.test.js +63 -0
- package/dist/utils/Validate/validateTextArea.js +37 -0
- package/dist/utils/Validate/validateTextArea.test.js +42 -0
- package/dist/utils/Validate/validateTime.js +2 -2
- package/dist/utils/Validate/validateTime.test.js +59 -0
- package/dist/utils/index.js +4 -1
- package/package.json +35 -50
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _models = require("../../../models");
|
|
5
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
describe('utils.Component.get', function () {
|
|
14
|
+
it('should return an appropriately rendered textarea component', function () {
|
|
15
|
+
var ID = 'test-id';
|
|
16
|
+
var FIELD_ID = 'field-id';
|
|
17
|
+
var LABEL = 'label';
|
|
18
|
+
var ROWS = 13;
|
|
19
|
+
var ON_CHANGE_CALLS = [];
|
|
20
|
+
var ON_CHANGE = function ON_CHANGE(e) {
|
|
21
|
+
ON_CHANGE_CALLS.push(e.target);
|
|
22
|
+
};
|
|
23
|
+
var COMPONENT = {
|
|
24
|
+
type: _models.ComponentTypes.TEXT_AREA,
|
|
25
|
+
id: ID,
|
|
26
|
+
fieldId: FIELD_ID,
|
|
27
|
+
label: LABEL,
|
|
28
|
+
rows: ROWS,
|
|
29
|
+
onChange: ON_CHANGE,
|
|
30
|
+
'data-testid': ID
|
|
31
|
+
};
|
|
32
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
33
|
+
container = _render.container;
|
|
34
|
+
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
35
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
|
|
36
|
+
formGroup = _getAllByTestId2[0],
|
|
37
|
+
textarea = _getAllByTestId2[1];
|
|
38
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
39
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
40
|
+
var label = formGroup.childNodes[0];
|
|
41
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
42
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
43
|
+
expect(textarea.tagName).toEqual('TEXTAREA');
|
|
44
|
+
expect(textarea.classList).toContain('govuk-textarea');
|
|
45
|
+
expect(textarea.getAttribute('rows')).toEqual("".concat(ROWS));
|
|
46
|
+
expect(textarea.id).toEqual(ID);
|
|
47
|
+
_react.fireEvent.change(textarea, {
|
|
48
|
+
target: {
|
|
49
|
+
name: FIELD_ID,
|
|
50
|
+
value: 'Some text'
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
54
|
+
expect(ON_CHANGE_CALLS[0]).toMatchObject({
|
|
55
|
+
name: FIELD_ID,
|
|
56
|
+
value: 'Some text'
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it('should return an appropriately rendered textarea component with a character count', function () {
|
|
60
|
+
var ID = 'test-id';
|
|
61
|
+
var FIELD_ID = 'field-id';
|
|
62
|
+
var LABEL = 'label';
|
|
63
|
+
var ROWS = 13;
|
|
64
|
+
var ON_CHANGE_CALLS = [];
|
|
65
|
+
var ON_CHANGE = function ON_CHANGE(e) {
|
|
66
|
+
ON_CHANGE_CALLS.push(e.target);
|
|
67
|
+
};
|
|
68
|
+
var COMPONENT = {
|
|
69
|
+
type: _models.ComponentTypes.TEXT_AREA,
|
|
70
|
+
id: ID,
|
|
71
|
+
fieldId: FIELD_ID,
|
|
72
|
+
label: LABEL,
|
|
73
|
+
rows: ROWS,
|
|
74
|
+
onChange: ON_CHANGE,
|
|
75
|
+
'data-testid': ID,
|
|
76
|
+
showCharacterCount: true
|
|
77
|
+
};
|
|
78
|
+
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
79
|
+
container = _render2.container;
|
|
80
|
+
var _getAllByTestId3 = (0, _react.getAllByTestId)(container, ID),
|
|
81
|
+
_getAllByTestId4 = _slicedToArray(_getAllByTestId3, 2),
|
|
82
|
+
formGroup = _getAllByTestId4[0],
|
|
83
|
+
textarea = _getAllByTestId4[1];
|
|
84
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
85
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
86
|
+
var label = formGroup.childNodes[0];
|
|
87
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
88
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
89
|
+
expect(textarea.tagName).toEqual('TEXTAREA');
|
|
90
|
+
expect(textarea.classList).toContain('govuk-textarea');
|
|
91
|
+
expect(textarea.getAttribute('rows')).toEqual("".concat(ROWS));
|
|
92
|
+
expect(textarea.id).toEqual(ID);
|
|
93
|
+
_react.fireEvent.change(textarea, {
|
|
94
|
+
target: {
|
|
95
|
+
name: FIELD_ID,
|
|
96
|
+
value: 'Some text'
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
100
|
+
expect(ON_CHANGE_CALLS[0]).toMatchObject({
|
|
101
|
+
name: FIELD_ID,
|
|
102
|
+
value: 'Some text'
|
|
103
|
+
});
|
|
104
|
+
var characterCount = formGroup.childNodes[2];
|
|
105
|
+
expect(characterCount.tagName).toEqual('DIV');
|
|
106
|
+
expect(characterCount.classList).toContain('govuk-hint');
|
|
107
|
+
expect(characterCount.textContent).toEqual('You have 1000 characters remaining');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -7,8 +7,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
7
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
8
|
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."); }
|
|
9
9
|
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); }
|
|
10
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
11
|
-
function _iterableToArrayLimit(arr, i) { var _i =
|
|
10
|
+
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; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
13
|
describe('utils.Component.get', function () {
|
|
14
14
|
it('should return an appropriately rendered time component', function () {
|
|
@@ -61,11 +61,11 @@ describe('utils.Component.get', function () {
|
|
|
61
61
|
expect(part.item.tagName).toEqual('DIV');
|
|
62
62
|
expect(part.item.classList).toContain('govuk-date-input__item');
|
|
63
63
|
var _part$item$childNodes = _slicedToArray(part.item.childNodes, 2),
|
|
64
|
-
|
|
64
|
+
inputLabel = _part$item$childNodes[0],
|
|
65
65
|
input = _part$item$childNodes[1];
|
|
66
|
-
expect(
|
|
67
|
-
expect(
|
|
68
|
-
expect(
|
|
66
|
+
expect(inputLabel.tagName).toEqual('LABEL');
|
|
67
|
+
expect(inputLabel.classList).toContain('govuk-label');
|
|
68
|
+
expect(inputLabel.textContent).toEqual(part.label);
|
|
69
69
|
expect(input.tagName).toEqual('INPUT');
|
|
70
70
|
expect(input.id).toEqual("".concat(ID, "-").concat(part.id));
|
|
71
71
|
|
|
@@ -76,7 +76,7 @@ describe('utils.Component.get', function () {
|
|
|
76
76
|
value: part.value
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
-
onChangeCalls
|
|
79
|
+
onChangeCalls += 1;
|
|
80
80
|
expect(ON_CHANGE_CALLS.length).toEqual(onChangeCalls);
|
|
81
81
|
expect(ON_CHANGE_CALLS[onChangeCalls - 1]).toMatchObject({
|
|
82
82
|
name: FIELD_ID,
|
|
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _models = require("../../models");
|
|
8
8
|
var _DEFAULT_VALUES;
|
|
9
|
-
function
|
|
9
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
13
|
var DEFAULT_VALUES = (_DEFAULT_VALUES = {}, _defineProperty(_DEFAULT_VALUES, _models.ComponentTypes.COLLECTION, []), _defineProperty(_DEFAULT_VALUES, _models.ComponentTypes.CONTAINER, {}), _defineProperty(_DEFAULT_VALUES, _models.ComponentTypes.FILE, {}), _DEFAULT_VALUES);
|
|
11
14
|
var getDefaultValue = function getDefaultValue(component) {
|
|
12
15
|
if (component) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
var _getDefaultValue = _interopRequireDefault(require("./getDefaultValue"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
describe('utils.Component.defaultValue', function () {
|
|
7
|
+
it('should return an empty string if the component is undefined', function () {
|
|
8
|
+
expect((0, _getDefaultValue.default)(undefined)).toEqual('');
|
|
9
|
+
});
|
|
10
|
+
it('should return an empty string if the component is null', function () {
|
|
11
|
+
expect((0, _getDefaultValue.default)(null)).toEqual('');
|
|
12
|
+
});
|
|
13
|
+
it('should return an empty string if the component has no type', function () {
|
|
14
|
+
expect((0, _getDefaultValue.default)({})).toEqual('');
|
|
15
|
+
});
|
|
16
|
+
it('should return an empty string if the component type is null', function () {
|
|
17
|
+
expect((0, _getDefaultValue.default)({
|
|
18
|
+
type: null
|
|
19
|
+
})).toEqual('');
|
|
20
|
+
});
|
|
21
|
+
it('should return an empty string if the component type is undefined', function () {
|
|
22
|
+
expect((0, _getDefaultValue.default)({
|
|
23
|
+
type: undefined
|
|
24
|
+
})).toEqual('');
|
|
25
|
+
});
|
|
26
|
+
it("should return an empty array if the component type is 'collection'", function () {
|
|
27
|
+
expect((0, _getDefaultValue.default)({
|
|
28
|
+
type: _models.ComponentTypes.COLLECTION
|
|
29
|
+
})).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
it("should return an empty object if the component type is 'container'", function () {
|
|
32
|
+
expect((0, _getDefaultValue.default)({
|
|
33
|
+
type: _models.ComponentTypes.CONTAINER
|
|
34
|
+
})).toEqual({});
|
|
35
|
+
});
|
|
36
|
+
it("should return an empty object if the component type is 'file'", function () {
|
|
37
|
+
expect((0, _getDefaultValue.default)({
|
|
38
|
+
type: _models.ComponentTypes.FILE
|
|
39
|
+
})).toEqual({});
|
|
40
|
+
});
|
|
41
|
+
Object.values(_models.ComponentTypes).forEach(function (value) {
|
|
42
|
+
if (![_models.ComponentTypes.COLLECTION, _models.ComponentTypes.CONTAINER, _models.ComponentTypes.FILE].includes(value)) {
|
|
43
|
+
it("should return an empty object if the component type is '".concat(value, "'"), function () {
|
|
44
|
+
expect((0, _getDefaultValue.default)({
|
|
45
|
+
type: _models.ComponentTypes.TEXT
|
|
46
|
+
})).toEqual('');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -9,6 +9,7 @@ var _elevateNestedComponents = _interopRequireDefault(require("./elevateNestedCo
|
|
|
9
9
|
var _getComponent = _interopRequireDefault(require("./getComponent"));
|
|
10
10
|
var _getDefaultValue = _interopRequireDefault(require("./getDefaultValue"));
|
|
11
11
|
var _isEditable = _interopRequireDefault(require("./isEditable"));
|
|
12
|
+
var _setupContainerComponentsPath = _interopRequireDefault(require("./setupContainerComponentsPath"));
|
|
12
13
|
var _showComponent = _interopRequireDefault(require("./showComponent"));
|
|
13
14
|
var _wrapInFormGroup = _interopRequireDefault(require("./wrapInFormGroup"));
|
|
14
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -18,6 +19,7 @@ var Component = {
|
|
|
18
19
|
editable: _isEditable.default,
|
|
19
20
|
elevateNested: _elevateNestedComponents.default,
|
|
20
21
|
get: _getComponent.default,
|
|
22
|
+
setupContainerPaths: _setupContainerComponentsPath.default,
|
|
21
23
|
show: _showComponent.default,
|
|
22
24
|
wrap: _wrapInFormGroup.default
|
|
23
25
|
};
|
|
@@ -7,10 +7,10 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
7
7
|
var _models = require("../../models");
|
|
8
8
|
// Local imports
|
|
9
9
|
|
|
10
|
-
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
10
|
+
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
11
11
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
12
12
|
var isEditable = function isEditable(options) {
|
|
13
|
-
return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type);
|
|
13
|
+
return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type) || (options === null || options === void 0 ? void 0 : options.isEditable) || false;
|
|
14
14
|
};
|
|
15
15
|
var _default = isEditable;
|
|
16
16
|
exports.default = _default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
var _isEditable = _interopRequireWildcard(require("./isEditable"));
|
|
5
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
6
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
7
|
+
// Local imports
|
|
8
|
+
|
|
9
|
+
describe('utils', function () {
|
|
10
|
+
describe('Component', function () {
|
|
11
|
+
describe('isEditable', function () {
|
|
12
|
+
_isEditable.EDITABLE_TYPES.forEach(function (type) {
|
|
13
|
+
it("should return true for a type of '".concat(type, "'"), function () {
|
|
14
|
+
var OPTIONS = {
|
|
15
|
+
type: type
|
|
16
|
+
};
|
|
17
|
+
expect((0, _isEditable.default)(OPTIONS)).toEqual(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it('should return false if options is undefined', function () {
|
|
21
|
+
expect((0, _isEditable.default)(undefined)).toEqual(false);
|
|
22
|
+
});
|
|
23
|
+
it('should return false if options is null', function () {
|
|
24
|
+
expect((0, _isEditable.default)(null)).toEqual(false);
|
|
25
|
+
});
|
|
26
|
+
it('should return false if options has no type', function () {
|
|
27
|
+
expect((0, _isEditable.default)({
|
|
28
|
+
bob: 'Bob'
|
|
29
|
+
})).toEqual(false);
|
|
30
|
+
});
|
|
31
|
+
it("should return false if options has a type of 'hidden'", function () {
|
|
32
|
+
expect((0, _isEditable.default)({
|
|
33
|
+
type: 'hidden'
|
|
34
|
+
})).toEqual(false);
|
|
35
|
+
});
|
|
36
|
+
it("should return true if options has 'isEditable' set to true", function () {
|
|
37
|
+
expect((0, _isEditable.default)({
|
|
38
|
+
isEditable: true
|
|
39
|
+
})).toEqual(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Checks whether an option for a component has been selected.
|
|
9
|
+
*
|
|
10
|
+
* @param {object} componentValue The option's value selected for that component.
|
|
11
|
+
* @param {object} option The option of the component being tested.
|
|
12
|
+
*
|
|
13
|
+
* @returns A boolean of whether the option is selected.
|
|
14
|
+
*/
|
|
15
|
+
var optionIsSelected = function optionIsSelected(componentValue, option) {
|
|
16
|
+
if (Array.isArray(componentValue)) {
|
|
17
|
+
return componentValue.includes(option.value);
|
|
18
|
+
}
|
|
19
|
+
return componentValue === option.value;
|
|
20
|
+
};
|
|
21
|
+
var _default = optionIsSelected;
|
|
22
|
+
exports.default = _default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _optionIsSelected = _interopRequireDefault(require("./optionIsSelected"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils.Component.isSelected', function () {
|
|
8
|
+
var SELECTED_VALUE = 'selectedValue';
|
|
9
|
+
var NOT_SELECTED_VALUE = 'notSelectedValue';
|
|
10
|
+
var OPTIONS = [{
|
|
11
|
+
value: SELECTED_VALUE
|
|
12
|
+
}, {
|
|
13
|
+
value: NOT_SELECTED_VALUE
|
|
14
|
+
}];
|
|
15
|
+
var COMPONENT = {
|
|
16
|
+
id: 'a',
|
|
17
|
+
fieldId: 'a',
|
|
18
|
+
data: {
|
|
19
|
+
options: OPTIONS
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
it('should properly identify which option is selected for checkboxes', function () {
|
|
23
|
+
var PAGE = {
|
|
24
|
+
formData: {
|
|
25
|
+
a: [SELECTED_VALUE]
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
COMPONENT.type = 'checkboxes';
|
|
29
|
+
expect((0, _optionIsSelected.default)(PAGE.formData[COMPONENT.id], OPTIONS[0])).toEqual(true);
|
|
30
|
+
expect((0, _optionIsSelected.default)(PAGE.formData[COMPONENT.id], OPTIONS[1])).toEqual(false);
|
|
31
|
+
});
|
|
32
|
+
it('should properly identify which option is selected for radios', function () {
|
|
33
|
+
var PAGE = {
|
|
34
|
+
formData: {
|
|
35
|
+
a: SELECTED_VALUE
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
COMPONENT.type = 'radios';
|
|
39
|
+
expect((0, _optionIsSelected.default)(PAGE.formData[COMPONENT.id], OPTIONS[0])).toEqual(true);
|
|
40
|
+
expect((0, _optionIsSelected.default)(PAGE.formData[COMPONENT.id], OPTIONS[1])).toEqual(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _showComponentCYA = require("../CheckYourAnswers/showComponentCYA");
|
|
8
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
var setupContainerComponentsPath = function setupContainerComponentsPath(container) {
|
|
15
|
+
return _objectSpread(_objectSpread({}, container), {}, {
|
|
16
|
+
components: container.components.map(function (component) {
|
|
17
|
+
if (Array.isArray(component.components)) {
|
|
18
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
19
|
+
components: component.components.map(function (c) {
|
|
20
|
+
if (!_showComponentCYA.EXCLUDE_FROM_CYA.includes(c.type)) {
|
|
21
|
+
return _objectSpread(_objectSpread({}, c), !c.full_path && {
|
|
22
|
+
full_path: "".concat(component.full_path || "".concat(container.full_path, ".").concat(component.fieldId), ".").concat(c.fieldId)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
return null;
|
|
27
|
+
}).filter(function (c) {
|
|
28
|
+
return !!c;
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
;
|
|
33
|
+
return _objectSpread(_objectSpread({}, component), !component.full_path && {
|
|
34
|
+
full_path: "".concat(container.full_path || container.fieldId, ".").concat(component.fieldId)
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var _default = setupContainerComponentsPath;
|
|
40
|
+
exports.default = _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _setupTests = require("../../setupTests");
|
|
4
|
+
var _setupContainerComponentsPath = _interopRequireDefault(require("./setupContainerComponentsPath"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
describe('utils.CheckYourAnswers.setupContainerComponentsPath', function () {
|
|
7
|
+
it('should setup the full_path attribute for components within a container', function () {
|
|
8
|
+
var COMPONENT_1 = {
|
|
9
|
+
id: 'checkboxes1',
|
|
10
|
+
fieldId: 'checkboxes1',
|
|
11
|
+
type: 'checkboxes',
|
|
12
|
+
label: 'Alpha'
|
|
13
|
+
};
|
|
14
|
+
var COMPONENT_2 = {
|
|
15
|
+
id: 'checkboxes2',
|
|
16
|
+
fieldId: 'checkboxes2',
|
|
17
|
+
type: 'checkboxes',
|
|
18
|
+
label: 'Bravo'
|
|
19
|
+
};
|
|
20
|
+
var CONTAINER = {
|
|
21
|
+
id: 'test-container',
|
|
22
|
+
fieldId: 'test-container',
|
|
23
|
+
type: 'container',
|
|
24
|
+
full_path: 'test-container',
|
|
25
|
+
components: [COMPONENT_1, COMPONENT_2]
|
|
26
|
+
};
|
|
27
|
+
var container = (0, _setupContainerComponentsPath.default)(CONTAINER);
|
|
28
|
+
(0, _setupTests.expectObjectLike)(container.components[0], {
|
|
29
|
+
id: COMPONENT_1.id,
|
|
30
|
+
fieldId: COMPONENT_1.fieldId,
|
|
31
|
+
full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_1.fieldId),
|
|
32
|
+
type: COMPONENT_1.type,
|
|
33
|
+
label: COMPONENT_1.label
|
|
34
|
+
});
|
|
35
|
+
(0, _setupTests.expectObjectLike)(container.components[1], {
|
|
36
|
+
id: COMPONENT_2.id,
|
|
37
|
+
fieldId: COMPONENT_2.fieldId,
|
|
38
|
+
full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_2.fieldId),
|
|
39
|
+
type: COMPONENT_2.type,
|
|
40
|
+
label: COMPONENT_2.label
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('should setup the full_path attribute for components when the container full_path property is missing', function () {
|
|
44
|
+
var COMPONENT_1 = {
|
|
45
|
+
id: 'checkboxes1',
|
|
46
|
+
fieldId: 'checkboxes1',
|
|
47
|
+
type: 'checkboxes',
|
|
48
|
+
label: 'Alpha'
|
|
49
|
+
};
|
|
50
|
+
var COMPONENT_2 = {
|
|
51
|
+
id: 'checkboxes2',
|
|
52
|
+
fieldId: 'checkboxes2',
|
|
53
|
+
type: 'checkboxes',
|
|
54
|
+
label: 'Bravo'
|
|
55
|
+
};
|
|
56
|
+
var CONTAINER = {
|
|
57
|
+
id: 'test-container',
|
|
58
|
+
fieldId: 'test-container',
|
|
59
|
+
type: 'container',
|
|
60
|
+
components: [COMPONENT_1, COMPONENT_2]
|
|
61
|
+
};
|
|
62
|
+
var container = (0, _setupContainerComponentsPath.default)(CONTAINER);
|
|
63
|
+
(0, _setupTests.expectObjectLike)(container.components[0], {
|
|
64
|
+
id: COMPONENT_1.id,
|
|
65
|
+
fieldId: COMPONENT_1.fieldId,
|
|
66
|
+
full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_1.fieldId),
|
|
67
|
+
type: COMPONENT_1.type,
|
|
68
|
+
label: COMPONENT_1.label
|
|
69
|
+
});
|
|
70
|
+
(0, _setupTests.expectObjectLike)(container.components[1], {
|
|
71
|
+
id: COMPONENT_2.id,
|
|
72
|
+
fieldId: COMPONENT_2.fieldId,
|
|
73
|
+
full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_2.fieldId),
|
|
74
|
+
type: COMPONENT_2.type,
|
|
75
|
+
label: COMPONENT_2.label
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _showComponent = _interopRequireDefault(require("./showComponent"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
// Local imports
|
|
6
|
+
|
|
7
|
+
describe('utils', function () {
|
|
8
|
+
describe('Component', function () {
|
|
9
|
+
describe('show', function () {
|
|
10
|
+
it('should not show when there are no options', function () {
|
|
11
|
+
expect((0, _showComponent.default)(null, null)).toBeFalsy();
|
|
12
|
+
});
|
|
13
|
+
it('should not show when hidden and disabled', function () {
|
|
14
|
+
expect((0, _showComponent.default)({
|
|
15
|
+
hidden: true,
|
|
16
|
+
disabled: true
|
|
17
|
+
}, null)).toBeFalsy();
|
|
18
|
+
});
|
|
19
|
+
it('should show when hidden but not disabled', function () {
|
|
20
|
+
expect((0, _showComponent.default)({
|
|
21
|
+
hidden: true
|
|
22
|
+
}, null)).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
it('should show when disabled but not hidden', function () {
|
|
25
|
+
expect((0, _showComponent.default)({
|
|
26
|
+
disabled: true
|
|
27
|
+
}, null)).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
it('should show when a single show_when condition is met', function () {
|
|
30
|
+
var COMPONENT = {
|
|
31
|
+
show_when: {
|
|
32
|
+
field: 'alpha',
|
|
33
|
+
op: 'eq',
|
|
34
|
+
value: 'bravo'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var DATA = {
|
|
38
|
+
alpha: 'bravo'
|
|
39
|
+
};
|
|
40
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
it('should not show when a single show_when condition is not met', function () {
|
|
43
|
+
var COMPONENT = {
|
|
44
|
+
show_when: {
|
|
45
|
+
field: 'alpha',
|
|
46
|
+
op: 'eq',
|
|
47
|
+
value: 'bravo'
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var DATA = {
|
|
51
|
+
alpha: 'charlie'
|
|
52
|
+
};
|
|
53
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeFalsy();
|
|
54
|
+
});
|
|
55
|
+
it('should show when multiple show_when conditions are met', function () {
|
|
56
|
+
var COMPONENT = {
|
|
57
|
+
show_when: [{
|
|
58
|
+
field: 'alpha',
|
|
59
|
+
op: 'eq',
|
|
60
|
+
value: 'bravo'
|
|
61
|
+
}, {
|
|
62
|
+
field: 'charlie',
|
|
63
|
+
op: 'eq',
|
|
64
|
+
value: 'delta'
|
|
65
|
+
}]
|
|
66
|
+
};
|
|
67
|
+
var DATA = {
|
|
68
|
+
alpha: 'bravo',
|
|
69
|
+
charlie: 'delta'
|
|
70
|
+
};
|
|
71
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
it('should not show when one of multiple show_when conditions is not met', function () {
|
|
74
|
+
var COMPONENT = {
|
|
75
|
+
show_when: [{
|
|
76
|
+
field: 'alpha',
|
|
77
|
+
op: 'eq',
|
|
78
|
+
value: 'bravo'
|
|
79
|
+
}, {
|
|
80
|
+
field: 'charlie',
|
|
81
|
+
op: 'eq',
|
|
82
|
+
value: 'delta'
|
|
83
|
+
}]
|
|
84
|
+
};
|
|
85
|
+
var DATA = {
|
|
86
|
+
alpha: 'bravo',
|
|
87
|
+
charlie: 'echo'
|
|
88
|
+
};
|
|
89
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeFalsy();
|
|
90
|
+
});
|
|
91
|
+
it('SHOULD be shown when the component has multiple show_when conditions, with type "or" provided and ALL are matched', function () {
|
|
92
|
+
var COMPONENT = {
|
|
93
|
+
show_when: {
|
|
94
|
+
"type": "or",
|
|
95
|
+
"conditions": [{
|
|
96
|
+
field: 'alpha',
|
|
97
|
+
op: '=',
|
|
98
|
+
value: 'Alpha'
|
|
99
|
+
}, {
|
|
100
|
+
field: 'bravo',
|
|
101
|
+
op: '=',
|
|
102
|
+
value: 'Bravo'
|
|
103
|
+
}]
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var DATA = {
|
|
107
|
+
alpha: 'Alpha',
|
|
108
|
+
bravo: 'Bravo'
|
|
109
|
+
};
|
|
110
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeTruthy();
|
|
111
|
+
});
|
|
112
|
+
it('SHOULD be shown when the component has multiple show_when conditions, with type "or" provided and at least ONE is matched', function () {
|
|
113
|
+
var COMPONENT = {
|
|
114
|
+
show_when: {
|
|
115
|
+
"type": "or",
|
|
116
|
+
"conditions": [{
|
|
117
|
+
field: 'alpha',
|
|
118
|
+
op: '=',
|
|
119
|
+
value: 'Alpha'
|
|
120
|
+
}, {
|
|
121
|
+
field: 'charlie',
|
|
122
|
+
op: '=',
|
|
123
|
+
value: 'Charlie'
|
|
124
|
+
}]
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var DATA = {
|
|
128
|
+
alpha: 'Alpha',
|
|
129
|
+
bravo: 'Bravo'
|
|
130
|
+
};
|
|
131
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeTruthy();
|
|
132
|
+
});
|
|
133
|
+
it('should NOT be shown when the component has multiple show_when conditions, with type "or" provided and NONE are matched', function () {
|
|
134
|
+
var COMPONENT = {
|
|
135
|
+
show_when: {
|
|
136
|
+
"type": "or",
|
|
137
|
+
"conditions": [{
|
|
138
|
+
field: 'alpha',
|
|
139
|
+
op: '!=',
|
|
140
|
+
value: 'Alpha'
|
|
141
|
+
}, {
|
|
142
|
+
field: 'charlie',
|
|
143
|
+
op: '=',
|
|
144
|
+
value: 'Charlie'
|
|
145
|
+
}]
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var DATA = {
|
|
149
|
+
alpha: 'Alpha',
|
|
150
|
+
bravo: 'Bravo'
|
|
151
|
+
};
|
|
152
|
+
expect((0, _showComponent.default)(COMPONENT, DATA)).toBeFalsy();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -10,7 +10,7 @@ var _cleanAttributes = _interopRequireDefault(require("./cleanAttributes"));
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
12
12
|
var wrapInFormGroup = function wrapInFormGroup(config, children) {
|
|
13
|
-
var attrs = (0, _cleanAttributes.default)(config, ['fieldId', 'displayMenu']);
|
|
13
|
+
var attrs = (0, _cleanAttributes.default)(config, ['fieldId', 'displayMenu', 'showCharacterCount', 'readonly']);
|
|
14
14
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.FormGroup, _extends({}, attrs, {
|
|
15
15
|
onChange: null
|
|
16
16
|
}), children);
|
|
@@ -22,7 +22,7 @@ var meetsAllConditions = function meetsAllConditions(options, data) {
|
|
|
22
22
|
var arr = Array.isArray(conditions) ? conditions : [conditions];
|
|
23
23
|
return arr.every(function (condition) {
|
|
24
24
|
var sourceDataValue = _Data.default.getSource(data, condition.field);
|
|
25
|
-
return (0, _meetsCondition.default)(condition, sourceDataValue);
|
|
25
|
+
return (0, _meetsCondition.default)(condition, sourceDataValue, data);
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
return true;
|