-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS-16914: DUW Add prev-application-type question (#29288)
- Loading branch information
1 parent
6a355ea
commit d7dbc93
Showing
8 changed files
with
280 additions
and
14 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/applications/discharge-wizard/components/v2/questions/PrevApplicationType.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/applications/discharge-wizard/tests/v2/PrevApplicationType.unit.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.