@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CheckYourAnswers/Answer.js +18 -7
- package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
- package/dist/components/CollectionPage/CollectionPage.js +15 -10
- package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
- package/dist/components/FormComponent/Collection.js +91 -48
- package/dist/components/FormComponent/Collection.scss +2 -1
- package/dist/components/FormComponent/Collection.test.js +807 -0
- package/dist/components/FormComponent/Container.js +35 -16
- package/dist/components/FormComponent/Container.test.js +370 -0
- package/dist/components/FormComponent/FormComponent.js +39 -13
- package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
- package/dist/components/FormComponent/FormComponent.test.js +226 -0
- package/dist/components/FormComponent/helpers/addLabel.js +5 -4
- package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
- package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
- package/dist/components/FormComponent/helpers/index.js +8 -1
- package/dist/components/FormPage/FormPage.js +69 -30
- package/dist/components/FormPage/FormPage.stories.mdx +155 -0
- package/dist/components/FormPage/FormPage.test.js +330 -0
- package/dist/components/FormRenderer/FormRenderer.js +142 -228
- package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
- package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
- package/dist/components/FormRenderer/handlers/index.js +1 -2
- package/dist/components/FormRenderer/handlers/navigate.js +3 -1
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
- package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
- package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
- package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
- package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
- package/dist/components/FormRenderer/helpers/index.js +1 -2
- package/dist/components/FormRenderer/onCYAAction.js +108 -0
- package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
- package/dist/components/FormRenderer/onPageAction.js +145 -0
- package/dist/components/FormRenderer/onPageAction.test.js +678 -0
- package/dist/components/FormRenderer/onTaskAction.js +48 -0
- package/dist/components/FormRenderer/onTaskAction.test.js +217 -0
- package/dist/components/PageActions/ActionButton.js +0 -3
- package/dist/components/PageActions/ActionButton.test.js +93 -0
- package/dist/components/PageActions/PageActions.js +2 -2
- package/dist/components/PageActions/PageActions.stories.mdx +74 -0
- package/dist/components/PageActions/PageActions.test.js +132 -0
- package/dist/components/SummaryList/GroupAction.js +2 -2
- package/dist/components/SummaryList/GroupAction.test.js +80 -0
- package/dist/components/SummaryList/RowAction.js +2 -2
- package/dist/components/SummaryList/RowAction.test.js +80 -0
- package/dist/components/SummaryList/SummaryList.js +29 -12
- package/dist/components/SummaryList/SummaryList.scss +19 -0
- package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
- package/dist/components/SummaryList/SummaryList.test.js +400 -0
- package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
- package/dist/components/SummaryList/SummaryListRow.js +5 -2
- package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
- package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
- package/dist/components/TaskList/Task.js +3 -3
- package/dist/components/TaskList/Task.test.js +167 -0
- package/dist/components/TaskList/TaskList.js +73 -22
- package/dist/components/TaskList/TaskList.stories.mdx +164 -0
- package/dist/components/TaskList/TaskList.test.js +389 -0
- package/dist/components/TaskList/TaskState.js +2 -2
- package/dist/components/TaskList/TaskState.test.js +86 -0
- package/dist/components/index.js +14 -0
- package/dist/context/HooksContext/HooksContext.js +72 -8
- package/dist/context/HooksContext/HooksContext.test.js +44 -0
- package/dist/context/ValidationContext/ValidationContext.js +38 -28
- package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
- package/dist/hooks/useAxios.js +10 -12
- package/dist/hooks/useGetRequest.js +48 -49
- package/dist/hooks/useRefData.js +7 -4
- package/dist/index.js +34 -1
- package/dist/json/addressDetails.json +149 -0
- package/dist/json/areYouACivilServant.json +7 -0
- package/dist/json/firstForm.json +94 -0
- package/dist/json/grade.json +108 -0
- package/dist/json/group.data.json +21 -0
- package/dist/json/group.json +402 -0
- package/dist/json/groupOfRow.json +137 -0
- package/dist/json/groupOfRowData.json +15 -0
- package/dist/json/port.json +346 -0
- package/dist/json/saveAndContinue.json +98 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/taskList.json +265 -0
- package/dist/json/team.json +17351 -0
- package/dist/json/terminal.json +81 -0
- package/dist/json/userProfile.data.json +21 -0
- package/dist/json/userProfile.json +276 -0
- package/dist/models/ComponentTypes.js +8 -0
- package/dist/models/PageAction.js +4 -1
- package/dist/models/TaskStates.js +10 -2
- package/dist/models/index.js +16 -1
- package/dist/setupTests.js +46 -0
- package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
- package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
- package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
- package/dist/utils/Component/addShowWhen.js +44 -0
- package/dist/utils/Component/addShowWhen.test.js +216 -0
- package/dist/utils/Component/applyToComponentTree.js +71 -0
- package/dist/utils/Component/applyToComponentTree.test.js +127 -0
- package/dist/utils/Component/cleanAttributes.js +8 -2
- package/dist/utils/Component/cleanAttributes.test.js +68 -0
- package/dist/utils/Component/elevateNestedComponents.js +4 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
- package/dist/utils/Component/getComponent.js +80 -11
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
- package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
- package/dist/utils/Component/getDefaultValue.js +4 -1
- package/dist/utils/Component/getDefaultValue.test.js +50 -0
- package/dist/utils/Component/index.js +2 -0
- package/dist/utils/Component/isEditable.js +2 -2
- package/dist/utils/Component/isEditable.test.js +43 -0
- package/dist/utils/Component/optionIsSelected.js +22 -0
- package/dist/utils/Component/optionIsSelected.test.js +42 -0
- package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
- package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
- package/dist/utils/Component/showComponent.test.js +156 -0
- package/dist/utils/Component/wrapInFormGroup.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.js +1 -1
- package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
- package/dist/utils/Condition/meetsCondition.js +74 -4
- package/dist/utils/Condition/meetsCondition.test.js +763 -0
- package/dist/utils/Condition/meetsOneCondition.js +1 -1
- package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
- package/dist/utils/Condition/setupConditions.js +6 -3
- package/dist/utils/Condition/setupConditions.test.js +33 -0
- package/dist/utils/Container/getEditableComponents.test.js +135 -0
- package/dist/utils/Container/setupNesting.js +21 -2
- package/dist/utils/Container/setupNesting.test.js +145 -0
- package/dist/utils/Container/showContainer.test.js +178 -0
- package/dist/utils/Data/applyFormula.js +20 -11
- package/dist/utils/Data/applyFormula.test.js +263 -0
- package/dist/utils/Data/getAutocompleteSource.js +6 -2
- package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
- package/dist/utils/Data/getDataPath.test.js +48 -0
- package/dist/utils/Data/getOptions.js +17 -3
- package/dist/utils/Data/getOptions.test.js +140 -0
- package/dist/utils/Data/getSourceData.js +2 -2
- package/dist/utils/Data/getSourceData.test.js +153 -0
- package/dist/utils/Data/refDataToOptions.js +4 -1
- package/dist/utils/Data/refDataToOptions.test.js +196 -0
- package/dist/utils/Data/setDataItem.test.js +110 -0
- package/dist/utils/Data/setupFormData.js +39 -16
- package/dist/utils/Data/setupFormData.test.js +410 -0
- package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
- package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
- package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
- package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
- package/dist/utils/FormPage/getFormPage.js +5 -2
- package/dist/utils/FormPage/getFormPage.test.js +206 -0
- package/dist/utils/FormPage/getFormPages.js +4 -1
- package/dist/utils/FormPage/getFormPages.test.js +97 -0
- package/dist/utils/FormPage/getPageActions.js +8 -4
- package/dist/utils/FormPage/getPageActions.test.js +114 -0
- package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
- package/dist/utils/FormPage/index.js +2 -0
- package/dist/utils/FormPage/showFormPage.js +2 -2
- package/dist/utils/FormPage/showFormPage.test.js +180 -0
- package/dist/utils/FormPage/showFormPageCYA.js +1 -0
- package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
- package/dist/utils/FormPage/useComponent.js +29 -14
- package/dist/utils/FormPage/useComponent.test.js +167 -0
- package/dist/utils/Format/formatData.test.js +45 -0
- package/dist/utils/Format/formatDataForComponent.js +2 -1
- package/dist/utils/Format/formatDataForComponent.test.js +142 -0
- package/dist/utils/Format/formatDataForForm.js +4 -1
- package/dist/utils/Format/formatDataForForm.test.js +81 -0
- package/dist/utils/Format/formatDataForPage.test.js +99 -0
- package/dist/utils/Hub/getFormHub.test.js +105 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
- package/dist/utils/Meta/documents/index.js +2 -2
- package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
- package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
- package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
- package/dist/utils/Operate/getFirstOf.js +31 -0
- package/dist/utils/Operate/getFirstOf.test.js +86 -0
- package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
- package/dist/utils/Operate/persistValueInFormData.js +2 -1
- package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
- package/dist/utils/Operate/runPageOperations.js +3 -1
- package/dist/utils/Operate/runPageOperations.test.js +105 -0
- package/dist/utils/Operate/setValueInFormData.test.js +44 -0
- package/dist/utils/Operate/shouldRun.js +16 -13
- package/dist/utils/Operate/shouldRun.test.js +66 -0
- package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
- package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
- package/dist/utils/Validate/additional/index.js +13 -4
- package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
- package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
- package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
- package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
- package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
- package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
- package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
- package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
- package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
- package/dist/utils/Validate/additional/utils.js +18 -18
- package/dist/utils/Validate/index.js +6 -0
- package/dist/utils/Validate/validateCollection.js +20 -5
- package/dist/utils/Validate/validateCollection.test.js +125 -0
- package/dist/utils/Validate/validateComponent.js +36 -20
- package/dist/utils/Validate/validateComponent.test.js +365 -0
- package/dist/utils/Validate/validateContainer.js +9 -3
- package/dist/utils/Validate/validateContainer.test.js +75 -0
- package/dist/utils/Validate/validateDate.js +4 -3
- package/dist/utils/Validate/validateDate.test.js +114 -0
- package/dist/utils/Validate/validateEmail.js +14 -1
- package/dist/utils/Validate/validateEmail.test.js +74 -0
- package/dist/utils/Validate/validateMultifile.js +32 -0
- package/dist/utils/Validate/validateMultifile.test.js +47 -0
- package/dist/utils/Validate/validatePage.js +12 -6
- package/dist/utils/Validate/validatePage.test.js +472 -0
- package/dist/utils/Validate/validateRegex.js +2 -5
- package/dist/utils/Validate/validateRegex.test.js +42 -0
- package/dist/utils/Validate/validateRequired.js +2 -4
- package/dist/utils/Validate/validateRequired.test.js +63 -0
- package/dist/utils/Validate/validateTextArea.js +37 -0
- package/dist/utils/Validate/validateTextArea.test.js +42 -0
- package/dist/utils/Validate/validateTime.js +2 -2
- package/dist/utils/Validate/validateTime.test.js +59 -0
- package/dist/utils/index.js +4 -1
- package/package.json +35 -50
- package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
- package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
|
@@ -0,0 +1,184 @@
|
|
|
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 FormComponent from './FormComponent';
|
|
9
|
+
|
|
10
|
+
<!-- JSON documents -->
|
|
11
|
+
import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
|
|
12
|
+
import GRADE from '../../json/grade.json';
|
|
13
|
+
import TEAMS from '../../json/team.json';
|
|
14
|
+
import USER_PROFILE_DATA from '../../json/userProfile.data.json';
|
|
15
|
+
import USER_PROFILE from '../../json/userProfile.json';
|
|
16
|
+
|
|
17
|
+
<Meta title="Components/Form component" id="D-FormComponent" component={ FormComponent } decorators={[withMock]} />
|
|
18
|
+
|
|
19
|
+
<Heading size="xl" caption="Components">Form component</Heading>
|
|
20
|
+
|
|
21
|
+
Renders a single component on a form with <Link href="https://ukhomeoffice.github.io/cop-react-components/?path=/docs/d-alert--default-story">COP React components</Link>,
|
|
22
|
+
on the basis of a <Link href="/?path=/docs/f-json-component">JSON</Link> configuration.
|
|
23
|
+
|
|
24
|
+
<Canvas withToolbar>
|
|
25
|
+
<Story name="Default" parameters={{
|
|
26
|
+
mockData: [
|
|
27
|
+
{
|
|
28
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
29
|
+
method: 'GET',
|
|
30
|
+
status: 200,
|
|
31
|
+
response: CIVIL_SERVANT
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
35
|
+
method: 'GET',
|
|
36
|
+
status: 200,
|
|
37
|
+
response: GRADE
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
41
|
+
method: 'GET',
|
|
42
|
+
status: 200,
|
|
43
|
+
response: TEAMS
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}}>
|
|
47
|
+
{() => {
|
|
48
|
+
const COMPONENT = {
|
|
49
|
+
...USER_PROFILE.components.find(c => c.id === 'areYouACivilServant'),
|
|
50
|
+
data: {
|
|
51
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const ON_CHANGE = ({ target }) => {
|
|
55
|
+
// Do something with the target here.
|
|
56
|
+
};
|
|
57
|
+
return (
|
|
58
|
+
<HooksContextProvider>
|
|
59
|
+
<ValidationContextProvider>
|
|
60
|
+
<FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
|
|
61
|
+
</ValidationContextProvider>
|
|
62
|
+
</HooksContextProvider>
|
|
63
|
+
);
|
|
64
|
+
}}
|
|
65
|
+
</Story>
|
|
66
|
+
</Canvas>
|
|
67
|
+
|
|
68
|
+
<Details summary="Properties" className="no-indent">
|
|
69
|
+
<ArgsTable of={ FormComponent } />
|
|
70
|
+
</Details>
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Variants
|
|
74
|
+
### `autocomplete`
|
|
75
|
+
<Canvas>
|
|
76
|
+
<Story name="Autocomplete" parameters={{
|
|
77
|
+
mockData: [
|
|
78
|
+
{
|
|
79
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
80
|
+
method: 'GET',
|
|
81
|
+
status: 200,
|
|
82
|
+
response: CIVIL_SERVANT
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
86
|
+
method: 'GET',
|
|
87
|
+
status: 200,
|
|
88
|
+
response: GRADE
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
92
|
+
method: 'GET',
|
|
93
|
+
status: 200,
|
|
94
|
+
response: TEAMS
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}}>
|
|
98
|
+
{() => {
|
|
99
|
+
const COMPONENT = {
|
|
100
|
+
...USER_PROFILE.components.find(c => c.id === 'team'),
|
|
101
|
+
data: {
|
|
102
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const ON_CHANGE = ({ target }) => {
|
|
106
|
+
// Do something with the target here.
|
|
107
|
+
};
|
|
108
|
+
return (
|
|
109
|
+
<HooksContextProvider>
|
|
110
|
+
<ValidationContextProvider>
|
|
111
|
+
<FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
|
|
112
|
+
</ValidationContextProvider>
|
|
113
|
+
</HooksContextProvider>
|
|
114
|
+
);
|
|
115
|
+
}}
|
|
116
|
+
</Story>
|
|
117
|
+
</Canvas>
|
|
118
|
+
|
|
119
|
+
### `html`
|
|
120
|
+
|
|
121
|
+
<Canvas>
|
|
122
|
+
<Story name="HTML">
|
|
123
|
+
{() => {
|
|
124
|
+
const COMPONENT = { type: 'html', tagName: 'p', content: 'A paragraph of text to render' };
|
|
125
|
+
const ON_CHANGE = ({ target }) => {
|
|
126
|
+
// Do something with the target here.
|
|
127
|
+
};
|
|
128
|
+
return (
|
|
129
|
+
<HooksContextProvider>
|
|
130
|
+
<ValidationContextProvider>
|
|
131
|
+
<FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
|
|
132
|
+
</ValidationContextProvider>
|
|
133
|
+
</HooksContextProvider>
|
|
134
|
+
);
|
|
135
|
+
}}
|
|
136
|
+
</Story>
|
|
137
|
+
</Canvas>
|
|
138
|
+
|
|
139
|
+
### Unwrapped `autocomplete`
|
|
140
|
+
<Canvas>
|
|
141
|
+
<Story name="Unwrapped autocomplete" parameters={{
|
|
142
|
+
mockData: [
|
|
143
|
+
{
|
|
144
|
+
url: `${USER_PROFILE_DATA.urls.refData}/areYouACivilServant`,
|
|
145
|
+
method: 'GET',
|
|
146
|
+
status: 200,
|
|
147
|
+
response: CIVIL_SERVANT
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
url: `${USER_PROFILE_DATA.urls.refData}/grade`,
|
|
151
|
+
method: 'GET',
|
|
152
|
+
status: 200,
|
|
153
|
+
response: GRADE
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`,
|
|
157
|
+
method: 'GET',
|
|
158
|
+
status: 200,
|
|
159
|
+
response: TEAMS
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}}>
|
|
163
|
+
{() => {
|
|
164
|
+
const COMPONENT = {
|
|
165
|
+
...USER_PROFILE.components.find(c => c.id === 'team'),
|
|
166
|
+
id: 'team2',
|
|
167
|
+
fieldId: 'team2',
|
|
168
|
+
data: {
|
|
169
|
+
url: `${USER_PROFILE_DATA.urls.refData}/team`
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const ON_CHANGE = ({ target }) => {
|
|
173
|
+
// Do something with the target here.
|
|
174
|
+
};
|
|
175
|
+
return (
|
|
176
|
+
<HooksContextProvider>
|
|
177
|
+
<ValidationContextProvider>
|
|
178
|
+
<FormComponent component={COMPONENT} value={''} wrap={false} onChange={ON_CHANGE} />
|
|
179
|
+
</ValidationContextProvider>
|
|
180
|
+
</HooksContextProvider>
|
|
181
|
+
);
|
|
182
|
+
}}
|
|
183
|
+
</Story>
|
|
184
|
+
</Canvas>
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _setupTests = require("../../setupTests");
|
|
6
|
+
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
9
|
+
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); } }
|
|
10
|
+
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); }); }; }
|
|
11
|
+
describe('components', function () {
|
|
12
|
+
describe('FormComponent', function () {
|
|
13
|
+
it('should render a text component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
14
|
+
var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation, container, formGroup, label, hint, input;
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
ID = 'component';
|
|
19
|
+
VALUE = 'Text value';
|
|
20
|
+
COMPONENT = {
|
|
21
|
+
id: ID,
|
|
22
|
+
fieldId: ID,
|
|
23
|
+
type: 'text',
|
|
24
|
+
label: 'Text component',
|
|
25
|
+
hint: 'Text hint'
|
|
26
|
+
};
|
|
27
|
+
ON_CHANGE = function ON_CHANGE() {};
|
|
28
|
+
_renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
29
|
+
"data-testid": ID,
|
|
30
|
+
component: COMPONENT,
|
|
31
|
+
value: VALUE,
|
|
32
|
+
onChange: ON_CHANGE
|
|
33
|
+
})), container = _renderWithValidation.container; // text components are wrapper in a FormGroup by default.
|
|
34
|
+
formGroup = container.childNodes[0];
|
|
35
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
36
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
37
|
+
label = formGroup.childNodes[0];
|
|
38
|
+
expect(label.tagName).toEqual('LABEL');
|
|
39
|
+
expect(label.classList).toContain('govuk-label');
|
|
40
|
+
expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
|
|
41
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
42
|
+
hint = formGroup.childNodes[1];
|
|
43
|
+
expect(hint.tagName).toEqual('DIV');
|
|
44
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
45
|
+
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
46
|
+
input = formGroup.childNodes[2];
|
|
47
|
+
expect(input.tagName).toEqual('INPUT');
|
|
48
|
+
expect(input.classList).toContain('govuk-input');
|
|
49
|
+
expect(input.id).toEqual(ID);
|
|
50
|
+
expect(input.value).toEqual(VALUE);
|
|
51
|
+
case 22:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
54
|
+
}
|
|
55
|
+
}, _callee);
|
|
56
|
+
})));
|
|
57
|
+
it('should render a text component appropriately with wrap turned off', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
58
|
+
var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation2, container, input;
|
|
59
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
60
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
ID = 'component';
|
|
63
|
+
VALUE = 'Text value';
|
|
64
|
+
COMPONENT = {
|
|
65
|
+
id: ID,
|
|
66
|
+
fieldId: ID,
|
|
67
|
+
type: 'text',
|
|
68
|
+
label: 'Text component',
|
|
69
|
+
hint: 'Text hint'
|
|
70
|
+
};
|
|
71
|
+
ON_CHANGE = function ON_CHANGE() {};
|
|
72
|
+
_renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
73
|
+
"data-testid": ID,
|
|
74
|
+
component: COMPONENT,
|
|
75
|
+
wrap: false,
|
|
76
|
+
value: VALUE,
|
|
77
|
+
onChange: ON_CHANGE
|
|
78
|
+
})), container = _renderWithValidation2.container; // With wrap = false, there should be no form group.
|
|
79
|
+
input = container.childNodes[0];
|
|
80
|
+
expect(input.tagName).toEqual('INPUT');
|
|
81
|
+
expect(input.classList).toContain('govuk-input');
|
|
82
|
+
expect(input.id).toEqual(ID);
|
|
83
|
+
expect(input.value).toEqual(VALUE);
|
|
84
|
+
case 10:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context2.stop();
|
|
87
|
+
}
|
|
88
|
+
}, _callee2);
|
|
89
|
+
})));
|
|
90
|
+
it('should render an html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
91
|
+
var ID, COMPONENT, _renderWithValidation3, container, p;
|
|
92
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
93
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
94
|
+
case 0:
|
|
95
|
+
ID = 'component';
|
|
96
|
+
COMPONENT = {
|
|
97
|
+
type: 'html',
|
|
98
|
+
tagName: 'p',
|
|
99
|
+
content: 'HTML content'
|
|
100
|
+
};
|
|
101
|
+
_renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
102
|
+
"data-testid": ID,
|
|
103
|
+
component: COMPONENT
|
|
104
|
+
})), container = _renderWithValidation3.container;
|
|
105
|
+
p = container.childNodes[0];
|
|
106
|
+
expect(p.tagName).toEqual('P');
|
|
107
|
+
expect(p.textContent).toEqual(COMPONENT.content);
|
|
108
|
+
case 6:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context3.stop();
|
|
111
|
+
}
|
|
112
|
+
}, _callee3);
|
|
113
|
+
})));
|
|
114
|
+
it('should render an overridden html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
115
|
+
var hooks, ID, COMPONENT, _renderWithValidation4, container, div;
|
|
116
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
117
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
hooks = {
|
|
120
|
+
onGetComponent: function onGetComponent(config, wrap) {
|
|
121
|
+
return /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
ID = 'component';
|
|
125
|
+
COMPONENT = {
|
|
126
|
+
type: 'html',
|
|
127
|
+
tagName: 'p',
|
|
128
|
+
content: 'HTML content'
|
|
129
|
+
};
|
|
130
|
+
_renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
131
|
+
"data-testid": ID,
|
|
132
|
+
component: COMPONENT
|
|
133
|
+
}), {
|
|
134
|
+
hooks: hooks
|
|
135
|
+
}), container = _renderWithValidation4.container;
|
|
136
|
+
div = container.childNodes[0];
|
|
137
|
+
expect(div.tagName).toEqual('DIV');
|
|
138
|
+
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
|
|
139
|
+
case 7:
|
|
140
|
+
case "end":
|
|
141
|
+
return _context4.stop();
|
|
142
|
+
}
|
|
143
|
+
}, _callee4);
|
|
144
|
+
})));
|
|
145
|
+
it('should render the correct html component when the override returns null', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
146
|
+
var hooks, ID, COMPONENT, _renderWithValidation5, container, p;
|
|
147
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
148
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
hooks = {
|
|
151
|
+
onGetComponent: function onGetComponent() {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
ID = 'component';
|
|
156
|
+
COMPONENT = {
|
|
157
|
+
type: 'html',
|
|
158
|
+
tagName: 'p',
|
|
159
|
+
content: 'HTML content'
|
|
160
|
+
};
|
|
161
|
+
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
162
|
+
"data-testid": ID,
|
|
163
|
+
component: COMPONENT
|
|
164
|
+
}), {
|
|
165
|
+
hooks: hooks
|
|
166
|
+
}), container = _renderWithValidation5.container;
|
|
167
|
+
p = container.childNodes[0];
|
|
168
|
+
expect(p.tagName).toEqual('P');
|
|
169
|
+
expect(p.textContent).toEqual(COMPONENT.content);
|
|
170
|
+
case 7:
|
|
171
|
+
case "end":
|
|
172
|
+
return _context5.stop();
|
|
173
|
+
}
|
|
174
|
+
}, _callee5);
|
|
175
|
+
})));
|
|
176
|
+
it('should render a text component appropriately with interpolated label', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
177
|
+
var ID, VALUE, COMPONENT, DATA, ON_CHANGE, _renderWithValidation6, container, formGroup, label, hint, input;
|
|
178
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
179
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
180
|
+
case 0:
|
|
181
|
+
ID = 'component';
|
|
182
|
+
VALUE = 'Text value'; // eslint-disable-next-line no-template-curly-in-string
|
|
183
|
+
COMPONENT = {
|
|
184
|
+
id: ID,
|
|
185
|
+
fieldId: ID,
|
|
186
|
+
type: 'text',
|
|
187
|
+
label: '${text} Text component',
|
|
188
|
+
cya_label: '${text} Text component',
|
|
189
|
+
hint: 'Text hint'
|
|
190
|
+
};
|
|
191
|
+
DATA = {
|
|
192
|
+
text: 'Interpolated'
|
|
193
|
+
};
|
|
194
|
+
ON_CHANGE = function ON_CHANGE() {};
|
|
195
|
+
_renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
196
|
+
"data-testid": ID,
|
|
197
|
+
component: COMPONENT,
|
|
198
|
+
value: VALUE,
|
|
199
|
+
onChange: ON_CHANGE,
|
|
200
|
+
formData: DATA
|
|
201
|
+
})), container = _renderWithValidation6.container; // text components are wrapper in a FormGroup by default.
|
|
202
|
+
formGroup = container.childNodes[0];
|
|
203
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
204
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
205
|
+
label = formGroup.childNodes[0];
|
|
206
|
+
expect(label.tagName).toEqual('LABEL');
|
|
207
|
+
expect(label.classList).toContain('govuk-label');
|
|
208
|
+
expect(label.textContent).toEqual('Interpolated Text component (optional)');
|
|
209
|
+
expect(label.getAttribute('for')).toEqual(ID);
|
|
210
|
+
hint = formGroup.childNodes[1];
|
|
211
|
+
expect(hint.tagName).toEqual('DIV');
|
|
212
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
213
|
+
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
214
|
+
input = formGroup.childNodes[2];
|
|
215
|
+
expect(input.tagName).toEqual('INPUT');
|
|
216
|
+
expect(input.classList).toContain('govuk-input');
|
|
217
|
+
expect(input.id).toEqual(ID);
|
|
218
|
+
expect(input.value).toEqual(VALUE);
|
|
219
|
+
case 23:
|
|
220
|
+
case "end":
|
|
221
|
+
return _context6.stop();
|
|
222
|
+
}
|
|
223
|
+
}, _callee6);
|
|
224
|
+
})));
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -10,16 +10,17 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
10
10
|
* @param {object} target The target to be updated.
|
|
11
11
|
* @returns The updated target.
|
|
12
12
|
*/
|
|
13
|
-
var addLabel = function addLabel(
|
|
13
|
+
var addLabel = function addLabel(paramTarget, component, data) {
|
|
14
|
+
var target = paramTarget;
|
|
14
15
|
// target.value can be an object in which case use value in object attribute
|
|
15
16
|
var value = _typeof(target.value) === 'object' ? target.value.value : target.value;
|
|
16
17
|
// find the reference data item using the value
|
|
17
18
|
var item = data.find(function (e) {
|
|
18
|
-
return e.id === value;
|
|
19
|
+
return String(e.id) === value;
|
|
19
20
|
});
|
|
20
21
|
// if item is null it means that the target.value can be used as a label otherwise use item.label
|
|
21
|
-
target
|
|
22
|
-
target
|
|
22
|
+
target.label = item === undefined ? target.value : item.label;
|
|
23
|
+
target.component = component.cya_label;
|
|
23
24
|
return target;
|
|
24
25
|
};
|
|
25
26
|
var _default = addLabel;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _models = require("../../../models");
|
|
8
|
+
var SHOULD_HAVE_FIELDSET = [_models.ComponentTypes.RADIOS, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE];
|
|
9
|
+
var _default = function _default(component) {
|
|
10
|
+
// Check to see if this is explicitly set first, as this is efficient.
|
|
11
|
+
if (component.fieldset === true) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return SHOULD_HAVE_FIELDSET.includes(component.type);
|
|
15
|
+
};
|
|
16
|
+
exports.default = _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getComponentFieldSet = _interopRequireDefault(require("./getComponentFieldSet"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('components.FormComponent.helpers.getComponentFieldSet', function () {
|
|
6
|
+
it('should return true for component type radios', function () {
|
|
7
|
+
expect((0, _getComponentFieldSet.default)({
|
|
8
|
+
type: 'radios'
|
|
9
|
+
})).toEqual(true);
|
|
10
|
+
});
|
|
11
|
+
it('should return true for component type checkboxes', function () {
|
|
12
|
+
expect((0, _getComponentFieldSet.default)({
|
|
13
|
+
type: 'checkboxes'
|
|
14
|
+
})).toEqual(true);
|
|
15
|
+
});
|
|
16
|
+
it('should return true for component type date', function () {
|
|
17
|
+
expect((0, _getComponentFieldSet.default)({
|
|
18
|
+
type: 'date'
|
|
19
|
+
})).toEqual(true);
|
|
20
|
+
});
|
|
21
|
+
it('should return false for component type text', function () {
|
|
22
|
+
expect((0, _getComponentFieldSet.default)({
|
|
23
|
+
type: 'text'
|
|
24
|
+
})).toEqual(false);
|
|
25
|
+
});
|
|
26
|
+
it('should return false when component type missing', function () {
|
|
27
|
+
expect((0, _getComponentFieldSet.default)({})).toEqual(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -21,7 +21,14 @@ Object.defineProperty(exports, "getComponentError", {
|
|
|
21
21
|
return _getComponentError.default;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "getComponentFieldSet", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _getComponentFieldSet.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _addLabel = _interopRequireDefault(require("./addLabel"));
|
|
24
31
|
var _getComponentDisabled = _interopRequireDefault(require("./getComponentDisabled"));
|
|
25
32
|
var _getComponentError = _interopRequireDefault(require("./getComponentError"));
|
|
26
|
-
var
|
|
33
|
+
var _getComponentFieldSet = _interopRequireDefault(require("./getComponentFieldSet"));
|
|
27
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|