Skip to content

test: add unit tests for localizedDescription selection logic - #1025

Merged
davidmaronio merged 1 commit into
Iris-IV:mainfrom
Queen-T16:fix/799-localized-description-unit-tests
Aug 5, 2026
Merged

test: add unit tests for localizedDescription selection logic#1025
davidmaronio merged 1 commit into
Iris-IV:mainfrom
Queen-T16:fix/799-localized-description-unit-tests

Conversation

@Queen-T16

@Queen-T16 Queen-T16 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #799 — [Testing] Add unit tests for localizedDescription selection logic.

src/utils/localizedDescription.ts had no test coverage for its locale-selection / fallback behavior. This PR adds a unit-test suite and fixes a small fallback bug it exposed: an empty translation for the requested locale was returned as "" instead of falling back to the default locale.

Changes

src/utils/localizedDescription.ts

  • getLocalizedDescription() now uses map[locale] || map["en"] || description instead of ??. Because parse() stores trimmed values, an empty / whitespace-only translation is represented as "", so ?? (nullish coalescing) let the empty string through. The logical-or treats missing and empty translations identically, both falling back to the default locale (English), then to the raw description string. (Verified compatible with the existing consumer in CauseDetailClient.tsx, which then runs isBlankMarkdown.)

src/__tests__/utils/localizedDescription.test.ts (new)

  • getLocalizedDescription:
    • returns the requested locale's description when it exists
    • returns plain text as-is when there are no language markers
    • falls back to the default locale when the requested locale is missing
    • falls back to the default locale when the requested locale is empty (e.g. [lang:fr] / [lang:fr] with no text)
    • falls back to the raw description when the default locale is also empty
  • encodeLocalizedDescription:
    • encodes translations into the [lang:xx]... marker format
    • omits empty / whitespace-only translations
    • returns "" when there are no non-empty translations
  • round-trip test: encode → decode returns the correct per-locale text

Note: placed at src/__tests__/utils/localizedDescription.test.ts (the repo's existing convention, e.g. exportCsv.test.ts) rather than the literal src/tests/ path from the issue, since the repo has no src/tests directory and Jest ignores only the root tests/ e2e dir.

Acceptance criteria

  • Add src/tests/utils/localizedDescription.test.ts (see note above — added under src/__tests__/utils/ per repo convention).
  • Cover the case where the requested locale's description exists.
  • Cover fallback to the default locale when the requested locale's description is missing or empty.

Verification

  • New suite: 9 tests pass (npx jest src/__tests__/utils/localizedDescription.test.ts).
  • eslint clean and prettier --check clean on both touched files.
  • tsc --noEmit shows only the pre-existing errors in CauseDetailClient.tsx / WalletContext.tsx (unrelated, present on main).

Out of scope

Adding a translation UI for campaign descriptions (explicitly out of scope in the issue).

@sshdopey

sshdopey commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@drips-wave

drips-wave Bot commented Aug 1, 2026

Copy link
Copy Markdown

@Queen-T16 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@davidmaronio

Copy link
Copy Markdown
Contributor

nice tight PR: the ?? to || change correctly makes an empty translation fall back to english (and the parse-trims-values reasoning in the body is right), and the test suite covers requested-locale hit, plain text, missing locale, empty locale, empty default, encode filtering, and a round-trip. no code asks from me.

gate: branch is behind main; rebase and rerun CI, then this is good to merge. (independent of your #1023/#1024, no stacking.)

Add src/__tests__/utils/localizedDescription.test.ts covering
getLocalizedDescription and encodeLocalizedDescription.

Fix getLocalizedDescription so an empty (whitespace-only) translation for
the requested locale falls back to the default locale (English) instead of
being returned as an empty string. parse() stores trimmed values, so empty
translations are already represented as ""; switching the nullish
coalescing to logical-or makes missing and empty translations behave the
same.

Closes Iris-IV#799
@Queen-T16
Queen-T16 force-pushed the fix/799-localized-description-unit-tests branch from 7bb1bef to e218f25 Compare August 5, 2026 11:09
@sshdopey

sshdopey commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@davidmaronio davidmaronio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase looks good and the pr is still tightly scoped to the util and its tests. merging.

@davidmaronio
davidmaronio merged commit 6e53ab5 into Iris-IV:main Aug 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Testing] Add unit tests for localizedDescription selection logic

3 participants