@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
|
@@ -16,8 +16,8 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
16
16
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
17
17
|
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."); }
|
|
18
18
|
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); }
|
|
19
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
20
|
-
function _iterableToArrayLimit(arr, i) { var _i =
|
|
19
|
+
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; }
|
|
20
|
+
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; } }
|
|
21
21
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
22
|
var GroupAction = function GroupAction(_ref) {
|
|
23
23
|
var group = _ref.group;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
5
|
+
var _GroupAction = _interopRequireDefault(require("./GroupAction"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
// Global imports
|
|
8
|
+
|
|
9
|
+
// Local imports
|
|
10
|
+
|
|
11
|
+
describe('components', function () {
|
|
12
|
+
describe('SummaryList.GroupAction', function () {
|
|
13
|
+
it('should handle a group row without an action', function () {
|
|
14
|
+
var ROW = {};
|
|
15
|
+
var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
16
|
+
group: ROW
|
|
17
|
+
})),
|
|
18
|
+
container = _render.container;
|
|
19
|
+
expect(container.childNodes.length).toEqual(0);
|
|
20
|
+
});
|
|
21
|
+
it('should handle a row with an href in the action', function () {
|
|
22
|
+
var PAGE = 'alpha';
|
|
23
|
+
var ROW = {
|
|
24
|
+
action: {
|
|
25
|
+
page: PAGE,
|
|
26
|
+
label: 'Change'
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
30
|
+
group: ROW
|
|
31
|
+
})),
|
|
32
|
+
container = _render2.container;
|
|
33
|
+
var link = container.childNodes[0];
|
|
34
|
+
expect(link.tagName).toEqual('A');
|
|
35
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
36
|
+
expect(link.textContent).toEqual(ROW.action.label);
|
|
37
|
+
});
|
|
38
|
+
it('should render an aria_suffix appropriately', function () {
|
|
39
|
+
var PAGE = 'alpha';
|
|
40
|
+
var ROW = {
|
|
41
|
+
action: {
|
|
42
|
+
page: PAGE,
|
|
43
|
+
label: 'Change',
|
|
44
|
+
aria_suffix: 'the thing'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
48
|
+
group: ROW
|
|
49
|
+
})),
|
|
50
|
+
container = _render3.container;
|
|
51
|
+
var link = container.childNodes[0];
|
|
52
|
+
expect(link.tagName).toEqual('A');
|
|
53
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
54
|
+
expect(link.textContent).toEqual("".concat(ROW.action.label, " ").concat(ROW.action.aria_suffix));
|
|
55
|
+
});
|
|
56
|
+
it('should handle a row with an onAction in the action', function () {
|
|
57
|
+
var ON_ACTION_CALLS = [];
|
|
58
|
+
var ON_ACTION = function ON_ACTION(row) {
|
|
59
|
+
ON_ACTION_CALLS.push(row);
|
|
60
|
+
};
|
|
61
|
+
var ROW = {
|
|
62
|
+
action: {
|
|
63
|
+
onAction: ON_ACTION,
|
|
64
|
+
label: 'Change'
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_GroupAction.default, {
|
|
68
|
+
group: ROW
|
|
69
|
+
})),
|
|
70
|
+
container = _render4.container;
|
|
71
|
+
var link = container.childNodes[0];
|
|
72
|
+
expect(link.tagName).toEqual('A');
|
|
73
|
+
expect(link.getAttribute('onClick')).toBeDefined();
|
|
74
|
+
expect(link.textContent).toEqual(ROW.action.label);
|
|
75
|
+
_react.fireEvent.click(link, {});
|
|
76
|
+
expect(ON_ACTION_CALLS.length).toEqual(1);
|
|
77
|
+
expect(ON_ACTION_CALLS[0]).toEqual(ROW);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -15,8 +15,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
15
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
16
|
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."); }
|
|
17
17
|
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); }
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
19
|
-
function _iterableToArrayLimit(arr, i) { var _i =
|
|
18
|
+
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; }
|
|
19
|
+
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; } }
|
|
20
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
21
|
var RowAction = function RowAction(_ref) {
|
|
22
22
|
var row = _ref.row;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
5
|
+
var _RowAction = _interopRequireDefault(require("./RowAction"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
+
// Global imports
|
|
8
|
+
|
|
9
|
+
// Local imports
|
|
10
|
+
|
|
11
|
+
describe('components', function () {
|
|
12
|
+
describe('SummaryList.RowAction', function () {
|
|
13
|
+
it('should handle a row without an action', function () {
|
|
14
|
+
var ROW = {};
|
|
15
|
+
var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
16
|
+
row: ROW
|
|
17
|
+
})),
|
|
18
|
+
container = _render.container;
|
|
19
|
+
expect(container.childNodes.length).toEqual(0);
|
|
20
|
+
});
|
|
21
|
+
it('should handle a row with an href in the action', function () {
|
|
22
|
+
var PAGE = 'alpha';
|
|
23
|
+
var ROW = {
|
|
24
|
+
action: {
|
|
25
|
+
page: PAGE,
|
|
26
|
+
label: 'Change'
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
30
|
+
row: ROW
|
|
31
|
+
})),
|
|
32
|
+
container = _render2.container;
|
|
33
|
+
var link = container.childNodes[0];
|
|
34
|
+
expect(link.tagName).toEqual('A');
|
|
35
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
36
|
+
expect(link.textContent).toEqual(ROW.action.label);
|
|
37
|
+
});
|
|
38
|
+
it('should render an aria_suffix appropriately', function () {
|
|
39
|
+
var PAGE = 'alpha';
|
|
40
|
+
var ROW = {
|
|
41
|
+
action: {
|
|
42
|
+
page: PAGE,
|
|
43
|
+
label: 'Change',
|
|
44
|
+
aria_suffix: 'the thing'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
48
|
+
row: ROW
|
|
49
|
+
})),
|
|
50
|
+
container = _render3.container;
|
|
51
|
+
var link = container.childNodes[0];
|
|
52
|
+
expect(link.tagName).toEqual('A');
|
|
53
|
+
expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
|
|
54
|
+
expect(link.textContent).toEqual("".concat(ROW.action.label, " ").concat(ROW.action.aria_suffix));
|
|
55
|
+
});
|
|
56
|
+
it('should handle a row with an onAction in the action', function () {
|
|
57
|
+
var ON_ACTION_CALLS = [];
|
|
58
|
+
var ON_ACTION = function ON_ACTION(row) {
|
|
59
|
+
ON_ACTION_CALLS.push(row);
|
|
60
|
+
};
|
|
61
|
+
var ROW = {
|
|
62
|
+
action: {
|
|
63
|
+
onAction: ON_ACTION,
|
|
64
|
+
label: 'Change'
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_RowAction.default, {
|
|
68
|
+
row: ROW
|
|
69
|
+
})),
|
|
70
|
+
container = _render4.container;
|
|
71
|
+
var link = container.childNodes[0];
|
|
72
|
+
expect(link.tagName).toEqual('A');
|
|
73
|
+
expect(link.getAttribute('onClick')).toBeDefined();
|
|
74
|
+
expect(link.textContent).toEqual(ROW.action.label);
|
|
75
|
+
_react.fireEvent.click(link, {});
|
|
76
|
+
expect(ON_ACTION_CALLS.length).toEqual(1);
|
|
77
|
+
expect(ON_ACTION_CALLS[0]).toEqual(ROW);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -9,9 +9,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _GroupAction = _interopRequireDefault(require("./GroupAction"));
|
|
11
11
|
var _SummaryListRow = _interopRequireDefault(require("./SummaryListRow"));
|
|
12
|
+
var _SummaryListHeadingRow = _interopRequireDefault(require("./SummaryListHeadingRow"));
|
|
12
13
|
var _SummaryListTitleRow = _interopRequireDefault(require("./SummaryListTitleRow"));
|
|
13
14
|
require("./SummaryList.scss");
|
|
14
|
-
var _excluded = ["rows", "noChangeAction", "isGroup", "classBlock", "classModifiers", "className"];
|
|
15
|
+
var _excluded = ["rows", "noChangeAction", "noGroupAction", "isGroup", "classBlock", "classModifiers", "className"];
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
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); }
|
|
17
18
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
@@ -21,6 +22,7 @@ exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
|
21
22
|
var SummaryList = function SummaryList(_ref) {
|
|
22
23
|
var rows = _ref.rows,
|
|
23
24
|
noChangeAction = _ref.noChangeAction,
|
|
25
|
+
noGroupAction = _ref.noGroupAction,
|
|
24
26
|
isGroup = _ref.isGroup,
|
|
25
27
|
classBlock = _ref.classBlock,
|
|
26
28
|
classModifiers = _ref.classModifiers,
|
|
@@ -32,7 +34,7 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
32
34
|
var rowActions = rows.filter(function (r) {
|
|
33
35
|
return !!r.action;
|
|
34
36
|
});
|
|
35
|
-
groupActionRow = rowActions
|
|
37
|
+
groupActionRow = rowActions !== null && rowActions !== void 0 && rowActions.length ? rowActions[0] : null;
|
|
36
38
|
}
|
|
37
39
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
38
40
|
className: "group-of-rows"
|
|
@@ -47,8 +49,16 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
47
49
|
classes: classes
|
|
48
50
|
});
|
|
49
51
|
}
|
|
52
|
+
if (row.type === 'heading') {
|
|
53
|
+
return /*#__PURE__*/_react.default.createElement(_SummaryListHeadingRow.default, {
|
|
54
|
+
key: key,
|
|
55
|
+
title: row.key,
|
|
56
|
+
size: row.size || 's',
|
|
57
|
+
classes: classes
|
|
58
|
+
});
|
|
59
|
+
}
|
|
50
60
|
if (row.type === 'action') {
|
|
51
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
61
|
+
return noChangeAction ? null : /*#__PURE__*/_react.default.createElement("div", {
|
|
52
62
|
key: "".concat(key, "-actions")
|
|
53
63
|
}, /*#__PURE__*/_react.default.createElement(_GroupAction.default, {
|
|
54
64
|
group: row
|
|
@@ -60,35 +70,42 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
60
70
|
classes: classes,
|
|
61
71
|
showAction: !noChangeAction
|
|
62
72
|
});
|
|
63
|
-
})
|
|
73
|
+
}).filter(function (r) {
|
|
74
|
+
return !!r;
|
|
75
|
+
}), isGroup && !noGroupAction && /*#__PURE__*/_react.default.createElement("div", {
|
|
64
76
|
className: "change-group-button"
|
|
65
77
|
}, /*#__PURE__*/_react.default.createElement(_GroupAction.default, {
|
|
66
78
|
group: groupActionRow
|
|
67
79
|
}))));
|
|
68
80
|
};
|
|
69
81
|
SummaryList.propTypes = {
|
|
82
|
+
classBlock: _propTypes.default.string,
|
|
83
|
+
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
84
|
+
className: _propTypes.default.string,
|
|
85
|
+
isGroup: _propTypes.default.bool,
|
|
86
|
+
noChangeAction: _propTypes.default.bool,
|
|
87
|
+
noGroupAction: _propTypes.default.bool,
|
|
70
88
|
rows: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
71
89
|
pageId: _propTypes.default.string.isRequired,
|
|
72
90
|
fieldId: _propTypes.default.string.isRequired,
|
|
73
91
|
full_path: _propTypes.default.string,
|
|
74
92
|
key: _propTypes.default.string.isRequired,
|
|
75
|
-
value: _propTypes.default.
|
|
93
|
+
value: _propTypes.default.node,
|
|
76
94
|
action: _propTypes.default.shape({
|
|
77
95
|
page: _propTypes.default.string,
|
|
78
96
|
label: _propTypes.default.string,
|
|
79
97
|
aria_suffix: _propTypes.default.string,
|
|
80
98
|
onAction: _propTypes.default.func
|
|
81
99
|
})
|
|
82
|
-
})).isRequired
|
|
83
|
-
noChangeAction: _propTypes.default.bool,
|
|
84
|
-
isGroup: _propTypes.default.bool,
|
|
85
|
-
classBlock: _propTypes.default.string,
|
|
86
|
-
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
87
|
-
className: _propTypes.default.string
|
|
100
|
+
})).isRequired
|
|
88
101
|
};
|
|
89
102
|
SummaryList.defaultProps = {
|
|
90
103
|
classBlock: DEFAULT_CLASS,
|
|
91
|
-
|
|
104
|
+
classModifiers: [],
|
|
105
|
+
className: '',
|
|
106
|
+
isGroup: false,
|
|
107
|
+
noChangeAction: false,
|
|
108
|
+
noGroupAction: false
|
|
92
109
|
};
|
|
93
110
|
var _default = SummaryList;
|
|
94
111
|
exports.default = _default;
|
|
@@ -14,6 +14,25 @@
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
.govuk-summary-list__heading {
|
|
18
|
+
width: 100%;
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
.govuk-heading-s {
|
|
21
|
+
margin-bottom: 10px;
|
|
22
|
+
}
|
|
23
|
+
.govuk-heading-m {
|
|
24
|
+
margin-bottom: 10px;
|
|
25
|
+
}
|
|
26
|
+
&:not(:first-child) {
|
|
27
|
+
.govuk-heading-s {
|
|
28
|
+
margin-top: 20px;
|
|
29
|
+
}
|
|
30
|
+
.govuk-heading-m {
|
|
31
|
+
margin-top: 30px;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
17
36
|
.changeRow {
|
|
18
37
|
.govuk-link {
|
|
19
38
|
float: right;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!-- Global imports -->
|
|
2
|
+
|
|
3
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
4
|
+
import { Details, Heading } from '@ukhomeoffice/cop-react-components';
|
|
5
|
+
|
|
6
|
+
<!-- Local imports -->
|
|
7
|
+
|
|
8
|
+
import Utils from '../../utils';
|
|
9
|
+
import SummaryList from './SummaryList';
|
|
10
|
+
|
|
11
|
+
<Meta
|
|
12
|
+
title='Components/Summary list'
|
|
13
|
+
id='D-SummaryList'
|
|
14
|
+
component={SummaryList}
|
|
15
|
+
/>
|
|
16
|
+
|
|
17
|
+
<Heading size='xl' caption='Components'>
|
|
18
|
+
Summary list
|
|
19
|
+
</Heading>
|
|
20
|
+
|
|
21
|
+
Renders a list of key-value pairs, most commonly on the **Check your answers** screen, and optionally
|
|
22
|
+
display action links.
|
|
23
|
+
|
|
24
|
+
<Canvas withToolbar>
|
|
25
|
+
<Story name='Default'>
|
|
26
|
+
{() => {
|
|
27
|
+
const onAction = (row) => {
|
|
28
|
+
console.log('action clicked', row);
|
|
29
|
+
};
|
|
30
|
+
const ROWS = [
|
|
31
|
+
{
|
|
32
|
+
pageId: 'p1',
|
|
33
|
+
fieldId: 'forename',
|
|
34
|
+
key: 'Forename(s)',
|
|
35
|
+
value: 'John',
|
|
36
|
+
},
|
|
37
|
+
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
38
|
+
{
|
|
39
|
+
pageId: 'p2',
|
|
40
|
+
fieldId: 'dob',
|
|
41
|
+
key: 'Date of birth',
|
|
42
|
+
value: '29/08/1993',
|
|
43
|
+
action: { label: 'Change', onAction },
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
return <SummaryList rows={ROWS} />;
|
|
47
|
+
}}
|
|
48
|
+
</Story>
|
|
49
|
+
</Canvas>
|
|
50
|
+
|
|
51
|
+
<Details summary='Properties' className='no-indent'>
|
|
52
|
+
<ArgsTable of={SummaryList} />
|
|
53
|
+
</Details>
|
|
54
|
+
|
|
55
|
+
## Variant
|
|
56
|
+
|
|
57
|
+
### Read-only style
|
|
58
|
+
|
|
59
|
+
<Canvas>
|
|
60
|
+
<Story name='Read-only style'>
|
|
61
|
+
{() => {
|
|
62
|
+
const onAction = (row) => {
|
|
63
|
+
console.log('action clicked', row);
|
|
64
|
+
};
|
|
65
|
+
const ROWS = [
|
|
66
|
+
{
|
|
67
|
+
pageId: 'p1',
|
|
68
|
+
fieldId: 'forename',
|
|
69
|
+
key: 'Forename(s)',
|
|
70
|
+
value: 'John',
|
|
71
|
+
},
|
|
72
|
+
{ pageId: 'p1', fieldId: 'surname', key: 'Surname', value: 'Smith' },
|
|
73
|
+
{
|
|
74
|
+
pageId: 'p2',
|
|
75
|
+
fieldId: 'dob',
|
|
76
|
+
key: 'Date of birth',
|
|
77
|
+
value: '29/08/1993',
|
|
78
|
+
action: { label: 'Change', onAction },
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
return (
|
|
82
|
+
<SummaryList
|
|
83
|
+
classModifiers='no-border'
|
|
84
|
+
rows={ROWS}
|
|
85
|
+
noChangeAction={true}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}}
|
|
89
|
+
</Story>
|
|
90
|
+
</Canvas>
|