-
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.
* EDM-91 YRT frontend mockups (2 of 4) * update propTypes
- Loading branch information
1 parent
59a65a7
commit b19a3fa
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/applications/gi/components/profile/YellowRibbonTableRows.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,88 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const deriveDegreeLevel = degreeLevel => { | ||
// Show unknown if there's no degreeLevel. | ||
if (!degreeLevel) { | ||
return 'Not provided'; | ||
} | ||
|
||
// Show the degreeLevel. | ||
return degreeLevel; | ||
}; | ||
|
||
export const deriveMaxAmount = contributionAmount => { | ||
// Show unknown if there's no contributionAmount. | ||
if (!contributionAmount) { | ||
return 'Not provided'; | ||
} | ||
|
||
// Derive the contribution amount number. | ||
const contributionAmountNum = parseFloat(contributionAmount); | ||
|
||
// Show unlimited contribution amount state. | ||
if (contributionAmountNum >= 99999) { | ||
return "Pays remaining tuition that Post-9/11 GI Bill doesn't cover"; | ||
} | ||
|
||
// Show formatted contributionAmount. | ||
return contributionAmountNum.toLocaleString('en-US', { | ||
currency: 'USD', | ||
maximumFractionDigits: 0, | ||
minimumFractionDigits: 0, | ||
style: 'currency', | ||
}); | ||
}; | ||
|
||
export const deriveEligibleStudents = numberOfStudents => { | ||
// Show unknown if there's no numberOfStudents. | ||
if (!numberOfStudents) { | ||
return 'Not provided'; | ||
} | ||
|
||
// Escape early if the data indicates all eligible students. | ||
if (numberOfStudents >= 99999) { | ||
return 'All eligible students'; | ||
} | ||
|
||
// Show numberOfStudents. | ||
return `${numberOfStudents} students`; | ||
}; | ||
|
||
export const formatDegree = degreeLevel => { | ||
let degreeLevels; | ||
|
||
if (degreeLevel.includes(',')) { | ||
degreeLevels = degreeLevel.split(','); | ||
return `${degreeLevels[0]}/${degreeLevels[1].trim()}`; | ||
} | ||
|
||
return degreeLevel; | ||
}; | ||
|
||
function YellowRibbonTableRows({ programs }) { | ||
return ( | ||
<> | ||
{programs.map((program, index) => { | ||
const { | ||
degreeLevel, | ||
divisionProfessionalSchool, | ||
numberOfStudents, | ||
contributionAmount, | ||
} = program; | ||
|
||
return ( | ||
<va-table-row key={`row-default-${index}`}> | ||
<span>{formatDegree(deriveDegreeLevel(degreeLevel))}</span> | ||
<span>{divisionProfessionalSchool}</span> | ||
<span>{deriveEligibleStudents(numberOfStudents)}</span> | ||
<span>{deriveMaxAmount(contributionAmount)}</span> | ||
</va-table-row> | ||
); | ||
})} | ||
</> | ||
); | ||
} | ||
|
||
YellowRibbonTableRows.propTypes = { programs: PropTypes.object }; | ||
export default YellowRibbonTableRows; |
63 changes: 63 additions & 0 deletions
63
src/applications/gi/tests/components/profile/YellowRibbonTableRows.unit.spec.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,63 @@ | ||
import { expect } from 'chai'; | ||
import { | ||
deriveDegreeLevel, | ||
deriveMaxAmount, | ||
deriveEligibleStudents, | ||
formatDegree, | ||
} from '../../../components/profile/YellowRibbonTableRows'; | ||
|
||
describe('Test deriveDegreeLevel function', () => { | ||
it('should return "Not provided" if degreeLevel is undefined or null', () => { | ||
expect(deriveDegreeLevel(undefined)).to.equal('Not provided'); | ||
expect(deriveDegreeLevel(null)).to.equal('Not provided'); | ||
}); | ||
|
||
it('should return the provided degree level when degreeLevel is defined', () => { | ||
expect(deriveDegreeLevel('Bachelor')).to.equal('Bachelor'); | ||
expect(deriveDegreeLevel('Master')).to.equal('Master'); | ||
}); | ||
}); | ||
|
||
describe('Test deriveMaxAmount function', () => { | ||
it('should return "Not provided" if contributionAmount is undefined or null', () => { | ||
expect(deriveMaxAmount(undefined)).to.equal('Not provided'); | ||
expect(deriveMaxAmount(null)).to.equal('Not provided'); | ||
}); | ||
|
||
it('should return correct formatted contribution amount for a valid number', () => { | ||
expect(deriveMaxAmount('5000')).to.equal('$5,000'); | ||
expect(deriveMaxAmount('10000')).to.equal('$10,000'); | ||
}); | ||
|
||
it('should return "Pays remaining tuition that Post-9/11 GI Bill doesn\'t cover" if contributionAmount is 99999 or greater', () => { | ||
expect(deriveMaxAmount('99999')).to.equal( | ||
"Pays remaining tuition that Post-9/11 GI Bill doesn't cover", | ||
); | ||
expect(deriveMaxAmount('100000')).to.equal( | ||
"Pays remaining tuition that Post-9/11 GI Bill doesn't cover", | ||
); | ||
}); | ||
}); | ||
|
||
describe('Test deriveEligibleStudents function', () => { | ||
it('should return "Not provided" if numberOfStudents is null or undefined', () => { | ||
expect(deriveEligibleStudents(undefined)).to.equal('Not provided'); | ||
expect(deriveEligibleStudents(null)).to.equal('Not provided'); | ||
}); | ||
|
||
it('should return the number of students with "students" suffix', () => { | ||
expect(deriveEligibleStudents(50)).to.equal('50 students'); | ||
expect(deriveEligibleStudents(100)).to.equal('100 students'); | ||
}); | ||
|
||
it('should return "All eligible students" if numberOfStudents is 99999 or greater', () => { | ||
expect(deriveEligibleStudents(99999)).to.equal('All eligible students'); | ||
expect(deriveEligibleStudents(100000)).to.equal('All eligible students'); | ||
}); | ||
}); | ||
|
||
describe('Test formatDegree function', () => { | ||
it('should format degreeLevel with a comma separator into first/second format', () => { | ||
expect(formatDegree('Bachelor, Master')).to.equal('Bachelor/Master'); | ||
}); | ||
}); |