diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/current-spouse-marriage-history-details/additionalQuestionsView.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/current-spouse-marriage-history-details/additionalQuestionsView.js index bc29eb117c31..c4a5ceaa6ef1 100644 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/current-spouse-marriage-history-details/additionalQuestionsView.js +++ b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/current-spouse-marriage-history-details/additionalQuestionsView.js @@ -1,4 +1,4 @@ -import React from 'react'; +import { generateTransition } from '../../../helpers'; export const schema = { type: 'object', @@ -12,10 +12,8 @@ export const schema = { export const uiSchema = { 'view:additionalQuestionsMessage': { - 'ui:description': ( -

- Now we’ll ask you about each of your spouse’s former marriages. -

+ 'ui:description': generateTransition( + 'Now we’ll ask you about each of your spouse’s former marriages.', ), 'ui:options': { hideOnReview: true, diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/veteran-marriage-history-details/veteranAdditionalQuestionsView.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/veteran-marriage-history-details/veteranAdditionalQuestionsView.js index ca38f7504335..d939f03d23c2 100644 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/veteran-marriage-history-details/veteranAdditionalQuestionsView.js +++ b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-add-a-spouse/veteran-marriage-history-details/veteranAdditionalQuestionsView.js @@ -1,4 +1,4 @@ -import React from 'react'; +import { generateTransition } from '../../../helpers'; export const schema = { type: 'object', @@ -12,10 +12,8 @@ export const schema = { export const uiSchema = { 'view:additionalQuestionsMessage': { - 'ui:description': ( -

- Now we’ll ask you about each of your former marriages. -

+ 'ui:description': generateTransition( + 'Now we’ll ask you about each of your former marriages.', ), 'ui:options': { hideOnReview: true, diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/deceasedDependentArrayPages.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/deceasedDependentArrayPages.js new file mode 100644 index 000000000000..0295efb46ea0 --- /dev/null +++ b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/deceasedDependentArrayPages.js @@ -0,0 +1,262 @@ +import { format, parseISO } from 'date-fns'; +import { capitalize } from 'lodash'; +import { + titleUI, + arrayBuilderItemFirstPageTitleUI, + arrayBuilderYesNoSchema, + arrayBuilderYesNoUI, + arrayBuilderItemSubsequentPageTitleUI, + fullNameNoSuffixUI, + fullNameNoSuffixSchema, + radioUI, + radioSchema, + checkboxGroupUI, + checkboxGroupSchema, + ssnUI, + ssnSchema, + currentOrPastDateUI, + currentOrPastDateSchema, +} from 'platform/forms-system/src/js/web-component-patterns'; +import VaTextInputField from 'platform/forms-system/src/js/web-component-fields/VaTextInputField'; +import VaSelectField from 'platform/forms-system/src/js/web-component-fields/VaSelectField'; +import VaCheckboxField from 'platform/forms-system/src/js/web-component-fields/VaCheckboxField'; +import { + relationshipEnums, + relationshipLabels, + childTypeEnums, + childTypeLabels, +} from './helpers'; +import { customLocationSchema } from '../../helpers'; + +/** @type {ArrayBuilderOptions} */ +export const deceasedDependentOptions = { + arrayPath: 'deaths', + nounSingular: 'dependent', + nounPlural: 'dependents', + required: true, + isItemIncomplete: item => + !item?.fullName?.first || + !item?.fullName?.last || + !item?.ssn || + !item?.birthDate || + !item?.dependentType || + !item?.dependentDeathLocation?.location?.city || + !item?.dependentDeathDate || + (item?.dependentDeathLocation?.outsideUsa === false && + !item?.dependentDeathLocation?.location?.state), + maxItems: 7, + text: { + getItemName: item => + `${capitalize(item.fullName?.first) || ''} ${capitalize( + item.fullName?.last, + ) || ''}`, + cardDescription: item => { + const birthDate = item?.birthDate + ? format(parseISO(item.birthDate), 'MM/dd/yyyy') + : 'Unknown'; + const dependentDeathDate = item?.dependentDeathDate + ? format(parseISO(item.dependentDeathDate), 'MM/dd/yyyy') + : 'Unknown'; + + return `${birthDate} - ${dependentDeathDate}`; + }, + }, +}; + +/** @returns {PageSchema} */ +export const deceasedDependentIntroPage = { + uiSchema: { + ...titleUI({ + title: 'Dependents who have died', + description: + 'In the next few questions, we’ll ask you about your dependents who have died. You must add at least one dependent. You may add up to 7 dependents.', + }), + }, + schema: { + type: 'object', + properties: {}, + }, +}; + +/** @returns {PageSchema} */ +export const deceasedDependentSummaryPage = { + uiSchema: { + 'view:completedDependent': arrayBuilderYesNoUI(deceasedDependentOptions, { + title: 'Do you have another deceased dependent to report?', + labels: { + Y: 'Yes, I have another dependent to report', + N: 'No, I don’t have another dependent to report', + }, + }), + }, + schema: { + type: 'object', + properties: { + 'view:completedDependent': arrayBuilderYesNoSchema, + }, + required: ['view:completedDependent'], + }, +}; + +/** @returns {PageSchema} */ +export const deceasedDependentPersonalInfoPage = { + uiSchema: { + ...arrayBuilderItemFirstPageTitleUI({ + title: 'Dependent who has died', + nounSingular: deceasedDependentOptions.nounSingular, + }), + fullName: fullNameNoSuffixUI(), + ssn: { + ...ssnUI('Dependent’s Social Security number'), + 'ui:required': () => true, + }, + birthDate: currentOrPastDateUI({ + title: 'Dependent’s date of birth', + required: () => true, + }), + }, + schema: { + type: 'object', + properties: { + fullName: fullNameNoSuffixSchema, + ssn: ssnSchema, + birthDate: currentOrPastDateSchema, + }, + }, +}; + +/** @returns {PageSchema} */ +export const deceasedDependentTypePage = { + uiSchema: { + ...arrayBuilderItemSubsequentPageTitleUI(({ formData }) => { + const fullName = formData?.fullName || {}; + const { first = '', last = '' } = fullName; + + return first && last + ? `Your relationship to ${capitalize(first)} ${capitalize(last)}` + : 'Your relationship to the deceased dependent'; + }), + dependentType: { + ...radioUI({ + title: 'What was your relationship to the dependent?', + required: () => true, + labels: relationshipLabels, + }), + }, + }, + schema: { + type: 'object', + properties: { + dependentType: radioSchema(relationshipEnums), + }, + }, +}; + +/** @returns {PageSchema} */ +export const deceasedDependentChildTypePage = { + uiSchema: { + ...arrayBuilderItemSubsequentPageTitleUI(({ formData }) => { + const fullName = formData?.fullName || {}; + const { first = '', last = '' } = fullName; + + return first && last + ? `Your relationship to ${capitalize(first)} ${capitalize(last)}` + : 'Your relationship to the deceased dependent'; + }), + childStatus: { + ...checkboxGroupUI({ + title: 'What type of child?', + required: () => true, + labels: childTypeLabels, + }), + }, + }, + schema: { + type: 'object', + properties: { + childStatus: checkboxGroupSchema(childTypeEnums), + }, + }, +}; + +export const deceasedDependentDateOfDeathPage = { + uiSchema: { + ...arrayBuilderItemSubsequentPageTitleUI(({ formData }) => { + const fullName = formData?.fullName || {}; + const { first = '', last = '' } = fullName; + + return first && last + ? `When did ${capitalize(first)} ${capitalize(last)} die?` + : 'When did the dependent die?'; + }), + dependentDeathDate: currentOrPastDateUI({ + title: 'Date of death', + required: () => true, + }), + }, + schema: { + type: 'object', + properties: { + dependentDeathDate: currentOrPastDateSchema, + }, + }, +}; + +export const deceasedDependentLocationOfDeathPage = { + uiSchema: { + ...arrayBuilderItemSubsequentPageTitleUI(({ formData }) => { + const fullName = formData?.fullName || {}; + const { first = '', last = '' } = fullName; + + return first && last + ? `Where did ${capitalize(first)} ${capitalize(last)} die?` + : 'Where did the dependent die?'; + }), + dependentDeathLocation: { + outsideUsa: { + 'ui:title': 'This occurred outside the U.S.', + 'ui:webComponentField': VaCheckboxField, + }, + location: { + city: { + 'ui:title': 'Enter a city', + 'ui:webComponentField': VaTextInputField, + 'ui:required': () => true, + 'ui:errorMessages': { + required: 'Enter a city', + }, + }, + state: { + 'ui:title': 'Select a state', + 'ui:webComponentField': VaSelectField, + 'ui:errorMessages': { + required: 'Enter a state', + }, + 'ui:required': (formData, index) => { + const isEditMode = formData?.dependentDeathLocation?.outsideUsa; + const isAddMode = + formData?.deaths?.[index]?.dependentDeathLocation?.outsideUsa; + + return !isAddMode && !isEditMode; + }, + 'ui:options': { + // NOTE: formData while in Add mode of the array builder + // will be the entire formData object + // formData while in Edit mode will be the entire array item object + // Because of this, index will sometimes be null + // Check for both to cover both array builder modes + hideIf: (formData, index) => + formData?.dependentDeathLocation?.outsideUsa || + formData?.deaths?.[index]?.dependentDeathLocation?.outsideUsa, + }, + }, + }, + }, + }, + schema: { + type: 'object', + properties: { + dependentDeathLocation: customLocationSchema, + }, + }, +}; diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-additional-information/dependentAdditionalInformation.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-additional-information/dependentAdditionalInformation.js deleted file mode 100644 index cd41db73e741..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-additional-information/dependentAdditionalInformation.js +++ /dev/null @@ -1,43 +0,0 @@ -import currentOrPastDateUI from 'platform/forms-system/src/js/definitions/currentOrPastDate'; -import environment from 'platform/utilities/environment'; -import { TASK_KEYS } from '../../../constants'; -import { - isChapterFieldRequired, - PensionIncomeRemovalQuestionTitle, -} from '../../../helpers'; -import { deceasedDependents } from '../../../utilities'; -import DependentViewField from '../../../../components/DependentViewField'; -import { DependentNameHeader } from './helpers'; -import { locationUISchema } from '../../../location-schema'; - -export const schema = - deceasedDependents.properties.dependentAdditionalInformation; - -export const uiSchema = { - deaths: { - 'ui:options': { viewField: DependentViewField }, - items: { - 'ui:title': DependentNameHeader, - date: { - ...currentOrPastDateUI('Date of death'), - 'ui:required': formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - }, - location: locationUISchema( - 'deaths', - 'location', - true, - 'Place of death', - 'reportDeath', - ), - dependentIncome: { - 'ui:options': { - hideIf: () => environment.isProduction(), - hideEmptyValueInReview: true, - }, - 'ui:title': PensionIncomeRemovalQuestionTitle, - 'ui:widget': 'yesNo', - }, - }, - }, -}; diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-additional-information/helpers.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-additional-information/helpers.js deleted file mode 100644 index 32dacc302e60..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-additional-information/helpers.js +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react'; - -export const DependentNameHeader = ({ formData }) => { - const { first, last } = formData.fullName; - return ( -
-

- {first[0].toUpperCase()} - {first.slice(1).toLowerCase()} {last[0].toUpperCase()} - {last.slice(1).toLowerCase()} -

-
- ); -}; diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-information/dependentInformation.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-information/dependentInformation.js deleted file mode 100644 index 29917404ae19..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-information/dependentInformation.js +++ /dev/null @@ -1,136 +0,0 @@ -import merge from 'lodash/merge'; -import currentOrPastDateUI from 'platform/forms-system/src/js/definitions/currentOrPastDate'; -import ssnUI from 'platform/forms-system/src/js/definitions/ssn'; -import { TASK_KEYS } from '../../../constants'; -import { isChapterFieldRequired } from '../../../helpers'; -import DependentViewField from '../../../../components/DependentViewField'; -import { validateName, deceasedDependents } from '../../../utilities'; - -export const schema = deceasedDependents.properties.dependentInformation; - -export const uiSchema = { - deaths: { - 'ui:options': { - viewField: DependentViewField, - itemName: 'Deceased dependent', - keepInPageOnReview: true, - customTitle: ' ', - }, - items: { - 'ui:title': 'Dependent who is deceased', - fullName: { - 'ui:validations': [validateName], - first: { - 'ui:title': 'First name', - 'ui:errorMessages': { - required: 'Enter a first name', - pattern: 'This field accepts alphabetic characters only', - }, - 'ui:required': formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - 'ui:options': { - useDlWrap: true, - }, - }, - middle: { - 'ui:title': 'Middle name', - 'ui:options': { - useDlWrap: true, - hideEmptyValueInReview: true, - }, - 'ui:errorMessages': { - pattern: 'This field accepts alphabetic characters only', - }, - }, - last: { - 'ui:title': 'Last name', - 'ui:errorMessages': { - required: 'Enter a last name', - pattern: 'This field accepts alphabetic characters only', - }, - 'ui:required': formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - 'ui:options': { - useDlWrap: true, - }, - }, - suffix: { - 'ui:title': 'Suffix', - 'ui:options': { - widgetClassNames: 'form-select-medium', - useDlWrap: true, - hideEmptyValueInReview: true, - }, - }, - }, - ssn: { - ...ssnUI, - 'ui:title': 'Dependent’s Social Security number', - 'ui:required': formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - 'ui:options': { - useDlWrap: true, - widgetClassNames: 'usa-input-medium', - }, - }, - birthDate: merge(currentOrPastDateUI('Dependent’s date of birth'), { - 'ui:required': formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - 'ui:options': { - useDlWrap: true, - }, - }), - dependentType: { - 'ui:title': "What was your dependent's status?", - 'ui:widget': 'radio', - 'ui:required': formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - 'ui:options': { - useDlWrap: true, - }, - }, - childStatus: { - 'ui:title': "Child's status (Check all that apply)", - 'ui:required': (formData, index) => - formData.deaths[`${index}`].dependentType === 'CHILD', - 'ui:options': { - expandUnder: 'dependentType', - expandUnderCondition: 'CHILD', - showFieldLabel: true, - keepInPageOnReview: true, - useDlWrap: true, - }, - childUnder18: { - 'ui:title': 'Child under 18', - 'ui:options': { - useDlWrap: true, - }, - }, - stepChild: { - 'ui:title': 'Stepchild', - 'ui:options': { - useDlWrap: true, - }, - }, - adopted: { - 'ui:title': 'Adopted child', - 'ui:options': { - useDlWrap: true, - }, - }, - disabled: { - 'ui:title': 'Child incapable of self-support', - 'ui:options': { - useDlWrap: true, - }, - }, - childOver18InSchool: { - 'ui:title': 'Child 18-23 and in school', - 'ui:options': { - useDlWrap: true, - }, - }, - }, - }, - }, -}; diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-information/helpers.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-information/helpers.js deleted file mode 100644 index a334b36db4af..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/dependent-information/helpers.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; - -export function childInfo({ formData }) { - return ( -
- - {formData.first} {formData.last} - -
-
- ); -} diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/helpers.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/helpers.js new file mode 100644 index 000000000000..83a2d7cf6e6e --- /dev/null +++ b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/helpers.js @@ -0,0 +1,21 @@ +export const relationshipEnums = ['spouse', 'parent', 'child']; +export const relationshipLabels = { + spouse: 'Spouse', + parent: 'Dependent parent', + child: 'Child', +}; + +export const childTypeEnums = [ + 'childUnder18', + 'stepChild', + 'adopted', + 'disabled', + 'childOver18InSchool', +]; +export const childTypeLabels = { + childUnder18: 'Child under 18', + stepChild: 'Stepchild', + adopted: 'Adopted child', + disabled: 'Child incapable of self-support', + childOver18InSchool: 'Child 18-23 and in school', +}; diff --git a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/index.js b/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/index.js deleted file mode 100644 index e8ceaf463670..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/config/chapters/report-dependent-death/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import * as deceasedDependentInformation from './dependent-information/dependentInformation'; -import * as deceasedDependentAdditionalInformation from './dependent-additional-information/dependentAdditionalInformation'; - -export { deceasedDependentInformation, deceasedDependentAdditionalInformation }; diff --git a/src/applications/disability-benefits/686c-674-v2/config/form.js b/src/applications/disability-benefits/686c-674-v2/config/form.js index b5e8d51ef8f7..3e9acb7e5c68 100644 --- a/src/applications/disability-benefits/686c-674-v2/config/form.js +++ b/src/applications/disability-benefits/686c-674-v2/config/form.js @@ -1,5 +1,8 @@ import fullSchema from 'vets-json-schema/dist/686C-674-schema.json'; import environment from 'platform/utilities/environment'; +import { stringifyUrlParams } from '@department-of-veterans-affairs/platform-forms-system/helpers'; +import { getArrayIndexFromPathName } from 'platform/forms-system/src/js/patterns/array-builder/helpers'; +import { arrayBuilderPages } from 'platform/forms-system/src/js/patterns/array-builder'; import FormFooter from 'platform/forms/components/FormFooter'; import { externalServices } from 'platform/monitoring/DowntimeNotification'; import { VA_FORM_IDS } from 'platform/forms/constants'; @@ -17,9 +20,15 @@ import { formerSpouseInformationPartTwo, } from './chapters/report-divorce'; import { - deceasedDependentInformation, - deceasedDependentAdditionalInformation, -} from './chapters/report-dependent-death'; + deceasedDependentOptions, + deceasedDependentIntroPage, + deceasedDependentSummaryPage, + deceasedDependentPersonalInfoPage, + deceasedDependentTypePage, + deceasedDependentChildTypePage, + deceasedDependentDateOfDeathPage, + deceasedDependentLocationOfDeathPage, +} from './chapters/report-dependent-death/deceasedDependentArrayPages'; import { reportChildMarriage } from './chapters/report-marriage-of-child'; import { reportChildStoppedAttendingSchool } from './chapters/report-child-stopped-attending-school'; import { @@ -724,24 +733,81 @@ export const formConfig = { deceasedDependents: { title: 'Information needed to remove a dependent who has died', pages: { - dependentInformation: { - depends: formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - title: 'Report the death of a dependent: Basic information', - path: '686-report-dependent-death', - uiSchema: deceasedDependentInformation.uiSchema, - schema: deceasedDependentInformation.schema, - }, - dependentAdditionalInformation: { - depends: formData => - isChapterFieldRequired(formData, TASK_KEYS.reportDeath), - title: 'Report the death of a dependent: Additional information', - path: '686-report-dependent-death/:index/additional-information', - showPagePerItem: true, - arrayPath: 'deaths', - uiSchema: deceasedDependentAdditionalInformation.uiSchema, - schema: deceasedDependentAdditionalInformation.schema, - }, + ...arrayBuilderPages(deceasedDependentOptions, pageBuilder => ({ + dependentAdditionalInformationIntro: pageBuilder.introPage({ + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death', + uiSchema: deceasedDependentIntroPage.uiSchema, + schema: deceasedDependentIntroPage.schema, + }), + dependentAdditionalInformationSummary: pageBuilder.summaryPage({ + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death/dependent-summary', + uiSchema: deceasedDependentSummaryPage.uiSchema, + schema: deceasedDependentSummaryPage.schema, + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + }), + dependentAdditionalInformationPartOne: pageBuilder.itemPage({ + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death/:index/dependent-information', + uiSchema: deceasedDependentPersonalInfoPage.uiSchema, + schema: deceasedDependentPersonalInfoPage.schema, + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + }), + dependentAdditionalInformationPartTwo: pageBuilder.itemPage({ + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death/:index/child-status', + uiSchema: deceasedDependentTypePage.uiSchema, + schema: deceasedDependentTypePage.schema, + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + onNavForward: ({ + formData, + pathname, + urlParams, + goPath, + goNextPath, + }) => { + if (formData.dependentType !== 'child') { + const index = getArrayIndexFromPathName(pathname); + const urlParamsString = stringifyUrlParams(urlParams) || ''; + goPath( + `/686-report-dependent-death/${index}/date-of-death${urlParamsString}`, + ); + } else { + goNextPath(urlParams); + } + }, + }), + dependentAdditionalInformationPartThree: pageBuilder.itemPage({ + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death/:index/child-type', + uiSchema: deceasedDependentChildTypePage.uiSchema, + schema: deceasedDependentChildTypePage.schema, + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + }), + dependentAdditionalInformationPartFour: pageBuilder.itemPage({ + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death/:index/date-of-death', + uiSchema: deceasedDependentDateOfDeathPage.uiSchema, + schema: deceasedDependentDateOfDeathPage.schema, + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + }), + dependentAdditionalInformationPartFive: pageBuilder.itemPage({ + title: 'Information needed to remove a dependent who has died', + path: '686-report-dependent-death/:index/location-of-death', + uiSchema: deceasedDependentLocationOfDeathPage.uiSchema, + schema: deceasedDependentLocationOfDeathPage.schema, + depends: formData => + isChapterFieldRequired(formData, TASK_KEYS.reportDeath), + }), + })), }, }, diff --git a/src/applications/disability-benefits/686c-674-v2/config/helpers.js b/src/applications/disability-benefits/686c-674-v2/config/helpers.js index 764cf361ff25..6bdb966ecb15 100644 --- a/src/applications/disability-benefits/686c-674-v2/config/helpers.js +++ b/src/applications/disability-benefits/686c-674-v2/config/helpers.js @@ -247,6 +247,10 @@ export const generateHelpText = (text, className = 'vads-u-color--gray') => { return {text}; }; +export const generateTransition = (text, className = 'vads-u-margin-y--6') => { + return

{text}

; +}; + export const generateTitle = text => { return

{text}

; }; diff --git a/src/applications/disability-benefits/686c-674-v2/config/utilities.js b/src/applications/disability-benefits/686c-674-v2/config/utilities.js index 90e95186b166..246fb5ae52a7 100644 --- a/src/applications/disability-benefits/686c-674-v2/config/utilities.js +++ b/src/applications/disability-benefits/686c-674-v2/config/utilities.js @@ -1,6 +1,6 @@ import fullSchema from 'vets-json-schema/dist/686C-674-schema.json'; import _ from 'platform/utilities/data'; -import cloneDeep from 'platform/utilities/data/cloneDeep'; +import cloneDeep from 'lodash/cloneDeep'; import { validateWhiteSpace } from 'platform/forms/validations'; import { filterInactivePageData, @@ -103,7 +103,7 @@ export { export function customTransformForSubmit(formConfig, form) { const payload = cloneDeep(form); // manually delete view:confirmEmail, since in our case we actually want the other view fields - delete payload.data.veteranContactInformation['view:confirmEmail']; + // delete payload.data.veteranContactInformation['view:confirmEmail']; const expandedPages = expandArrayPages( createFormPageList(formConfig), payload.data, diff --git a/src/applications/disability-benefits/686c-674-v2/tests/config/chapters/report-dependent-death/deceasedDependentsArray.unit.spec.js b/src/applications/disability-benefits/686c-674-v2/tests/config/chapters/report-dependent-death/deceasedDependentsArray.unit.spec.js new file mode 100644 index 000000000000..57f3cc34c2d7 --- /dev/null +++ b/src/applications/disability-benefits/686c-674-v2/tests/config/chapters/report-dependent-death/deceasedDependentsArray.unit.spec.js @@ -0,0 +1,477 @@ +import { render } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import { expect } from 'chai'; +import React from 'react'; +import createCommonStore from '@department-of-veterans-affairs/platform-startup/store'; +import { DefinitionTester } from 'platform/testing/unit/schemaform-utils'; +import { $$ } from 'platform/forms-system/src/js/utilities/ui'; +import { deceasedDependentOptions } from '../../../../config/chapters/report-dependent-death/deceasedDependentArrayPages'; +import formConfig from '../../../../config/form'; + +const defaultStore = createCommonStore(); + +// deaths array options + +describe('deceasedDependentOptions', () => { + it('should have the correct base properties', () => { + expect(deceasedDependentOptions.arrayPath).to.equal('deaths'); + expect(deceasedDependentOptions.nounSingular).to.equal('dependent'); + expect(deceasedDependentOptions.nounPlural).to.equal('dependents'); + expect(deceasedDependentOptions.required).to.be.true; + expect(deceasedDependentOptions.maxItems).to.equal(7); + }); + + describe('isItemIncomplete', () => { + it('should return true if any required fields are missing', () => { + const incompleteItem = { + fullName: { first: 'John' }, + ssn: '333445555', + birthDate: '1991-02-19', + dependentType: 'spouse', + dependentDeathLocation: { + location: { city: 'Some City' }, + }, + dependentDeathDate: '1991-01-19', + }; + expect(deceasedDependentOptions.isItemIncomplete(incompleteItem)).to.be + .true; + }); + + it('should return false if all required fields are present', () => { + const completeItem = { + fullName: { first: 'John', last: 'Doe' }, + ssn: '333445555', + birthDate: '1991-02-19', + dependentType: 'spouse', + dependentDeathLocation: { + location: { city: 'Some City' }, + }, + dependentDeathDate: '1991-01-19', + }; + expect(deceasedDependentOptions.isItemIncomplete(completeItem)).to.be + .false; + }); + + it('should return true if state is missing and outsideUsa is false', () => { + const incompleteItem = { + fullName: { first: 'John', last: 'Doe' }, + ssn: '333445555', + birthDate: '1991-02-19', + dependentType: 'spouse', + dependentDeathLocation: { + location: { city: 'Some City' }, + outsideUsa: false, + }, + dependentDeathDate: '1991-01-19', + }; + expect(deceasedDependentOptions.isItemIncomplete(incompleteItem)).to.be + .true; + }); + + it('should return false if state is missing but outsideUsa is true', () => { + const completeItemWithoutState = { + fullName: { first: 'John', last: 'Doe' }, + ssn: '333445555', + birthDate: '1991-02-19', + dependentType: 'spouse', + dependentDeathLocation: { + location: { city: 'Some City' }, + outsideUsa: true, + }, + dependentDeathDate: '1991-01-19', + }; + expect( + deceasedDependentOptions.isItemIncomplete(completeItemWithoutState), + ).to.be.false; + }); + }); + + describe('text.getItemName', () => { + it('should return the full name of the item', () => { + const item = { + fullName: { first: 'John', last: 'Doe' }, + }; + expect(deceasedDependentOptions.text.getItemName(item)).to.equal( + 'John Doe', + ); + }); + + it('should return an empty string if first or last name is missing', () => { + const incompleteItem = { fullName: { first: 'John' } }; + expect( + deceasedDependentOptions.text.getItemName(incompleteItem), + ).to.equal('John '); + + const missingBoth = { fullName: {} }; + expect(deceasedDependentOptions.text.getItemName(missingBoth)).to.equal( + ' ', + ); + }); + }); + + describe('text.cardDescription', () => { + it('should return formatted birth and death dates', () => { + const item = { + birthDate: '1991-02-19', + dependentDeathDate: '1991-01-19', + }; + expect(deceasedDependentOptions.text.cardDescription(item)).to.equal( + '02/19/1991 - 01/19/1991', + ); + }); + + it('should return "Unknown" if birth or death date is missing', () => { + const missingBirthDate = { dependentDeathDate: '1991-01-19' }; + expect( + deceasedDependentOptions.text.cardDescription(missingBirthDate), + ).to.equal('Unknown - 01/19/1991'); + + const missingDeathDate = { birthDate: '1991-02-19' }; + expect( + deceasedDependentOptions.text.cardDescription(missingDeathDate), + ).to.equal('02/19/1991 - Unknown'); + + const missingBoth = {}; + expect( + deceasedDependentOptions.text.cardDescription(missingBoth), + ).to.equal('Unknown - Unknown'); + }); + }); +}); + +// deaths array pages + +const formData = (state = 'CA') => { + return { + 'view:selectable686Options': { + reportDeath: true, + }, + deaths: [ + { + dependentDeathDate: '2023-04-17', + dependentType: 'spouse', + fullName: { + first: 'John', + last: 'Doe', + }, + ssn: '333445555', + birthDate: '1991-02-19', + dependentDeathLocation: { + outsideUsa: false, + location: { + city: 'Some city', + state, + }, + }, + }, + { + dependentDeathDate: '2000-12-14', + dependentType: 'spouse', + ssn: '333445555', + birthDate: '1991-02-19', + dependentDeathLocation: { + outsideUsa: false, + location: { + city: 'Some city', + state, + }, + }, + }, + { + dependentDeathDate: '2012-10-31', + dependentType: 'child', + ssn: '333445555', + birthDate: '2010-02-19', + fullName: { + first: 'Tom', + last: 'Riddle', + }, + dependentDeathLocation: { + outsideUsa: true, + location: { + city: 'Some city', + }, + }, + childStatus: { + childUnder18: true, + adopted: true, + }, + }, + ], + }; +}; + +const arrayPath = 'deaths'; + +describe('686 report death: Introduction page', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationIntro; + + it('should render', () => { + const { container } = render( + + + , + ); + + expect($$('h3', container).length).to.equal(1); + expect($$('span', container).length).to.equal(1); + }); +}); + +describe('686 report death: Summary page', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationSummary; + + it('should render', () => { + const { container } = render( + + + , + ); + + expect($$('va-radio', container).length).to.equal(1); + expect($$('va-radio-option', container).length).to.equal(2); + }); +}); + +describe('686 report death: Dependent information', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationPartOne; + + it('should render', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Dependent who has died/i)).to.not.be.null; + expect($$('va-text-input', container).length).to.equal(4); + expect($$('va-memorable-date', container).length).to.equal(1); + }); +}); + +describe('686 report death: Dependent Type', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationPartTwo; + + it('should render', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Your relationship to John Doe/i)).to.not.be.null; + expect($$('va-radio', container).length).to.equal(1); + expect($$('va-radio-option', container).length).to.equal(3); + }); + + it('should render alternate title if fullName is empty', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Your relationship to the deceased dependent/i)).to.not + .be.null; + expect($$('va-radio', container).length).to.equal(1); + expect($$('va-radio-option', container).length).to.equal(3); + }); +}); + +describe('686 report death: Child Type', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationPartThree; + + it('should render', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Your relationship to John Doe/i)).to.not.be.null; + expect($$('va-checkbox-group', container).length).to.equal(1); + expect($$('va-checkbox', container).length).to.equal(5); + }); + + it('should render alternate title if fullName is empty', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Your relationship to the deceased dependent/i)).to.not + .be.null; + expect($$('va-checkbox-group', container).length).to.equal(1); + expect($$('va-checkbox', container).length).to.equal(5); + }); +}); + +describe('686 report death: Date of Death', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationPartFour; + + it('should render', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/When did John Doe die?/i)).to.not.be.null; + expect($$('va-memorable-date', container).length).to.equal(1); + }); + + it('should render alternate title if fullName is empty', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/When did the dependent die?/i)).to.not.be.null; + expect($$('va-memorable-date', container).length).to.equal(1); + }); +}); + +describe('686 report death: Location of Death', () => { + const { + schema, + uiSchema, + } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformationPartFive; + + it('should render', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Where did John Doe die?/i)).to.not.be.null; + expect($$('va-checkbox', container).length).to.equal(1); + expect($$('va-text-input', container).length).to.equal(1); + expect($$('va-select', container).length).to.equal(1); + }); + + it('should render alternate title if fullName is empty', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Where did the dependent die?/i)).to.not.be.null; + expect($$('va-checkbox', container).length).to.equal(1); + expect($$('va-text-input', container).length).to.equal(1); + expect($$('va-select', container).length).to.equal(1); + }); + + it('should render w/ hidden State selector', () => { + const { container, queryByText } = render( + + + , + ); + + expect(queryByText(/Where did Tom Riddle die?/i)).to.not.be.null; + expect($$('va-checkbox', container).length).to.equal(1); + expect($$('va-text-input', container).length).to.equal(1); + }); +}); diff --git a/src/applications/disability-benefits/686c-674-v2/tests/config/reportDeath.unit.spec.jsx b/src/applications/disability-benefits/686c-674-v2/tests/config/reportDeath.unit.spec.jsx deleted file mode 100644 index ad2e93199afe..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/tests/config/reportDeath.unit.spec.jsx +++ /dev/null @@ -1,171 +0,0 @@ -import React from 'react'; -import { expect } from 'chai'; -import sinon from 'sinon'; -import { mount } from 'enzyme'; - -import { - DefinitionTester, - fillData, - selectCheckbox, - selectRadio, -} from 'platform/testing/unit/schemaform-utils.jsx'; -import { changeDropdown } from 'platform/testing/unit/helpers'; -import formConfig from '../../config/form'; - -describe('686 report dependent death', () => { - const { - schema, - uiSchema, - } = formConfig.chapters.deceasedDependents.pages.dependentInformation; - - const formData = { - 'view:selectable686Options': { - reportDeath: true, - }, - }; - - it('should render', () => { - const form = mount( - , - ); - expect(form.find('input').length).to.equal(8); - expect(form.find('select').length).to.equal(2); - form.unmount(); - }); - - it('should not submit an empty form', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(5); - expect(onSubmit.called).to.be.false; - form.unmount(); - }); - - it('select spouse as dependentType', () => { - const form = mount( - , - ); - selectRadio(form, 'root_deaths_0_dependentType', 'SPOUSE'); - expect(form.find('input').length).to.equal(8); - form.unmount(); - }); - - it('select dependent parent as dependentType', () => { - const form = mount( - , - ); - selectRadio(form, 'root_deaths_0_dependentType', 'DEPENDENT_PARENT'); - expect(form.find('input').length).to.equal(8); - form.unmount(); - }); - - it('should expand child options if dependentType is child', () => { - const form = mount( - , - ); - selectRadio(form, 'root_deaths_0_dependentType', 'CHILD'); - expect(form.find('input').length).to.equal(13); - form.unmount(); - }); - - it('should submit a valid form with a dependent spouse', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - // dependent type - selectRadio(form, 'root_deaths_0_dependentType', 'SPOUSE'); - fillData(form, 'input#root_deaths_0_fullName_first', 'Billy'); - fillData(form, 'input#root_deaths_0_fullName_last', 'Bob'); - fillData(form, 'input#root_deaths_0_ssn', '123211234'); - changeDropdown(form, 'select#root_deaths_0_birthDateMonth', 1); - changeDropdown(form, 'select#root_deaths_0_birthDateDay', 1); - fillData(form, 'input#root_deaths_0_birthDateYear', '2010'); - - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(0); - expect(onSubmit.called).to.be.true; - form.unmount(); - }); - - it('should submit a valid form with a dependent child', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - // dependent type - selectRadio(form, 'root_deaths_0_dependentType', 'CHILD'); - selectCheckbox(form, 'root_deaths_0_childStatus_childUnder18', true); - fillData(form, 'input#root_deaths_0_fullName_first', 'Billy'); - fillData(form, 'input#root_deaths_0_fullName_last', 'Bob'); - fillData(form, 'input#root_deaths_0_ssn', '123211234'); - changeDropdown(form, 'select#root_deaths_0_birthDateMonth', 1); - changeDropdown(form, 'select#root_deaths_0_birthDateDay', 1); - fillData(form, 'input#root_deaths_0_birthDateYear', '2010'); - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(0); - expect(onSubmit.called).to.be.true; - form.unmount(); - }); - - it('should not submit when child is selected without any subtypes', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - // dependent type - selectRadio(form, 'root_deaths_0_dependentType', 'CHILD'); - - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(5); - expect(onSubmit.called).to.be.false; - form.unmount(); - }); -}); diff --git a/src/applications/disability-benefits/686c-674-v2/tests/config/reportDeathAdditionalInformation.unit.spec.jsx b/src/applications/disability-benefits/686c-674-v2/tests/config/reportDeathAdditionalInformation.unit.spec.jsx deleted file mode 100644 index 67b0568e8b41..000000000000 --- a/src/applications/disability-benefits/686c-674-v2/tests/config/reportDeathAdditionalInformation.unit.spec.jsx +++ /dev/null @@ -1,121 +0,0 @@ -import React from 'react'; -import { expect } from 'chai'; -import sinon from 'sinon'; -import { mount } from 'enzyme'; - -import { - DefinitionTester, - fillData, - selectCheckbox, -} from 'platform/testing/unit/schemaform-utils.jsx'; -import { changeDropdown } from 'platform/testing/unit/helpers'; -import formConfig from '../../config/form'; - -describe('686 report dependent death additional information', () => { - const { - schema, - uiSchema, - arrayPath, - } = formConfig.chapters.deceasedDependents.pages.dependentAdditionalInformation; - - const formData = { - 'view:selectable686Options': { - reportDeath: true, - }, - deaths: [ - { - fullName: { - first: 'Adam', - last: 'Hubers', - }, - }, - ], - }; - - it('should render', () => { - const form = mount( - , - ); - expect(form.find('input').length).to.equal(5); - form.unmount(); - }); - - it('should not submit an empty form', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(3); - expect(onSubmit.called).to.be.false; - form.unmount(); - }); - - it('should submit a form with the required fields filled out', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - changeDropdown(form, 'select#root_dateMonth', 1); - changeDropdown(form, 'select#root_dateDay', 1); - fillData(form, 'input#root_dateYear', '2000'); - changeDropdown(form, 'select#root_dateMonth', 1); - changeDropdown(form, 'select#root_location_state', 'CA'); - fillData(form, 'input#root_location_city', 'Someplace'); - - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(0); - expect(onSubmit.called).to.be.true; - form.unmount(); - }); - - it('should submit a form with a location of death outside US', () => { - const onSubmit = sinon.spy(); - const form = mount( - , - ); - changeDropdown(form, 'select#root_dateMonth', 1); - changeDropdown(form, 'select#root_dateDay', 1); - fillData(form, 'input#root_dateYear', '2000'); - changeDropdown(form, 'select#root_dateMonth', 1); - selectCheckbox(form, 'root_location_isOutsideUs', true); - changeDropdown(form, 'select#root_location_country', 'AFG'); - fillData(form, 'input#root_location_city', 'Someplace'); - - form.find('form').simulate('submit'); - expect(form.find('.usa-input-error').length).to.equal(0); - expect(onSubmit.called).to.be.true; - form.unmount(); - }); -}); diff --git a/src/applications/disability-benefits/686c-674-v2/tests/e2e/686C-674-ancilliary.cypress.spec.js b/src/applications/disability-benefits/686c-674-v2/tests/e2e/686C-674-ancilliary.cypress.spec.js index f98c559b0d25..e7683bcab01c 100644 --- a/src/applications/disability-benefits/686c-674-v2/tests/e2e/686C-674-ancilliary.cypress.spec.js +++ b/src/applications/disability-benefits/686c-674-v2/tests/e2e/686C-674-ancilliary.cypress.spec.js @@ -105,19 +105,6 @@ const testConfig = createTestConfig( cy.get('.usa-button-primary').click(); }); }, - - '686-report-dependent-death/0/additional-information': ({ - afterHook, - }) => { - afterHook(() => { - cy.get('#root_dateMonth').select('January'); - cy.get('#root_dateDay').select('1'); - cy.get('#root_dateYear').type('1991'); - cy.get('#root_location_state').select('Alabama'); - cy.get('#root_location_city').type('city'); - cy.get('.usa-button-primary').click(); - }); - }, }, }, diff --git a/src/applications/disability-benefits/686c-674-v2/tests/e2e/fixtures/ancilliary-flows.json b/src/applications/disability-benefits/686c-674-v2/tests/e2e/fixtures/ancilliary-flows.json index ffef58e575ea..d2008a2ab1b1 100644 --- a/src/applications/disability-benefits/686c-674-v2/tests/e2e/fixtures/ancilliary-flows.json +++ b/src/applications/disability-benefits/686c-674-v2/tests/e2e/fixtures/ancilliary-flows.json @@ -17,16 +17,32 @@ "dateMarried": "2008-04-05" } ], + "view:completedDependent": false, "deaths": [ - { - "date": "2020-05-09", - "location": { "isOutsideUs": false, "state": "GA", "city": "asdfdsa" }, - "fullName": { "first": "Jane", "last": "Doe" }, - "ssn": "123321234", - "birthDate": "1991-04-05", - "dependentType": "DEPENDENT_PARENT" - } - ], + { + "dependentDeathLocation": { + "outsideUsa": false, + "location": { + "city": "Fakesville", + "state": "AK" + } + }, + "dependentDeathDate": "1991-01-19", + "childStatus": { + "childUnder18": false, + "stepChild": true, + "disabled": false, + "childOver18InSchool": true + }, + "dependentType": "child", + "fullName": { + "first": "Tom", + "last": "Riddle" + }, + "ssn": "333445555", + "birthDate": "1991-01-19" + } + ], "stepChildren": [ { "supportingStepchild": true,