Skip to content
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
10 changes: 6 additions & 4 deletions packages/admin-portal/src/services/UserService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ describe("resolveOptionLabel", () => {
})

describe("getSelectOptionLabel", () => {
it("shows the stored option next to its description", () => {
expect(getSelectOptionLabel({M: "Male"}, "M", translate())).toBe("M - Male")
it("shows the configured label without prepending the stored option", () => {
expect(getSelectOptionLabel({"0": "0 - Non Resident"}, "0", translate())).toBe(
"0 - Non Resident"
)
})

it("keeps the stored option visible when the option itself is overridden", () => {
expect(getSelectOptionLabel(undefined, "M", translate({M: "Male"}))).toBe("M - Male")
it("shows the translated label without prepending the stored option", () => {
expect(getSelectOptionLabel(undefined, "M", translate({M: "Male"}))).toBe("Male")
})

it("shows the option alone when nothing describes it", () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/admin-portal/src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ const getSelectOptionDescription = (
}

/**
* Label shown for one option of a `select` user profile attribute. The stored
* option stays visible, so the admin still sees what is written to the voter,
* and its description is appended when the attribute configures one.
* Label shown for one option of a `select` user profile attribute. A configured
* description replaces the stored value; the value is the fallback when the
* option has no description.
*/
export const getSelectOptionLabel = (
optionLabels: Record<string, string> | undefined,
Expand All @@ -152,7 +152,7 @@ export const getSelectOptionLabel = (
): string => {
const description = getSelectOptionDescription(optionLabels, option, t)

return description && description !== option ? `${option} - ${description}` : option
return description ?? option
}

const toPositiveInteger = (value: unknown): number | undefined => {
Expand Down
Loading