Skip to content

Commit

Permalink
VACMS-16914: DUW Add prev-application-type question (#29288)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskim2311 authored Apr 23, 2024
1 parent 6a355ea commit d7dbc93
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
QUESTION_MAP,
RESPONSES,
SHORT_NAME_MAP,
} from '../../../constants/question-data-map';
import RadioGroup from './shared/RadioGroup';
import { updatePrevApplicationType } from '../../../actions';
import { pageSetup } from '../../../utilities/page-setup';
import { ROUTES } from '../../../constants';

const PrevApplicationType = ({
formResponses,
setPrevApplicationType,
router,
viewedIntroPage,
}) => {
const [formError, setFormError] = useState(false);
const shortName = SHORT_NAME_MAP.PREV_APPLICATION_TYPE;
const H1 = QUESTION_MAP[shortName];
const prevApplicationType = formResponses[shortName];
const {
PREV_APPLICATION_TYPE_1,
PREV_APPLICATION_TYPE_2,
PREV_APPLICATION_TYPE_3A,
PREV_APPLICATION_TYPE_3B,
PREV_APPLICATION_TYPE_4,
} = RESPONSES;

const prevApplicationTypeOptions = [
PREV_APPLICATION_TYPE_1,
PREV_APPLICATION_TYPE_2,
PREV_APPLICATION_TYPE_3A,
PREV_APPLICATION_TYPE_3B,
PREV_APPLICATION_TYPE_4,
].filter(option => {
if (
[RESPONSES.NAVY, RESPONSES.MARINE_CORPS].includes(
formResponses.SERVICE_BRANCH,
)
) {
return option !== PREV_APPLICATION_TYPE_3A;
}
return option !== PREV_APPLICATION_TYPE_3B;
});

useEffect(
() => {
pageSetup(H1);
},
[H1],
);

useEffect(
() => {
if (!viewedIntroPage) {
router.push(ROUTES.HOME);
}
},
[router, viewedIntroPage],
);

return (
<RadioGroup
formError={formError}
formResponses={formResponses}
formValue={prevApplicationType}
H1={H1}
responses={prevApplicationTypeOptions}
router={router}
setFormError={setFormError}
shortName={shortName}
testId="duw-prev_application_type"
valueSetter={setPrevApplicationType}
/>
);
};

PrevApplicationType.propTypes = {
formResponses: PropTypes.object,
router: PropTypes.shape({
push: PropTypes.func,
}),
setPrevApplicationType: PropTypes.func,
viewedIntroPage: PropTypes.bool,
};

const mapStateToProps = state => ({
formResponses: state?.dischargeUpgradeWizard?.duwForm?.form,
viewedIntroPage: state?.dischargeUpgradeWizard?.duwForm?.viewedIntroPage,
});

const mapDispatchToProps = {
setPrevApplicationType: updatePrevApplicationType,
};

export default connect(
mapStateToProps,
mapDispatchToProps,
)(PrevApplicationType);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const yearResponses = range(currentYear - 1992).map(i => {
const year = currentYear - i;
return year.toString();
});

