Skip to content

Commit

Permalink
Merge branch 'main' into tk/edm-177
Browse files Browse the repository at this point in the history
  • Loading branch information
binq authored Oct 4, 2024
2 parents 159575f + 83dc437 commit 097cf9b
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ describe('ConfirmationPageV2', () => {
`You submitted the request on ${date}`,
);
// expect($('va-loading-indicator', container)).to.exist;

const h2s = $$('h2', container);
expect(h2s.length).to.eq(4);
expect(h2s.length).to.eq(5);
expect(h2s.map(el => el.textContent)).to.deep.equal([
// `You submitted your Board Appeal request on ${date}`,
'Request a Board Appeal', // print only header
'Your Board Appeal request submission is in progress',
'What to expect next',
'How to contact us if you have questions',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const otherNamePage = {
...arrayBuilderItemFirstPageTitleUI({
title: 'Previous name',
nounSingular: options.nounSingular,
hasMultipleItemPages: false,
}),
previousFullName: fullNameUI(title => `Previous ${title}`),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const currentEmploymentHistoryPage = {
...arrayBuilderItemFirstPageTitleUI({
title: 'Current employment',
nounSingular: options.nounSingular,
hasMultipleItemPages: false,
}),
jobType: textUI('What kind of work do you currently do?'),
jobHoursWeek: numberUI({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const federalMedicalCenterPage = {
...arrayBuilderItemFirstPageTitleUI({
title: 'Federal medical center',
nounSingular: options.nounSingular,
hasMultipleItemPages: false,
}),
medicalCenter: textUI('Federal medical center'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const previousEmploymentHistoryPage = {
...arrayBuilderItemFirstPageTitleUI({
title: 'Previous employment',
nounSingular: options.nounSingular,
hasMultipleItemPages: false,
}),
jobDate: currentOrPastDateUI('When did you last work?'),
jobType: textUI('What kind of work did you do?'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const vaMedicalCenterPage = {
...arrayBuilderItemFirstPageTitleUI({
title: 'VA medical center',
nounSingular: options.nounSingular,
lowerCase: false,
hasMultipleItemPages: false,
}),
medicalCenter: textUI('VA medical center'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const options = {
nounPlural: 'dependent children',
required: false,
isItemIncomplete: item =>
!item?.fullName ||
!item?.fullName?.first ||
!item.fullName.last ||
!item.childDateOfBirth ||
!item.childPlaceOfBirth ||
(!item.childSocialSecurityNumber && !item['view:noSsn']) ||
Expand Down Expand Up @@ -114,9 +115,9 @@ const birthInformationPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} birth information`
: 'Birth Information',
`${formatFullName(formData.fullName)} birth information`,
undefined,
false,
),
childDateOfBirth: dateOfBirthUI(),
childPlaceOfBirth: {
Expand All @@ -141,9 +142,9 @@ const socialSecurityNumberPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} Social Security information`
: 'Social Security information',
`${formatFullName(formData.fullName)} Social Security information`,
undefined,
false,
),
childSocialSecurityNumber: merge({}, ssnUI(), {
'ui:required': (formData, index) =>
Expand All @@ -168,9 +169,9 @@ const relationshipPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} relationship information`
: 'Relationship information',
`${formatFullName(formData.fullName)} relationship information`,
undefined,
false,
),
childRelationship: radioUI({
title: "What's your relationship?",
Expand All @@ -191,9 +192,9 @@ const attendingSchoolPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} school information`
: 'School information',
`${formatFullName(formData.fullName)} school information`,
undefined,
false,
),
attendingCollege: yesNoUI({
title: 'Is your child in school?',
Expand All @@ -220,9 +221,9 @@ const disabledPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} disabled information`
: 'Disabled information',
`${formatFullName(formData.fullName)} disabled information`,
undefined,
false,
),
disabled: yesNoUI({
title: 'Is your child seriously disabled?',
Expand Down Expand Up @@ -253,9 +254,9 @@ const previouslyMarriedPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} marriage information`
: 'Marriage information',
`${formatFullName(formData.fullName)} marriage information`,
undefined,
false,
),
previouslyMarried: yesNoUI({
title: 'Has your child ever been married?',
Expand All @@ -282,9 +283,9 @@ const inHouseholdPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} household information`
: 'Household information',
`${formatFullName(formData.fullName)} household information`,
undefined,
false,
),
childInHousehold: yesNoUI({
title: 'Does your child live with you?',
Expand All @@ -304,9 +305,9 @@ const addressPage = {
uiSchema: {
...arrayBuilderItemSubsequentPageTitleUI(
({ formData }) =>
formData?.fullName
? `${formatFullName(formData.fullName)} address information`
: 'Address information',
`${formatFullName(formData.fullName)} address information`,
undefined,
false,
),
childAddress: addressUI({
omit: ['isMilitary', 'street3'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,18 @@ export default function ArrayBuilderSummaryPage({
}
};

const resetYesNo = () => {
// We shouldn't persist the 'yes' answer after an item is entered/cancelled
// We should ask the yes/no question again after an item is entered/cancelled
// Since it is required, it shouldn't be left null/undefined
if (props.data[hasItemsKey]) {
props.setData({ ...props.data, [hasItemsKey]: undefined });
}
};

cleanupEmptyItems();
redirectToIntroIfEmpty();
resetYesNo();
}, []);

useEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ export const nounPluralReplaceMePages = arrayBuilderPages( options,
## Web Component Patterns
| Pattern | Description |
|---------|-------------|
| `arrayBuilderItemFirstPageTitleUI` | Should be used instead of `titleUI` for the first item page. Includes adding "Edit" before the title if in edit mode, and showing a `va-alert` warning if an item is required when removing all. |
| `arrayBuilderItemFirstPageTitleUI` | Should be used instead of `titleUI` for the first item page. Includes adding "Edit" before the title if in edit mode, and showing a `va-alert` warning if an item is required when removing all. The description instructions can optionally be hidden when their is only one item page via the `hasMultipleItemPages: false` function parameter. |
| `arrayBuilderItemSubsequentPageTitleUI` | Can be used instead of `titleUI` for subsequent item pages. Includes adding "Edit" before the title if in edit mode. If you need to use a custom title instead, you can try passing `withEditTitle` into your implementation. |
| `withEditTitle` | Used with `arrayBuilderItemFirstPageTitleUI` and `arrayBuilderItemSubsequentPageTitleUI` to show "Edit" before the title, provided as an export for custom use. |
| `arrayBuilderYesNoUI` | Should be used instead of `yesNoUI` for the summary page. Has dynamic text for if the user has 0 items, or more 1+ items, and validation for max items. You can override all text values. |
| `withEditTitle` | Used with `arrayBuilderItemFirstPageTitleUI` and `arrayBuilderItemSubsequentPageTitleUI` to show "Edit" before the title, provided as an export for custom use. The "Edit" title item can be optionally lowercased via the `lowerCase` function parameter. |
| `arrayBuilderYesNoUI` | Should be used instead of `yesNoUI` for the summary page. Has dynamic text for if the user has 0 items, or more 1+ items, and validation for max items. After an item is added/cancelled the yes/no question is reset. You can override all text values. |
### Example `arrayBuilderYesNoUI` Text Overrides:
```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const mockRedux = ({
};
};

describe('ArrayBuilderItemPage', () => {
describe('ArrayBuilderFirstItemPage', () => {
let getArrayUrlSearchParamsStub;
let getIndexStub;

Expand Down Expand Up @@ -81,6 +81,8 @@ describe('ArrayBuilderItemPage', () => {
urlParams = '',
arrayData = [],
title = 'Name and address of employer',
lowerCase = true,
hasMultipleItemPages = true,
required = () => false,
}) {
const setFormData = sinon.spy();
Expand All @@ -102,6 +104,8 @@ describe('ArrayBuilderItemPage', () => {
...arrayBuilderItemFirstPageTitleUI({
title,
nounSingular: 'employer',
lowerCase,
hasMultipleItemPages,
}),
name: {
'ui:title': 'Name of employer',
Expand All @@ -128,7 +132,7 @@ describe('ArrayBuilderItemPage', () => {
required,
});

const { container, getByText } = render(
const { container, queryByText } = render(
<Provider store={mockStore}>
<CustomPage
schema={itemPage.schema}
Expand All @@ -147,37 +151,87 @@ describe('ArrayBuilderItemPage', () => {
</Provider>,
);

return { setFormData, goToPath, getText, container, getByText };
return { setFormData, goToPath, getText, container, queryByText };
}

it('should display correctly with add query parameter', () => {
const { getText, container, getByText } = setupArrayBuilderItemPage({
const { getText, container, queryByText } = setupArrayBuilderItemPage({
title: 'Name and address of employer',
index: 0,
urlParams: '?add=true',
arrayData: [{ name: 'Test' }],
});

expect(getByText('Name and address of employer')).to.exist;
expect(queryByText('Name and address of employer')).to.exist;
expect(container.querySelector('va-button[text="cancelAddButtonText"]')).to
.exist;
});

it('should display correctly with edit query parameter', () => {
const { getText, container, getByText } = setupArrayBuilderItemPage({
const { getText, container, queryByText } = setupArrayBuilderItemPage({
title: 'Name and address of employer',
index: 0,
urlParams: '?edit=true',
arrayData: [{ name: 'Test' }],
});

expect(getByText('Edit name and address of employer')).to.exist;
expect(queryByText('Edit name and address of employer')).to.exist;
expect(container.querySelector('va-button[text="cancelEditButtonText"]')).to
.exist;
});

it('should display correctly with edit query parameter is not lowercased', () => {
const { getText, container, queryByText } = setupArrayBuilderItemPage({
title: 'John Doe employer information',
lowerCase: false,
index: 0,
urlParams: '?edit=true',
arrayData: [{ name: 'Test' }],
});

expect(queryByText('Edit John Doe employer information')).to.exist;
expect(container.querySelector('va-button[text="cancelEditButtonText"]')).to
.exist;
});

it('should display correctly when hasMultipleItemPages is true', () => {
const { container, queryByText } = setupArrayBuilderItemPage({
title: 'Multiple page employer',
index: 0,
urlParams: '?edit=true',
arrayData: [{ name: 'Employer One' }],
hasMultipleItemPages: true,
});

expect(
queryByText(
'We’ll take you through each of the sections of this employer for you to review and edit',
),
).to.exist;
expect(container.querySelector('va-button[text="cancelEditButtonText"]')).to
.exist;
});

it('should display correctly when hasMultipleItemPages is false', () => {
const { container, queryByText } = setupArrayBuilderItemPage({
title: 'Single page employer',
index: 0,
urlParams: '?edit=true',
arrayData: [{ name: 'Employer One' }],
hasMultipleItemPages: false,
});

expect(
queryByText(
'We’ll take you through each of the sections of this employer for you to review and edit',
),
).to.not.exist;
expect(container.querySelector('va-button[text="cancelEditButtonText"]')).to
.exist;
});

it('should navigate away if not edit or add', () => {
const { goToPath, container, getByText } = setupArrayBuilderItemPage({
const { goToPath, container, queryByText } = setupArrayBuilderItemPage({
title: 'Name and address of employer',
index: 0,
urlParams: '',
Expand Down
Loading

0 comments on commit 097cf9b

Please sign in to comment.