test(web): add unit tests for usage format helpers - #79
Merged
wolfiesch merged 1 commit intoJul 19, 2026
Conversation
wolfiesch
force-pushed
the
test/usage-format-unit-tests
branch
from
July 19, 2026 22:31
4220cb6 to
787b75b
Compare
wolfiesch
force-pushed
the
test/usage-format-unit-tests
branch
from
July 19, 2026 22:38
787b75b to
aa366a9
Compare
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.
What this changes
Adds one colocated test file,
apps/web/src/features/usage/format.test.ts, covering the previously untested pure formatter moduleapps/web/src/features/usage/format.ts. No source changes — this PR adds tests for previously untested behavior only.Coverage pins the exact output strings of the observable contract:
formatDuration: 'a few seconds' below 5s, negative clamping, pluralization, and the s → m → h → day rounding boundaries (59s/60s, 59m/60m, 47h/48h → 2 days).ageLabel: future timestamps ('in X'), the ±5s 'just now' window, and past 'X ago'.usageAmountLabel: used/limit vs remaining-only vs fraction-only rendering, the 'No amount reported' fallback, percent precision (2 decimals below 1%, 1 decimal at/above), byte thresholds at exact GiB/MiB/KiB/B boundaries, USD formatting, and unit suffixes (tokens/requests/min).limitDisplayName: tier/window suffix appending, case-insensitive dedup, and 'quota window' suppression.resetLabel: null cases, passed resets, future countdown.capacityLabel: account pluralization.savedResetLabel: null/zero cases, pluralization, expiry parsing with unparseable/past/due-now filtering, sort order, and the 'next expires in X' suffix.reportIdentityDetail: org/plan composition and account-label dedup.Verfication
pnpm --filter @t4-code/web test— 72 files, 1029 tests passed (includes the new file).pnpm check— passes (release contract, provenance, lint --deny-warnings, typecheck).pnpm test; per project notes, the pre-existingpackages/clienttranscript-retention test failure on main is unrelated to this change.Checklist
pnpm checkpasses (release contract, provenance, lint, typecheck)pnpm testpasses; new behavior has a test that fails without this change (this PR is the tests; no source behavior changed)THIRD_PARTY_NOTICES.md