Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle empty other race options #4513

Merged
merged 6 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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