const {
ARMY,
NAVY,
Expand All @@ -24,6 +25,7 @@ const {
COURT_MARTIAL_1,
COURT_MARTIAL_2,
COURT_MARTIAL_3,
// INTENTION_2,
PREV_APPLICATION_1,
PREV_APPLICATION_2,
// DISCHARGE_TYPE_1,
Expand All @@ -34,6 +36,8 @@ const {
PREV_APPLICATION_YEAR_2A,
PREV_APPLICATION_YEAR_2B,
PREV_APPLICATION_YEAR_2C,
// PREV_APPLICATION_TYPE_3A,
// PREV_APPLICATION_TYPE_3B,
} = RESPONSES;

export const DISPLAY_CONDITIONS = Object.freeze({
Expand Down Expand Up @@ -108,6 +112,13 @@ export const DISPLAY_CONDITIONS = Object.freeze({
REASON: [REASON_8],
},
1: {
SERVICE_BRANCH: [ARMY, NAVY, AIR_FORCE, COAST_GUARD, MARINE_CORPS],
DISCHARGE_YEAR: yearResponses,
DISCHARGE_MONTH: [],
REASON: [REASON_5, REASON_6, REASON_7],
PREV_APPLICATION: [PREV_APPLICATION_1],
},
2: {
SERVICE_BRANCH: [ARMY, NAVY, AIR_FORCE, COAST_GUARD, MARINE_CORPS],
DISCHARGE_YEAR: yearResponses,
DISCHARGE_MONTH: [],
Expand All @@ -119,14 +130,20 @@ export const DISPLAY_CONDITIONS = Object.freeze({
REASON_5,
REASON_6,
REASON_7,
REASON_8,
],
PREV_APPLICATION_YEAR: [
PREV_APPLICATION_YEAR_2A,
PREV_APPLICATION_YEAR_2B,
PREV_APPLICATION_YEAR_2C,
],
},
3: {
PREV_APPLICATION_YEAR: [
PREV_APPLICATION_YEAR_2A,
PREV_APPLICATION_YEAR_2B,
PREV_APPLICATION_YEAR_2C,
],
},
},
},
PRIOR_SERVICE: {
Expand Down Expand Up @@ -167,6 +184,13 @@ export const DISPLAY_CONDITIONS = Object.freeze({
PREV_APPLICATION_YEAR_1C,
],
},
2: {
SERVICE_BRANCH: [ARMY, NAVY, AIR_FORCE, COAST_GUARD, MARINE_CORPS],
DISCHARGE_YEAR: yearResponses,
DISCHARGE_MONTH: [],
REASON: [REASON_1, REASON_2, REASON_3, REASON_4, REASON_6, REASON_7],
DISCHARGE_TYPE: [DISCHARGE_TYPE_2],
},
},
},
});
24 changes: 19 additions & 5 deletions src/applications/discharge-wizard/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export const ROUTES = Object.freeze({
COURT_MARTIAL: 'court-martial',
INTENTION: 'intention',
PREV_APPLICATION: 'prev-application',
PREV_APPLICATION_TYPE_A: 'prev-application-type',
PREV_APPLICATION_TYPE: 'prev-application-type',
PREV_APPLICATION_YEAR: 'prev-application-year',
PRIOR_SERVICE: 'prior-service',
Expand All @@ -149,14 +148,29 @@ export const questionsToClearMap = Object.freeze({
SHORT_NAME_MAP.DISCHARGE_TYPE,
SHORT_NAME_MAP.COURT_MARTIAL,
SHORT_NAME_MAP.INTENTION,
SHORT_NAME_MAP.PREVIOUS_APPLICATION,
SHORT_NAME_MAP.PREV_APPLICATION,
SHORT_NAME_MAP.PREV_APPLICATION_TYPE,
SHORT_NAME_MAP.PREV_APPLICATION_YEAR,
SHORT_NAME_MAP.PRIOR_SERVICE,
],
DISCHARGE_TYPE: [],
COURT_MARTIAL: [],
INTENTION: [],
PREV_APPLICATION: [],
PREV_APPLICATION_TYPE: [],
PREV_APPLICATION_YEAR: [],
PREV_APPLICATION: [
SHORT_NAME_MAP.PREV_APPLICATION_TYPE,
SHORT_NAME_MAP.PREV_APPLICATION_YEAR,
SHORT_NAME_MAP.PRIOR_SERVICE,
SHORT_NAME_MAP.FAILURE_TO_EXHAUST,
],
PREV_APPLICATION_TYPE: [
SHORT_NAME_MAP.PRIOR_SERVICE,
SHORT_NAME_MAP.FAILURE_TO_EXHAUST,
],
PREV_APPLICATION_YEAR: [
SHORT_NAME_MAP.PREV_APPLICATION_TYPE,
SHORT_NAME_MAP.FAILURE_TO_EXHAUST,
SHORT_NAME_MAP.PRIOR_SERVICE,
],
PRIOR_SERVICE: [],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export const QUESTION_MAP = Object.freeze({
COURT_MARTIAL: 'Was your discharge the outcome of a general court-martial?',
PREV_APPLICATION:
'Have you previously applied for and been denied a discharge upgrade for this period of service?',
PREV_APPLICATION_TYPE:
'What type of application did you make to upgrade your discharge previously?',
PREV_APPLICATION_TYPE: 'How did you apply for a discharge upgrade last time?',
PREV_APPLICATION_YEAR: 'What year did you apply for a discharge upgrade?',
PRIOR_SERVICE:
'Did you complete a period of service in which your character of service was Honorable or General Under Honorable Conditions?',
Expand All @@ -23,14 +22,14 @@ export const SHORT_NAME_MAP = Object.freeze({
DISCHARGE_YEAR: 'DISCHARGE_YEAR',
DISCHARGE_MONTH: 'DISCHARGE_MONTH',
REASON: 'REASON',
// PREV_APPLICATION_TYPE_A: 'PREV_APPLICATION_TYPE',
DISCHARGE_TYPE: 'DISCHARGE_TYPE',
INTENTION: 'INTENTION',
COURT_MARTIAL: 'COURT_MARTIAL',
PREV_APPLICATION: 'PREV_APPLICATION',
PREV_APPLICATION_YEAR: 'PREV_APPLICATION_YEAR',
PREV_APPLICATION_TYPE: 'PREV_APPLICATION_TYPE',
PRIOR_SERVICE: 'PRIOR_SERVICE',
FAILURE_TO_EXHAUST: 'FAILURE_TO_EXHAUST',
});

export const RESPONSES = Object.freeze({
Expand Down Expand Up @@ -68,7 +67,7 @@ export const RESPONSES = Object.freeze({
PREV_APPLICATION_TYPE_1:
'I applied to a Discharge Review Board (DRB) for a Documentary Review',
PREV_APPLICATION_TYPE_2:
'I applied to a Discharge Review Board (DRB) for a Personal Appearance Review in Washington, DC',
'I applied to a Discharge Review Board (DRB) for a Personal Appearance Review',
PREV_APPLICATION_TYPE_3A:
'I applied to a Board for Correction of Military Records (BCMR)',
PREV_APPLICATION_TYPE_3B:
Expand Down
4 changes: 2 additions & 2 deletions src/applications/discharge-wizard/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Reason from './components/v2/questions/Reason';
import DischargeType from './components/v2/questions/DischargeType';
import CourtMartial from './components/v2/questions/CourtMartial';
import Intention from './components/v2/questions/Intention';
// import PrevApplicationType from './components/v2/questions/PrevApplicationType';
import PrevApplicationType from './components/v2/questions/PrevApplicationType';
import PrevApplication from './components/v2/questions/PrevApplication';
import PrevApplicationYear from './components/v2/questions/PrevApplicationYear';
import PriorService from './components/v2/questions/PriorService';
Expand All @@ -39,7 +39,7 @@ const envChildRoutes = environment.isProduction()
{ path: 'discharge-type', component: DischargeType },
{ path: 'court-martial', component: CourtMartial },
{ path: 'intention', component: Intention },
// { path: 'prev-application-type', component: PrevApplicationType },
{ path: 'prev-application-type', component: PrevApplicationType },
{ path: 'prev-application', component: PrevApplication },
{ path: 'prev-application-year', component: PrevApplicationYear },
{ path: 'prior-service', component: PriorService },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import { Provider } from 'react-redux';
import { render } from '@testing-library/react';
import { expect } from 'chai';
import sinon from 'sinon';
import { ROUTES } from '../../constants';

import PrevApplicationType from '../../components/v2/questions/PrevApplicationType';

const mockStoreStandard = {
getState: () => ({
dischargeUpgradeWizard: {
duwForm: {
form: {},
viewedIntroPage: true,
},
},
}),
subscribe: () => {},
dispatch: () => {},
};

const mockStoreNoIntroPage = {
getState: () => ({
dischargeUpgradeWizard: {
duwForm: {
form: {},
viewedIntroPage: false,
},
},
}),
subscribe: () => {},
dispatch: () => {},
};

const pushStub = sinon.stub();

const propsStandard = {
formResponses: {},
setPrevApplicationType: () => {},
router: {
push: pushStub,
},
viewedIntroPage: true,
};

const propsNoIntroPage = {
formResponses: {},
setPrevApplicationType: () => {},
router: {
push: pushStub,
},
viewedIntroPage: false,
};

describe('Previous Application Type Page', () => {
afterEach(() => {
pushStub.resetHistory();
});

it('should correctly load the Previous Application page in the standard flow', () => {
const screen = render(
<Provider store={mockStoreStandard}>
<PrevApplicationType {...propsStandard} />
</Provider>,
);

expect(screen.getByTestId('duw-prev_application_type')).to.exist;
});

it('should redirect to home when the intro page has not been viewed', () => {
render(
<Provider store={mockStoreNoIntroPage}>
<PrevApplicationType {...propsNoIntroPage} />
</Provider>,
);

expect(pushStub.withArgs(ROUTES.HOME).called).to.be.true;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,45 @@ describe('utilities: display logic', () => {
.true;
});
});

describe('routing to prev application type question by skip ahead', () => {
const formResponses = {
SERVICE_BRANCH: RESPONSES.ARMY,
DISCHARGE_YEAR: '2024',
REASON: RESPONSES.REASON_8,
};

const router = {
push: sinon.spy(),
};

it('Reason: should correctly route to the next question based on the specific answer', () => {
navigateForward(SHORT_NAME_MAP.REASON, formResponses, router);
expect(router.push.firstCall.calledWith(ROUTES.PREV_APPLICATION_TYPE))
.to.be.true;
});
});

describe('routing to prior service question by skip ahead', () => {
const formResponses = {
SERVICE_BRANCH: RESPONSES.ARMY,
DISCHARGE_YEAR: '2024',
REASON: RESPONSES.REASON_3,
DISCHARGE_TYPE: RESPONSES.DISCHARGE_TYPE_2,
INTENTION: RESPONSES.INTENTION_1,
COURT_MARTIAL: RESPONSES.COURT_MARTIAL_2,
PREV_APPLICATION: RESPONSES.PREV_APPLICATION_2,
};

const router = {
push: sinon.spy(),
};

it('Reason: should correctly route to the next question based on the specific answer', () => {
navigateForward(SHORT_NAME_MAP.PREV_APPLICATION, formResponses, router);
expect(router.push.firstCall.calledWith(ROUTES.PRIOR_SERVICE)).to.be
.true;
});
});
});
});
Loading

0 comments on commit d7dbc93

Please sign in to comment.