fix(test): make desktop ui tests locale-agnostic - #73123
Closed
ypQQ1984 wants to merge 1 commit into
Closed
Conversation
Three desktop UI tests froze en-US-formatted strings while the
implementation formatters deliberately use the runtime locale
(new Intl.DateTimeFormat(undefined, ...) / Intl.NumberFormat(undefined,
...)) — runtime-locale output is the intended behavior for a localized
UI. On any non-en-US dev machine the tests fail even though the code is
correct:
# zh-CN host:
time.test.ts -> expected '三月' to be 'March'
billing -> Unable to find text 'Threshold: minimum is $10.'
(zh-CN renders USD as 'US$10')
billing -> Unable to find text '$25 added. Balance is refreshing.'
Assert the behavior contract instead of the frozen snapshot, per the
repo's testing guidance (behavior contracts over snapshots):
- time.test.ts: same-year month buckets render via fmtMonth, prior-year
via fmtMonthYear — assert sessionBucketLabel(bucket) equals the shared
formatter's output for bucket.at, with bucket-kind narrowing.
- billing/index.test.tsx: interpolate formatMoney(10) / formatMoney(25)
into the expected strings.
No production code changes.
Verified: zh-CN host 40/40, LANG=C.UTF-8 40/40, tsc clean, eslint clean.
Contributor
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three desktop UI tests froze en-US-formatted strings while the implementation formatters deliberately use the runtime locale (
new Intl.DateTimeFormat(undefined, ...)/new Intl.NumberFormat(undefined, ...)). Runtime-locale output is the intended behavior for a localized UI — but it means these tests fail on any non-en-US dev machine even though the code is correct:Upstream CI is en-US, so this stays invisible there; it only bites contributors on non-English locales.
Fix
Assert the behavior contract instead of the frozen snapshot, per the repo's testing guidance ("behavior contracts over snapshots"):
time.test.ts: same-year month buckets render viafmtMonth, prior-year buckets viafmtMonthYear— assertsessionBucketLabel(bucket)equals the shared formatter's output forbucket.at, with bucket-kind narrowing.billing/index.test.tsx: interpolateformatMoney(10)/formatMoney(25)into the expected strings.No production code changes.
Test plan
vitest run --project ui src/lib/time.test.ts src/app/settings/billing/index.test.tsx— 40/40 pass (was 37/40)LANG=C.UTF-8 LC_ALL=C.UTF-8: 40/40 passtsc --noEmitclean,eslintclean