Skip to content

Commit

Permalink
fix: handle empty other race options (#4513)
Browse files Browse the repository at this point in the history
* fix: handle empty other race options

* fix: clean up

* fix: cleaner way to store

* fix: improved csv formatting

* fix: remove space
  • Loading branch information
ColinBuyck authored Jan 2, 2025
1 parent c0d102d commit 1e1d8f3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
8 changes: 5 additions & 3 deletions api/src/utilities/application-export-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,13 @@ export const getHouseholdCsvHeaders = (
*/
export const convertDemographicRaceToReadable = (type: string): string => {
const [rootKey, customValue = ''] = type.split(':');
//only show colon if user entered a custom value
const customValueFormatted = customValue ? `:${customValue}` : '';
const typeMap = {
americanIndianAlaskanNative: 'American Indian / Alaskan Native',
asian: 'Asian',
'asian-asianIndian': 'Asian[Asian Indian]',
'asian-otherAsian': `Asian[Other Asian:${customValue}]`,
'asian-otherAsian': `Asian[Other Asian${customValueFormatted}]`,
blackAfricanAmerican: 'Black / African American',
'asian-chinese': 'Asian[Chinese]',
declineToRespond: 'Decline to Respond',
Expand All @@ -558,8 +560,8 @@ export const convertDemographicRaceToReadable = (type: string): string => {
'Native Hawaiian / Other Pacific Islander[Native Hawaiian]',
nativeHawaiianOtherPacificIslander:
'Native Hawaiian / Other Pacific Islander',
otherMultiracial: `Other / Multiracial:${customValue}`,
'nativeHawaiianOtherPacificIslander-otherPacificIslander': `Native Hawaiian / Other Pacific Islander[Other Pacific Islander:${customValue}]`,
otherMultiracial: `Other / Multiracial${customValueFormatted}`,
'nativeHawaiianOtherPacificIslander-otherPacificIslander': `Native Hawaiian / Other Pacific Islander[Other Pacific Islander${customValueFormatted}]`,
'nativeHawaiianOtherPacificIslander-samoan':
'Native Hawaiian / Other Pacific Islander[Samoan]',
'asian-vietnamese': 'Asian[Vietnamese]',
Expand Down
6 changes: 6 additions & 0 deletions api/test/unit/utilities/application-export-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ describe('Testing application export helpers', () => {
);
});

it('tests convertDemographicRaceToReadable with valid type and empty custom value', () => {
expect(convertDemographicRaceToReadable('otherMultiracial')).toBe(
'Other / Multiracial',
);
});

it('tests convertDemographicRaceToReadable with type not in typeMap', () => {
const custom = 'This is a custom value';
expect(convertDemographicRaceToReadable(custom)).toBe(custom);
Expand Down
11 changes: 11 additions & 0 deletions shared-helpers/__tests__/formKeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,15 @@ describe("formKeys helpers", () => {
const expectedArray = ["A", "B", "C", "D: 1,2"]
expect(fieldGroupObjectToArray(testObj, "root")).toStrictEqual(expectedArray)
})

it("fieldGroupObjectToArray with empty additional inputs", () => {
const testObj = {
["root-A"]: "A",
["root-B"]: "B",
["root-C"]: "C",
["root-D"]: "",
}
const expectedArray = ["A", "B", "C", "D"]
expect(fieldGroupObjectToArray(testObj, "root")).toStrictEqual(expectedArray)
})
})
11 changes: 9 additions & 2 deletions shared-helpers/src/utilities/formKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,17 @@ export const fieldGroupObjectToArray = (
const modifiedArray: string[] = []
const getValue = (elem: string) => {
const formSubKey = elem.substring(elem.indexOf("-") + 1)
return formSubKey === formObject[elem] ? formSubKey : `${formSubKey}: ${formObject[elem]}`
return formSubKey === formObject[elem] || formObject[elem] === ""
? formSubKey
: `${formSubKey}: ${formObject[elem]}`
}
Object.keys(formObject)
.filter((formValue) => formValue.split("-")[0] === rootKey && formObject[formValue])
.filter(
(formValue) =>
formValue.split("-")[0] === rootKey &&
//empty string handles selected checkbox fields with empty additionalText
(formObject[formValue] || formObject[formValue] === "")
)
.forEach((elem) => {
if (formObject[elem].isArray) {
formObject[elem].forEach(() => {
Expand Down

0 comments on commit 1e1d8f3

Please sign in to comment.