test: add unit tests for localizedDescription selection logic - #1025
Conversation
|
Auto-review failed (API error). Leaving PR for human review. |
|
@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! 🚀 |
|
nice tight PR: the 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
7bb1bef to
e218f25
Compare
|
Auto-review failed (API error). Leaving PR for human review. |
davidmaronio
left a comment
There was a problem hiding this comment.
rebase looks good and the pr is still tightly scoped to the util and its tests. merging.
Summary
Closes #799 — [Testing] Add unit tests for
localizedDescriptionselection logic.src/utils/localizedDescription.tshad 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.tsgetLocalizedDescription()now usesmap[locale] || map["en"] || descriptioninstead of??. Becauseparse()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 inCauseDetailClient.tsx, which then runsisBlankMarkdown.)src/__tests__/utils/localizedDescription.test.ts(new)getLocalizedDescription:[lang:fr]/[lang:fr]with no text)encodeLocalizedDescription:[lang:xx]...marker format""when there are no non-empty translationsAcceptance criteria
src/tests/utils/localizedDescription.test.ts(see note above — added undersrc/__tests__/utils/per repo convention).Verification
npx jest src/__tests__/utils/localizedDescription.test.ts).eslintclean andprettier --checkclean on both touched files.tsc --noEmitshows only the pre-existing errors inCauseDetailClient.tsx/WalletContext.tsx(unrelated, present onmain).Out of scope
Adding a translation UI for campaign descriptions (explicitly out of scope in the issue).