@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
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
4
|
var _models = require("../../../models");
|
|
5
|
+
var _setupTests = require("../../../setupTests");
|
|
5
6
|
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
6
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
9
|
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
10
|
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 =
|
|
11
|
+
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; }
|
|
12
|
+
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
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
14
|
describe('utils.Component.get', function () {
|
|
14
15
|
it('should return an appropriately rendered checkboxes component', function () {
|
|
@@ -45,7 +46,7 @@ describe('utils.Component.get', function () {
|
|
|
45
46
|
checkboxes = _getAllByTestId2[1];
|
|
46
47
|
expect(formGroup.tagName).toEqual('DIV');
|
|
47
48
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
48
|
-
var label
|
|
49
|
+
var label;
|
|
49
50
|
formGroup.childNodes.forEach(function (node) {
|
|
50
51
|
// Check if it's an element.
|
|
51
52
|
if (node instanceof Element) {
|
|
@@ -75,10 +76,10 @@ describe('utils.Component.get', function () {
|
|
|
75
76
|
expect(checkbox.classList).toContain('govuk-checkboxes__item');
|
|
76
77
|
var _checkbox$childNodes = _slicedToArray(checkbox.childNodes, 2),
|
|
77
78
|
input = _checkbox$childNodes[0],
|
|
78
|
-
|
|
79
|
+
inputLabel = _checkbox$childNodes[1];
|
|
79
80
|
expect(input.tagName).toEqual('INPUT');
|
|
80
81
|
expect(input.type).toEqual('checkbox');
|
|
81
|
-
expect(
|
|
82
|
+
expect(inputLabel.textContent).toEqual(option.label);
|
|
82
83
|
});
|
|
83
84
|
_react.fireEvent.click(checkboxItems[0].childNodes[0]); // alpha
|
|
84
85
|
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
@@ -99,4 +100,64 @@ describe('utils.Component.get', function () {
|
|
|
99
100
|
value: [OPTIONS[1].value]
|
|
100
101
|
});
|
|
101
102
|
});
|
|
103
|
+
it('should return an appropriately rendered checkboxes component with a nested component', function () {
|
|
104
|
+
var ID = 'test-id';
|
|
105
|
+
var FIELD_ID = 'field-id';
|
|
106
|
+
var LABEL = 'label';
|
|
107
|
+
var NESTED = {
|
|
108
|
+
id: 'charle',
|
|
109
|
+
fieldId: 'charle',
|
|
110
|
+
type: 'text'
|
|
111
|
+
};
|
|
112
|
+
var OPTIONS = [{
|
|
113
|
+
value: 'a',
|
|
114
|
+
label: 'Alpha',
|
|
115
|
+
nested: [NESTED]
|
|
116
|
+
}, {
|
|
117
|
+
value: 'b',
|
|
118
|
+
label: 'Bravo'
|
|
119
|
+
}];
|
|
120
|
+
var ON_CHANGE_CALLS = [];
|
|
121
|
+
var ON_CHANGE = function ON_CHANGE(e) {
|
|
122
|
+
ON_CHANGE_CALLS.push(e.target);
|
|
123
|
+
};
|
|
124
|
+
var COMPONENT = {
|
|
125
|
+
type: _models.ComponentTypes.CHECKBOXES,
|
|
126
|
+
id: ID,
|
|
127
|
+
fieldId: FIELD_ID,
|
|
128
|
+
label: LABEL,
|
|
129
|
+
data: {
|
|
130
|
+
options: OPTIONS
|
|
131
|
+
},
|
|
132
|
+
value: 'a',
|
|
133
|
+
onChange: ON_CHANGE,
|
|
134
|
+
'data-testid': ID
|
|
135
|
+
};
|
|
136
|
+
var _renderWithValidation = (0, _setupTests.renderWithValidation)((0, _getComponent.default)(COMPONENT)),
|
|
137
|
+
container = _renderWithValidation.container;
|
|
138
|
+
var _getAllByTestId3 = (0, _react.getAllByTestId)(container, ID),
|
|
139
|
+
_getAllByTestId4 = _slicedToArray(_getAllByTestId3, 2),
|
|
140
|
+
formGroup = _getAllByTestId4[0],
|
|
141
|
+
checkboxes = _getAllByTestId4[1];
|
|
142
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
143
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
144
|
+
var label;
|
|
145
|
+
formGroup.childNodes.forEach(function (node) {
|
|
146
|
+
// Check if it's an element.
|
|
147
|
+
if (node instanceof Element) {
|
|
148
|
+
if (node.tagName === 'LABEL') {
|
|
149
|
+
label = node;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
expect(label).toBeDefined();
|
|
154
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
155
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
156
|
+
expect(checkboxes.tagName).toEqual('DIV');
|
|
157
|
+
expect(checkboxes.classList).toContain('govuk-checkboxes');
|
|
158
|
+
expect(checkboxes.childNodes.length).toEqual(OPTIONS.length + 1); // +1 for nested component
|
|
159
|
+
expect(checkboxes.childNodes[0].classList).toContain('govuk-checkboxes__item');
|
|
160
|
+
expect(checkboxes.childNodes[1].classList).toContain('govuk-checkboxes__conditional');
|
|
161
|
+
expect(checkboxes.childNodes[2].classList).toContain('govuk-checkboxes__item');
|
|
162
|
+
});
|
|
102
163
|
});
|
|
@@ -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 date component', function () {
|
|
@@ -34,18 +34,20 @@ describe('utils.Component.get', function () {
|
|
|
34
34
|
type: _models.ComponentTypes.DETAILS,
|
|
35
35
|
content: CONTENT,
|
|
36
36
|
summary: SUMMARY,
|
|
37
|
+
tagName: 'div',
|
|
37
38
|
'data-testid': ID
|
|
38
39
|
};
|
|
39
40
|
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
40
41
|
container = _render2.container;
|
|
41
42
|
var details = container.querySelector('details');
|
|
42
43
|
expect(details.classList).toContain('hods-details');
|
|
43
|
-
|
|
44
|
-
expect(
|
|
45
|
-
expect(
|
|
46
|
-
expect(
|
|
47
|
-
expect(
|
|
48
|
-
expect(
|
|
49
|
-
expect(
|
|
44
|
+
var content = details.childNodes[1].childNodes[0].childNodes;
|
|
45
|
+
expect(content[0].textContent).toEqual('this is the content');
|
|
46
|
+
expect(content[0].tagName).toEqual('P');
|
|
47
|
+
expect(content[1].childNodes[0].textContent).toEqual('one');
|
|
48
|
+
expect(content[1].childNodes[1].textContent).toEqual('two');
|
|
49
|
+
expect(content[1].tagName).toEqual('OL');
|
|
50
|
+
expect(content[2].textContent).toEqual('second section of content');
|
|
51
|
+
expect(content[2].tagName).toEqual('P');
|
|
50
52
|
});
|
|
51
53
|
});
|
|
@@ -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 email component', function () {
|
|
@@ -35,7 +35,7 @@ describe('utils.Component.get', function () {
|
|
|
35
35
|
input = _getAllByTestId2[1];
|
|
36
36
|
expect(formGroup.tagName).toEqual('DIV');
|
|
37
37
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
38
|
-
var label
|
|
38
|
+
var label;
|
|
39
39
|
formGroup.childNodes.forEach(function (node) {
|
|
40
40
|
// Check if it's an element.
|
|
41
41
|
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
@@ -8,8 +8,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
8
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
9
|
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."); }
|
|
10
10
|
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); }
|
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
12
|
-
function _iterableToArrayLimit(arr, i) { var _i =
|
|
11
|
+
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; }
|
|
12
|
+
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; } }
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
14
|
describe('utils.Component.get', function () {
|
|
15
15
|
it('should return an appropriately rendered file component', function () {
|
|
@@ -36,7 +36,7 @@ describe('utils.Component.get', function () {
|
|
|
36
36
|
input = _getAllByTestId2[1];
|
|
37
37
|
expect(formGroup.tagName).toEqual('DIV');
|
|
38
38
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
39
|
-
var label
|
|
39
|
+
var label;
|
|
40
40
|
formGroup.childNodes.forEach(function (node) {
|
|
41
41
|
// Check if it's an element.
|
|
42
42
|
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
// Global imports
|
|
8
|
+
|
|
9
|
+
// Local imports
|
|
10
|
+
|
|
11
|
+
describe('utils.Component.get', function () {
|
|
12
|
+
it('should return a ul tag and correct className for an unordered list component', function () {
|
|
13
|
+
var ID = 'test-id';
|
|
14
|
+
var ITEMS = ['paragraph content1', 'paragraph content2'];
|
|
15
|
+
var COMPONENT = {
|
|
16
|
+
type: _models.ComponentTypes.LIST,
|
|
17
|
+
ordered: false,
|
|
18
|
+
items: ITEMS,
|
|
19
|
+
'data-testid': ID
|
|
20
|
+
};
|
|
21
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
22
|
+
container = _render.container;
|
|
23
|
+
var ul = (0, _react.getByTestId)(container, ID);
|
|
24
|
+
expect(ul.innerHTML).toContain('<li>paragraph content1</li><li>paragraph content2</li>');
|
|
25
|
+
expect(ul.tagName).toEqual('UL');
|
|
26
|
+
expect(ul.className).toEqual('govuk-list govuk-list--bullet');
|
|
27
|
+
});
|
|
28
|
+
it('should return a ol tag and correct className for an ordered list component', function () {
|
|
29
|
+
var ID = 'test-id';
|
|
30
|
+
var ITEMS = ['paragraph content1', 'paragraph content2'];
|
|
31
|
+
var COMPONENT = {
|
|
32
|
+
type: _models.ComponentTypes.LIST,
|
|
33
|
+
ordered: true,
|
|
34
|
+
items: ITEMS,
|
|
35
|
+
'data-testid': ID
|
|
36
|
+
};
|
|
37
|
+
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
38
|
+
container = _render2.container;
|
|
39
|
+
var ol = (0, _react.getByTestId)(container, ID);
|
|
40
|
+
expect(ol.innerHTML).toContain('<li>paragraph content1</li><li>paragraph content2</li>');
|
|
41
|
+
expect(ol.tagName).toEqual('OL');
|
|
42
|
+
expect(ol.className).toEqual('govuk-list govuk-list--number');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -7,53 +7,61 @@ 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
|
-
it('should return an appropriately rendered
|
|
14
|
+
it('should return an appropriately rendered multi file component', function () {
|
|
15
15
|
var ID = 'test-id';
|
|
16
16
|
var FIELD_ID = 'field-id';
|
|
17
17
|
var LABEL = 'label';
|
|
18
|
-
var ROWS = 13;
|
|
19
18
|
var ON_CHANGE_CALLS = [];
|
|
20
19
|
var ON_CHANGE = function ON_CHANGE(e) {
|
|
21
20
|
ON_CHANGE_CALLS.push(e.target);
|
|
22
21
|
};
|
|
23
22
|
var COMPONENT = {
|
|
24
|
-
type: _models.ComponentTypes.
|
|
23
|
+
type: _models.ComponentTypes.MULTI_FILE,
|
|
25
24
|
id: ID,
|
|
26
25
|
fieldId: FIELD_ID,
|
|
27
26
|
label: LABEL,
|
|
28
|
-
rows: ROWS,
|
|
29
27
|
onChange: ON_CHANGE,
|
|
30
28
|
'data-testid': ID
|
|
31
29
|
};
|
|
32
30
|
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
33
31
|
container = _render.container;
|
|
34
32
|
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
35
|
-
_getAllByTestId2 = _slicedToArray(_getAllByTestId,
|
|
36
|
-
formGroup = _getAllByTestId2[0]
|
|
37
|
-
textarea = _getAllByTestId2[1];
|
|
33
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 1),
|
|
34
|
+
formGroup = _getAllByTestId2[0];
|
|
38
35
|
expect(formGroup.tagName).toEqual('DIV');
|
|
39
36
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
40
|
-
var
|
|
37
|
+
var wrapper = container.querySelector("#".concat(ID));
|
|
38
|
+
expect(wrapper.tagName).toEqual('DIV');
|
|
39
|
+
expect(wrapper.classList).toContain('cop-multi-file-upload');
|
|
40
|
+
expect(wrapper.id).toEqual(ID);
|
|
41
|
+
var input = wrapper.children[1].children[0];
|
|
42
|
+
var label;
|
|
43
|
+
formGroup.childNodes.forEach(function (node) {
|
|
44
|
+
// Check if it's an element.
|
|
45
|
+
if (node instanceof Element && node.tagName === 'LABEL') {
|
|
46
|
+
label = node;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
expect(label).toBeDefined();
|
|
41
50
|
expect(label.innerHTML).toContain(LABEL);
|
|
42
51
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
var str = JSON.stringify({
|
|
53
|
+
alpha: 'bravo'
|
|
54
|
+
});
|
|
55
|
+
var blob = new Blob([str]);
|
|
56
|
+
var FILE = new File([blob], 'test.json', {
|
|
57
|
+
type: 'application/JSON'
|
|
58
|
+
});
|
|
59
|
+
_react.fireEvent.change(input, {
|
|
48
60
|
target: {
|
|
49
|
-
|
|
50
|
-
value: 'Some text'
|
|
61
|
+
files: [FILE]
|
|
51
62
|
}
|
|
52
63
|
});
|
|
53
64
|
expect(ON_CHANGE_CALLS.length).toEqual(1);
|
|
54
|
-
expect(
|
|
55
|
-
name: FIELD_ID,
|
|
56
|
-
value: 'Some text'
|
|
57
|
-
});
|
|
65
|
+
expect(input.files.length).toEqual(1);
|
|
58
66
|
});
|
|
59
67
|
});
|