@ukhomeoffice/cop-react-form-renderer 4.17.0 → 5.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +1 -14
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +19 -57
- package/dist/components/CheckYourAnswers/index.js +0 -3
- package/dist/components/CollectionPage/CollectionPage.js +8 -38
- package/dist/components/CollectionPage/index.js +0 -3
- package/dist/components/FormComponent/Collection.js +13 -54
- package/dist/components/FormComponent/Container.js +6 -30
- package/dist/components/FormComponent/FormComponent.js +14 -57
- package/dist/components/FormComponent/helpers/addLabel.js +4 -7
- package/dist/components/FormComponent/helpers/getComponentDisabled.js +0 -4
- package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +0 -2
- package/dist/components/FormComponent/helpers/getComponentError.js +0 -6
- package/dist/components/FormComponent/helpers/getComponentError.test.js +0 -2
- package/dist/components/FormComponent/helpers/index.js +0 -4
- package/dist/components/FormComponent/index.js +0 -3
- package/dist/components/FormPage/FormPage.js +14 -45
- package/dist/components/FormPage/index.js +0 -3
- package/dist/components/FormRenderer/FormRenderer.js +106 -189
- package/dist/components/FormRenderer/handlers/cyaAction.js +0 -5
- package/dist/components/FormRenderer/handlers/getPageId.js +0 -2
- package/dist/components/FormRenderer/handlers/getPageId.test.js +1 -2
- package/dist/components/FormRenderer/handlers/handlers.test.js +1 -18
- package/dist/components/FormRenderer/handlers/index.js +0 -5
- package/dist/components/FormRenderer/handlers/navigate.js +0 -5
- package/dist/components/FormRenderer/handlers/submissionError.js +0 -2
- package/dist/components/FormRenderer/helpers/canActionProceed.js +0 -3
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +1 -3
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +0 -2
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +1 -5
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +0 -5
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +1 -2
- package/dist/components/FormRenderer/helpers/getCYA.js +0 -6
- package/dist/components/FormRenderer/helpers/getCYA.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getFormState.js +0 -5
- package/dist/components/FormRenderer/helpers/getFormState.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getNextPageId.js +0 -25
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +1 -4
- package/dist/components/FormRenderer/helpers/getPage.js +0 -5
- package/dist/components/FormRenderer/helpers/getPage.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +0 -6
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -3
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +0 -10
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +0 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +6 -20
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +3 -8
- package/dist/components/FormRenderer/helpers/index.js +1 -11
- package/dist/components/FormRenderer/index.js +0 -3
- package/dist/components/PageActions/ActionButton.js +2 -17
- package/dist/components/PageActions/PageActions.js +3 -10
- package/dist/components/PageActions/index.js +0 -3
- package/dist/components/SummaryList/GroupAction.js +3 -24
- package/dist/components/SummaryList/RowAction.js +3 -23
- package/dist/components/SummaryList/SummaryList.js +6 -28
- package/dist/components/SummaryList/SummaryListRow.js +4 -8
- package/dist/components/SummaryList/SummaryListTitleRow.js +2 -7
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +0 -3
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +0 -6
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +0 -3
- package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +0 -6
- package/dist/components/SummaryList/helpers/index.js +0 -2
- package/dist/components/SummaryList/index.js +0 -3
- package/dist/components/TaskList/Task.js +7 -29
- package/dist/components/TaskList/TaskList.js +12 -33
- package/dist/components/TaskList/TaskState.js +2 -10
- package/dist/components/TaskList/index.js +0 -3
- package/dist/components/index.js +0 -6
- package/dist/context/HooksContext/HooksContext.js +14 -34
- package/dist/context/HooksContext/index.js +0 -5
- package/dist/context/ValidationContext/ValidationContext.js +8 -34
- package/dist/context/ValidationContext/index.js +0 -5
- package/dist/context/index.js +0 -3
- package/dist/hooks/index.js +0 -9
- package/dist/hooks/useAxios.js +8 -25
- package/dist/hooks/useGetRequest.js +13 -47
- package/dist/hooks/useHooks.js +2 -4
- package/dist/hooks/useRefData.js +8 -37
- package/dist/hooks/useValidation.js +2 -4
- package/dist/index.js +0 -6
- package/dist/models/PageAction.js +0 -3
- package/dist/models/TaskStates.js +0 -3
- package/dist/models/index.js +0 -9
- package/dist/utils/CheckYourAnswers/getCYAAction.js +1 -9
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +0 -10
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +0 -8
- package/dist/utils/CheckYourAnswers/getCYARow.js +1 -10
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +2 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +0 -18
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +0 -20
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +0 -13
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +2 -22
- package/dist/utils/CheckYourAnswers/index.js +1 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +2 -11
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +0 -11
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +0 -6
- package/dist/utils/CollectionPage/index.js +1 -5
- package/dist/utils/CollectionPage/mergeCollectionPages.js +1 -12
- package/dist/utils/Component/cleanAttributes.js +1 -8
- package/dist/utils/Component/elevateNestedComponents.js +0 -3
- package/dist/utils/Component/getComponent.js +4 -68
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +6 -10
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +10 -28
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +6 -33
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +10 -27
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +4 -10
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +4 -22
- package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +3 -7
- package/dist/utils/Component/getComponentTests/getComponent.html.test.js +4 -10
- package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +3 -7
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -15
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +6 -33
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +4 -21
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +10 -29
- package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +1 -2
- package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +3 -7
- package/dist/utils/Component/getDefaultValue.js +0 -7
- package/dist/utils/Component/index.js +0 -9
- package/dist/utils/Component/isEditable.js +1 -4
- package/dist/utils/Component/showComponent.js +1 -8
- package/dist/utils/Component/wrapInFormGroup.js +0 -7
- package/dist/utils/Condition/index.js +0 -5
- package/dist/utils/Condition/meetsAllConditions.js +0 -9
- package/dist/utils/Condition/meetsCondition.js +7 -19
- package/dist/utils/Condition/meetsOneCondition.js +1 -9
- package/dist/utils/Condition/setupConditions.js +0 -12
- package/dist/utils/Container/getEditableComponents.js +0 -7
- package/dist/utils/Container/index.js +0 -5
- package/dist/utils/Container/setupNesting.js +0 -11
- package/dist/utils/Container/showContainer.js +9 -18
- package/dist/utils/Data/applyFormula.js +2 -28
- package/dist/utils/Data/getAutocompleteSource.js +1 -4
- package/dist/utils/Data/getDataPath.js +3 -17
- package/dist/utils/Data/getOptions.js +0 -9
- package/dist/utils/Data/getSourceData.js +4 -19
- package/dist/utils/Data/index.js +1 -11
- package/dist/utils/Data/refDataToOptions.js +1 -12
- package/dist/utils/Data/setDataItem.js +0 -5
- package/dist/utils/Data/setupFormData.js +2 -20
- package/dist/utils/Data/setupRefDataUrlForComponent.js +0 -14
- package/dist/utils/FormPage/getFormPage.js +0 -15
- package/dist/utils/FormPage/getFormPages.js +0 -8
- package/dist/utils/FormPage/getPageActions.js +3 -18
- package/dist/utils/FormPage/getParagraphFromText.js +0 -3
- package/dist/utils/FormPage/index.js +0 -6
- package/dist/utils/FormPage/showFormPage.js +9 -18
- package/dist/utils/FormPage/showFormPageCYA.js +0 -5
- package/dist/utils/FormPage/useComponent.js +3 -18
- package/dist/utils/Format/formatData.js +0 -5
- package/dist/utils/Format/formatDataForComponent.js +1 -6
- package/dist/utils/Format/formatDataForForm.js +0 -8
- package/dist/utils/Format/formatDataForPage.js +1 -5
- package/dist/utils/Format/index.js +1 -6
- package/dist/utils/Hub/getFormHub.js +0 -8
- package/dist/utils/Hub/index.js +1 -3
- package/dist/utils/Meta/documents/getDocuments.js +1 -4
- package/dist/utils/Meta/documents/getDocuments.test.js +0 -9
- package/dist/utils/Meta/documents/index.js +1 -5
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -11
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -11
- package/dist/utils/Meta/index.js +2 -6
- package/dist/utils/Operate/checkValueIsTruthy.js +1 -7
- package/dist/utils/Operate/getIndexOfMatchingValueIn.js +7 -21
- package/dist/utils/Operate/index.js +0 -3
- package/dist/utils/Operate/persistValueInFormData.js +1 -8
- package/dist/utils/Operate/runPageOperations.js +3 -18
- package/dist/utils/Operate/setValueInFormData.js +2 -7
- package/dist/utils/Operate/shouldRun.js +1 -14
- package/dist/utils/Validate/additional/index.js +1 -18
- package/dist/utils/Validate/additional/index.test.js +0 -6
- package/dist/utils/Validate/additional/mustBeAfter.js +3 -8
- package/dist/utils/Validate/additional/mustBeAfter.test.js +0 -4
- package/dist/utils/Validate/additional/mustBeBefore.js +3 -8
- package/dist/utils/Validate/additional/mustBeBefore.test.js +0 -4
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +5 -16
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +0 -7
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +3 -12
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +0 -3
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -13
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +0 -3
- package/dist/utils/Validate/additional/mustBeLessThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeLongerThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeLongerThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +0 -4
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +0 -2
- package/dist/utils/Validate/additional/mustBeShorterThan.js +0 -3
- package/dist/utils/Validate/additional/mustBeShorterThan.test.js +0 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +0 -5
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +0 -4
- package/dist/utils/Validate/additional/utils.js +8 -24
- package/dist/utils/Validate/index.js +1 -9
- package/dist/utils/Validate/validateCollection.js +0 -9
- package/dist/utils/Validate/validateComponent.js +2 -35
- package/dist/utils/Validate/validateContainer.js +0 -13
- package/dist/utils/Validate/validateDate.js +4 -36
- package/dist/utils/Validate/validateEmail.js +1 -7
- package/dist/utils/Validate/validatePage.js +0 -15
- package/dist/utils/Validate/validateRegex.js +0 -10
- package/dist/utils/Validate/validateRequired.js +0 -8
- package/dist/utils/Validate/validateTime.js +3 -20
- package/dist/utils/index.js +0 -19
- package/package.json +50 -34
- package/dist/components/CheckYourAnswers/Answer.test.js +0 -95
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +0 -410
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +0 -680
- package/dist/components/CollectionPage/CollectionPage.test.js +0 -428
- package/dist/components/FormComponent/Collection.test.js +0 -381
- package/dist/components/FormComponent/Container.test.js +0 -423
- package/dist/components/FormComponent/FormComponent.stories.mdx +0 -184
- package/dist/components/FormComponent/FormComponent.test.js +0 -264
- package/dist/components/FormPage/FormPage.stories.mdx +0 -131
- package/dist/components/FormPage/FormPage.test.js +0 -368
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +0 -183
- package/dist/components/FormRenderer/FormRenderer.test.js +0 -1006
- package/dist/components/PageActions/ActionButton.test.js +0 -116
- package/dist/components/PageActions/PageActions.stories.mdx +0 -74
- package/dist/components/PageActions/PageActions.test.js +0 -157
- package/dist/components/SummaryList/GroupAction.test.js +0 -94
- package/dist/components/SummaryList/RowAction.test.js +0 -94
- package/dist/components/SummaryList/SummaryList.stories.mdx +0 -90
- package/dist/components/SummaryList/SummaryList.test.js +0 -361
- package/dist/components/TaskList/Task.test.js +0 -194
- package/dist/components/TaskList/TaskList.stories.mdx +0 -164
- package/dist/components/TaskList/TaskList.test.js +0 -334
- package/dist/components/TaskList/TaskState.test.js +0 -104
- package/dist/context/HooksContext/HooksContext.test.js +0 -60
- package/dist/context/ValidationContext/ValidationContext.test.js +0 -98
- package/dist/json/areYouACivilServant.json +0 -7
- package/dist/json/firstForm.json +0 -94
- package/dist/json/grade.json +0 -108
- package/dist/json/group.data.json +0 -21
- package/dist/json/group.json +0 -402
- package/dist/json/groupOfRow.json +0 -137
- package/dist/json/groupOfRowData.json +0 -15
- package/dist/json/port.json +0 -346
- package/dist/json/saveAndContinue.json +0 -98
- package/dist/json/sublocation.json +0 -859
- package/dist/json/taskList.json +0 -265
- package/dist/json/team.json +0 -17351
- package/dist/json/terminal.json +0 -81
- package/dist/json/userProfile.data.json +0 -21
- package/dist/json/userProfile.json +0 -276
- package/dist/setupTests.js +0 -59
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +0 -139
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +0 -76
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +0 -59
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +0 -256
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +0 -77
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +0 -199
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +0 -170
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +0 -323
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +0 -281
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +0 -64
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +0 -41
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +0 -54
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -131
- package/dist/utils/Component/cleanAttributes.test.js +0 -69
- package/dist/utils/Component/elevateNestedComponents.test.js +0 -92
- package/dist/utils/Component/getDefaultValue.test.js +0 -53
- package/dist/utils/Component/isEditable.test.js +0 -42
- package/dist/utils/Component/showComponent.test.js +0 -157
- package/dist/utils/Condition/meetsAllConditions.test.js +0 -62
- package/dist/utils/Condition/meetsCondition.test.js +0 -391
- package/dist/utils/Condition/meetsOneCondition.test.js +0 -101
- package/dist/utils/Condition/setupConditions.test.js +0 -35
- package/dist/utils/Container/getEditableComponents.test.js +0 -146
- package/dist/utils/Container/setupNesting.test.js +0 -92
- package/dist/utils/Container/showContainer.test.js +0 -179
- package/dist/utils/Data/applyFormula.test.js +0 -264
- package/dist/utils/Data/getAutocompleteSource.test.js +0 -146
- package/dist/utils/Data/getDataPath.test.js +0 -52
- package/dist/utils/Data/getOptions.test.js +0 -71
- package/dist/utils/Data/getSourceData.test.js +0 -141
- package/dist/utils/Data/refDataToOptions.test.js +0 -197
- package/dist/utils/Data/setDataItem.test.js +0 -112
- package/dist/utils/Data/setupFormData.test.js +0 -276
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +0 -133
- package/dist/utils/FormPage/getFormPage.test.js +0 -205
- package/dist/utils/FormPage/getFormPages.test.js +0 -98
- package/dist/utils/FormPage/getPageActions.test.js +0 -89
- package/dist/utils/FormPage/getParagraphFromText.test.js +0 -29
- package/dist/utils/FormPage/showFormPage.test.js +0 -182
- package/dist/utils/FormPage/showFormPageCYA.test.js +0 -30
- package/dist/utils/FormPage/useComponent.test.js +0 -169
- package/dist/utils/Format/formatData.test.js +0 -46
- package/dist/utils/Format/formatDataForComponent.test.js +0 -161
- package/dist/utils/Format/formatDataForForm.test.js +0 -78
- package/dist/utils/Format/formatDataForPage.test.js +0 -96
- package/dist/utils/Hub/getFormHub.test.js +0 -107
- package/dist/utils/Operate/checkValueIsTruthy.test.js +0 -44
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +0 -159
- package/dist/utils/Operate/persistValueInFormData.test.js +0 -106
- package/dist/utils/Operate/runPageOperations.test.js +0 -107
- package/dist/utils/Operate/setValueInFormData.test.js +0 -46
- package/dist/utils/Operate/shouldRun.test.js +0 -69
- package/dist/utils/Validate/validateCollection.test.js +0 -74
- package/dist/utils/Validate/validateComponent.test.js +0 -267
- package/dist/utils/Validate/validateContainer.test.js +0 -81
- package/dist/utils/Validate/validateDate.test.js +0 -118
- package/dist/utils/Validate/validateEmail.test.js +0 -57
- package/dist/utils/Validate/validatePage.test.js +0 -383
- package/dist/utils/Validate/validateRegex.test.js +0 -41
- package/dist/utils/Validate/validateRequired.test.js +0 -62
- package/dist/utils/Validate/validateTime.test.js +0 -61
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = _interopRequireDefault(require("react"));
|
|
4
|
-
|
|
5
|
-
var _setupTests = require("../../setupTests");
|
|
6
|
-
|
|
7
|
-
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
-
|
|
13
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
|
-
|
|
15
|
-
describe('components', function () {
|
|
16
|
-
describe('FormComponent', function () {
|
|
17
|
-
it('should render a text component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
18
|
-
var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation, container, formGroup, label, hint, input;
|
|
19
|
-
|
|
20
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
|
-
while (1) {
|
|
22
|
-
switch (_context.prev = _context.next) {
|
|
23
|
-
case 0:
|
|
24
|
-
ID = 'component';
|
|
25
|
-
VALUE = 'Text value';
|
|
26
|
-
COMPONENT = {
|
|
27
|
-
id: ID,
|
|
28
|
-
fieldId: ID,
|
|
29
|
-
type: 'text',
|
|
30
|
-
label: 'Text component',
|
|
31
|
-
hint: 'Text hint'
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
ON_CHANGE = function ON_CHANGE() {};
|
|
35
|
-
|
|
36
|
-
_renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
37
|
-
"data-testid": ID,
|
|
38
|
-
component: COMPONENT,
|
|
39
|
-
value: VALUE,
|
|
40
|
-
onChange: ON_CHANGE
|
|
41
|
-
})), container = _renderWithValidation.container; // text components are wrapper in a FormGroup by default.
|
|
42
|
-
|
|
43
|
-
formGroup = container.childNodes[0];
|
|
44
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
45
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
46
|
-
label = formGroup.childNodes[0];
|
|
47
|
-
expect(label.tagName).toEqual('LABEL');
|
|
48
|
-
expect(label.classList).toContain('govuk-label');
|
|
49
|
-
expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
|
|
50
|
-
expect(label.getAttribute('for')).toEqual(ID);
|
|
51
|
-
hint = formGroup.childNodes[1];
|
|
52
|
-
expect(hint.tagName).toEqual('SPAN');
|
|
53
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
54
|
-
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
55
|
-
input = formGroup.childNodes[2];
|
|
56
|
-
expect(input.tagName).toEqual('INPUT');
|
|
57
|
-
expect(input.classList).toContain('govuk-input');
|
|
58
|
-
expect(input.id).toEqual(ID);
|
|
59
|
-
expect(input.value).toEqual(VALUE);
|
|
60
|
-
|
|
61
|
-
case 22:
|
|
62
|
-
case "end":
|
|
63
|
-
return _context.stop();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}, _callee);
|
|
67
|
-
})));
|
|
68
|
-
it('should render a text component appropriately with wrap turned off', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
69
|
-
var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation2, container, input;
|
|
70
|
-
|
|
71
|
-
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
72
|
-
while (1) {
|
|
73
|
-
switch (_context2.prev = _context2.next) {
|
|
74
|
-
case 0:
|
|
75
|
-
ID = 'component';
|
|
76
|
-
VALUE = 'Text value';
|
|
77
|
-
COMPONENT = {
|
|
78
|
-
id: ID,
|
|
79
|
-
fieldId: ID,
|
|
80
|
-
type: 'text',
|
|
81
|
-
label: 'Text component',
|
|
82
|
-
hint: 'Text hint'
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
ON_CHANGE = function ON_CHANGE() {};
|
|
86
|
-
|
|
87
|
-
_renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
88
|
-
"data-testid": ID,
|
|
89
|
-
component: COMPONENT,
|
|
90
|
-
wrap: false,
|
|
91
|
-
value: VALUE,
|
|
92
|
-
onChange: ON_CHANGE
|
|
93
|
-
})), container = _renderWithValidation2.container; // With wrap = false, there should be no form group.
|
|
94
|
-
|
|
95
|
-
input = container.childNodes[0];
|
|
96
|
-
expect(input.tagName).toEqual('INPUT');
|
|
97
|
-
expect(input.classList).toContain('govuk-input');
|
|
98
|
-
expect(input.id).toEqual(ID);
|
|
99
|
-
expect(input.value).toEqual(VALUE);
|
|
100
|
-
|
|
101
|
-
case 10:
|
|
102
|
-
case "end":
|
|
103
|
-
return _context2.stop();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}, _callee2);
|
|
107
|
-
})));
|
|
108
|
-
it('should render an html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
109
|
-
var ID, COMPONENT, _renderWithValidation3, container, p;
|
|
110
|
-
|
|
111
|
-
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
112
|
-
while (1) {
|
|
113
|
-
switch (_context3.prev = _context3.next) {
|
|
114
|
-
case 0:
|
|
115
|
-
ID = 'component';
|
|
116
|
-
COMPONENT = {
|
|
117
|
-
type: 'html',
|
|
118
|
-
tagName: 'p',
|
|
119
|
-
content: 'HTML content'
|
|
120
|
-
};
|
|
121
|
-
_renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
122
|
-
"data-testid": ID,
|
|
123
|
-
component: COMPONENT
|
|
124
|
-
})), container = _renderWithValidation3.container;
|
|
125
|
-
p = container.childNodes[0];
|
|
126
|
-
expect(p.tagName).toEqual('P');
|
|
127
|
-
expect(p.textContent).toEqual(COMPONENT.content);
|
|
128
|
-
|
|
129
|
-
case 6:
|
|
130
|
-
case "end":
|
|
131
|
-
return _context3.stop();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}, _callee3);
|
|
135
|
-
})));
|
|
136
|
-
it('should render an overridden html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
137
|
-
var hooks, ID, COMPONENT, _renderWithValidation4, container, div;
|
|
138
|
-
|
|
139
|
-
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
140
|
-
while (1) {
|
|
141
|
-
switch (_context4.prev = _context4.next) {
|
|
142
|
-
case 0:
|
|
143
|
-
hooks = {
|
|
144
|
-
onGetComponent: function onGetComponent(config, wrap) {
|
|
145
|
-
return /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap));
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
ID = 'component';
|
|
149
|
-
COMPONENT = {
|
|
150
|
-
type: 'html',
|
|
151
|
-
tagName: 'p',
|
|
152
|
-
content: 'HTML content'
|
|
153
|
-
};
|
|
154
|
-
_renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
155
|
-
"data-testid": ID,
|
|
156
|
-
component: COMPONENT
|
|
157
|
-
}), {
|
|
158
|
-
hooks: hooks
|
|
159
|
-
}), container = _renderWithValidation4.container;
|
|
160
|
-
div = container.childNodes[0];
|
|
161
|
-
expect(div.tagName).toEqual('DIV');
|
|
162
|
-
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
|
|
163
|
-
|
|
164
|
-
case 7:
|
|
165
|
-
case "end":
|
|
166
|
-
return _context4.stop();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}, _callee4);
|
|
170
|
-
})));
|
|
171
|
-
it('should render the correct html component when the override returns null', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
172
|
-
var hooks, ID, COMPONENT, _renderWithValidation5, container, p;
|
|
173
|
-
|
|
174
|
-
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
175
|
-
while (1) {
|
|
176
|
-
switch (_context5.prev = _context5.next) {
|
|
177
|
-
case 0:
|
|
178
|
-
hooks = {
|
|
179
|
-
onGetComponent: function onGetComponent() {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
ID = 'component';
|
|
184
|
-
COMPONENT = {
|
|
185
|
-
type: 'html',
|
|
186
|
-
tagName: 'p',
|
|
187
|
-
content: 'HTML content'
|
|
188
|
-
};
|
|
189
|
-
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
190
|
-
"data-testid": ID,
|
|
191
|
-
component: COMPONENT
|
|
192
|
-
}), {
|
|
193
|
-
hooks: hooks
|
|
194
|
-
}), container = _renderWithValidation5.container;
|
|
195
|
-
p = container.childNodes[0];
|
|
196
|
-
expect(p.tagName).toEqual('P');
|
|
197
|
-
expect(p.textContent).toEqual(COMPONENT.content);
|
|
198
|
-
|
|
199
|
-
case 7:
|
|
200
|
-
case "end":
|
|
201
|
-
return _context5.stop();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, _callee5);
|
|
205
|
-
})));
|
|
206
|
-
it('should render a text component appropriately with interpolated label', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
|
|
207
|
-
var ID, VALUE, COMPONENT, DATA, ON_CHANGE, _renderWithValidation6, container, formGroup, label, hint, input;
|
|
208
|
-
|
|
209
|
-
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
210
|
-
while (1) {
|
|
211
|
-
switch (_context6.prev = _context6.next) {
|
|
212
|
-
case 0:
|
|
213
|
-
ID = 'component';
|
|
214
|
-
VALUE = 'Text value'; // eslint-disable-next-line no-template-curly-in-string
|
|
215
|
-
|
|
216
|
-
COMPONENT = {
|
|
217
|
-
id: ID,
|
|
218
|
-
fieldId: ID,
|
|
219
|
-
type: 'text',
|
|
220
|
-
label: '${text} Text component',
|
|
221
|
-
cya_label: '${text} Text component',
|
|
222
|
-
hint: 'Text hint'
|
|
223
|
-
};
|
|
224
|
-
DATA = {
|
|
225
|
-
text: 'Interpolated'
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
ON_CHANGE = function ON_CHANGE() {};
|
|
229
|
-
|
|
230
|
-
_renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
231
|
-
"data-testid": ID,
|
|
232
|
-
component: COMPONENT,
|
|
233
|
-
value: VALUE,
|
|
234
|
-
onChange: ON_CHANGE,
|
|
235
|
-
formData: DATA
|
|
236
|
-
})), container = _renderWithValidation6.container; // text components are wrapper in a FormGroup by default.
|
|
237
|
-
|
|
238
|
-
formGroup = container.childNodes[0];
|
|
239
|
-
expect(formGroup.tagName).toEqual('DIV');
|
|
240
|
-
expect(formGroup.classList).toContain('govuk-form-group');
|
|
241
|
-
label = formGroup.childNodes[0];
|
|
242
|
-
expect(label.tagName).toEqual('LABEL');
|
|
243
|
-
expect(label.classList).toContain('govuk-label');
|
|
244
|
-
expect(label.textContent).toEqual('Interpolated Text component (optional)');
|
|
245
|
-
expect(label.getAttribute('for')).toEqual(ID);
|
|
246
|
-
hint = formGroup.childNodes[1];
|
|
247
|
-
expect(hint.tagName).toEqual('SPAN');
|
|
248
|
-
expect(hint.classList).toContain('govuk-hint');
|
|
249
|
-
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
250
|
-
input = formGroup.childNodes[2];
|
|
251
|
-
expect(input.tagName).toEqual('INPUT');
|
|
252
|
-
expect(input.classList).toContain('govuk-input');
|
|
253
|
-
expect(input.id).toEqual(ID);
|
|
254
|
-
expect(input.value).toEqual(VALUE);
|
|
255
|
-
|
|
256
|
-
case 23:
|
|
257
|
-
case "end":
|
|
258
|
-
return _context6.stop();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}, _callee6);
|
|
262
|
-
})));
|
|
263
|
-
});
|
|
264
|
-
});
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
<!-- Global imports -->
|
|
2
|
-
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
|
-
import { Details, Heading, Link } from '@ukhomeoffice/cop-react-components';
|
|
4
|
-
import withMock from 'storybook-addon-mock';
|
|
5
|
-
|
|
6
|
-
<!-- Local imports -->
|
|
7
|
-
import { HooksContextProvider, ValidationContextProvider } from '../../context';
|
|
8
|
-
import Utils from '../../utils';
|
|
9
|
-
import FormPage from './FormPage';
|
|
10
|
-
|
|
11
|
-
<!-- JSON documents -->
|
|
12
|
-
import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
|
|
13
|
-
import GRADE from '../../json/grade.json';
|
|
14
|
-
import TEAMS from '../../json/team.json';
|
|
15
|
-
import USER_PROFILE_DATA from '../../json/userProfile.data.json';
|
|
16
|
-
import USER_PROFILE from '../../json/userProfile.json';
|
|
17
|
-
|
|
18
|
-
<Meta title="Components/Form page" id="D-FormPage" component={ FormPage } decorators={[withMock]} />
|
|
19
|
-
|
|
20
|
-
<Heading size="xl" caption="Components">Form page</Heading>
|
|
21
|
-
|
|
22
|
-
Renders a page on a form with <Link href="https://ukhomeoffice.github.io/cop-react-components/?path=/docs/d-alert--default-story">COP React components</Link>,
|
|
23
|
-
on the basis of a <Link href="/?path=/docs/f-json-page">JSON</Link> configuration.
|
|
24
|
-
|
|
25
|
-
<Canvas withToolbar>
|
|
26
|
-
<Story name="Default" parameters={{
|
|
27
|
-
mockData: [
|
|
28
|
-
{
|
|
29
|
-
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
30
|
-
method: 'GET',
|
|
31
|
-
status: 200,
|
|
32
|
-
response: CIVIL_SERVANT
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
36
|
-
method: 'GET',
|
|
37
|
-
status: 200,
|
|
38
|
-
response: GRADE
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
42
|
-
method: 'GET',
|
|
43
|
-
status: 200,
|
|
44
|
-
response: TEAMS
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}}>
|
|
48
|
-
{() => {
|
|
49
|
-
const PAGE_JSON = USER_PROFILE.pages.find(p => p.id === 'civil-servant-status');
|
|
50
|
-
const PAGE = Utils.FormPage.get(PAGE_JSON, USER_PROFILE.components, { ...USER_PROFILE_DATA });
|
|
51
|
-
const ON_ACTION = (action, patch, onError) => {
|
|
52
|
-
console.log('action invoked', action, patch);
|
|
53
|
-
};
|
|
54
|
-
return (
|
|
55
|
-
<HooksContextProvider>
|
|
56
|
-
<ValidationContextProvider>
|
|
57
|
-
<FormPage page={PAGE} onAction={ON_ACTION} />
|
|
58
|
-
</ValidationContextProvider>
|
|
59
|
-
</HooksContextProvider>
|
|
60
|
-
);
|
|
61
|
-
}}
|
|
62
|
-
</Story>
|
|
63
|
-
</Canvas>
|
|
64
|
-
|
|
65
|
-
<Details summary="Properties" className="no-indent">
|
|
66
|
-
<ArgsTable of={ FormPage } />
|
|
67
|
-
</Details>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
## Variants
|
|
71
|
-
### With `autocomplete`
|
|
72
|
-
<Canvas>
|
|
73
|
-
<Story name="With autocomplete" parameters={{
|
|
74
|
-
mockData: [
|
|
75
|
-
{
|
|
76
|
-
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
77
|
-
method: 'GET',
|
|
78
|
-
status: 200,
|
|
79
|
-
response: CIVIL_SERVANT
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
83
|
-
method: 'GET',
|
|
84
|
-
status: 200,
|
|
85
|
-
response: GRADE
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
89
|
-
method: 'GET',
|
|
90
|
-
status: 200,
|
|
91
|
-
response: TEAMS
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}}>
|
|
95
|
-
{() => {
|
|
96
|
-
const PAGE_JSON = USER_PROFILE.pages.find(p => p.id === 'team-name');
|
|
97
|
-
const PAGE = Utils.FormPage.get(PAGE_JSON, USER_PROFILE.components, { ...USER_PROFILE_DATA });
|
|
98
|
-
const ON_ACTION = (action, patch, onError) => {
|
|
99
|
-
console.log('action invoked', action, patch);
|
|
100
|
-
};
|
|
101
|
-
return (
|
|
102
|
-
<HooksContextProvider>
|
|
103
|
-
<ValidationContextProvider>
|
|
104
|
-
<FormPage page={PAGE} onAction={ON_ACTION} />
|
|
105
|
-
</ValidationContextProvider>
|
|
106
|
-
</HooksContextProvider>
|
|
107
|
-
);
|
|
108
|
-
}}
|
|
109
|
-
</Story>
|
|
110
|
-
</Canvas>
|
|
111
|
-
|
|
112
|
-
### Without editable controls
|
|
113
|
-
|
|
114
|
-
<Canvas>
|
|
115
|
-
<Story name="Without editable controls">
|
|
116
|
-
{() => {
|
|
117
|
-
const PAGE_JSON = USER_PROFILE.pages.find(p => p.id === 'add-or-change-line-manager');
|
|
118
|
-
const PAGE = Utils.FormPage.get(PAGE_JSON, USER_PROFILE.components, { ...USER_PROFILE_DATA });
|
|
119
|
-
const ON_ACTION = (action, patch, onError) => {
|
|
120
|
-
console.log('action invoked', action, patch);
|
|
121
|
-
};
|
|
122
|
-
return (
|
|
123
|
-
<HooksContextProvider>
|
|
124
|
-
<ValidationContextProvider>
|
|
125
|
-
<FormPage page={PAGE} onAction={ON_ACTION} />
|
|
126
|
-
</ValidationContextProvider>
|
|
127
|
-
</HooksContextProvider>
|
|
128
|
-
);
|
|
129
|
-
}}
|
|
130
|
-
</Story>
|
|
131
|
-
</Canvas>
|