Files
SimpleFinanceDash/.planning/phases/04-chart-polish-and-bug-fixes/04-01-PLAN.md

104 lines
3.8 KiB
Markdown

---
phase: 04-chart-polish-and-bug-fixes
plan: 01
type: tdd
wave: 1
depends_on: []
files_modified:
- frontend/src/lib/format.ts
- frontend/src/lib/format.test.ts
autonomous: true
requirements:
- FIX-01
must_haves:
truths:
- "formatCurrency no longer hardcodes 'de-DE' — the default locale is 'en'"
- "formatCurrency accepts an optional third locale parameter"
- "Calling formatCurrency(1234.56, 'EUR', 'de') produces German-formatted output"
- "Calling formatCurrency(1234.56, 'USD', 'en') produces English-formatted output"
- "Calling formatCurrency(1234.56, 'EUR') without locale uses 'en' default, not 'de-DE'"
artifacts:
- path: "frontend/src/lib/format.ts"
provides: "Locale-aware formatCurrency function"
contains: "locale"
- path: "frontend/src/lib/format.test.ts"
provides: "Unit tests for formatCurrency locale behavior"
min_lines: 20
key_links:
- from: "frontend/src/lib/format.ts"
to: "Intl.NumberFormat"
via: "locale parameter passed as first arg"
pattern: "Intl\\.NumberFormat\\(locale"
---
<objective>
Fix the hardcoded `'de-DE'` locale in `formatCurrency` by adding an optional `locale` parameter with `'en'` as the default. This is the foundation for IXTN-04 (chart tooltips) and ensures all currency formatting respects the user's locale preference.
Purpose: FIX-01 — English-locale users currently see German number formatting everywhere
Output: Updated `format.ts` with locale parameter, comprehensive unit tests
</objective>
<execution_context>
@/home/jean-luc-makiola/.claude/get-shit-done/workflows/execute-plan.md
@/home/jean-luc-makiola/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/phases/04-chart-polish-and-bug-fixes/04-RESEARCH.md
@frontend/src/lib/format.ts
</context>
<feature>
<name>Locale-aware formatCurrency</name>
<files>frontend/src/lib/format.ts, frontend/src/lib/format.test.ts</files>
<behavior>
- formatCurrency(1234.56, 'EUR', 'en') returns a string containing "1,234.56" (English grouping)
- formatCurrency(1234.56, 'EUR', 'de') returns a string containing "1.234,56" (German grouping)
- formatCurrency(1234.56, 'USD', 'en') returns a string containing "$" and "1,234.56"
- formatCurrency(1234.56, 'EUR') with NO locale arg uses 'en' default — does NOT produce German formatting
- formatCurrency(0, 'EUR', 'en') returns a string containing "0.00"
- formatCurrency(-500, 'EUR', 'en') returns a string containing "-" and "500.00"
- formatCurrency(1234.56, 'EUR', '') falls back gracefully (does not throw RangeError)
</behavior>
<implementation>
Update `frontend/src/lib/format.ts`:
```ts
export function formatCurrency(
amount: number,
currency: string = 'EUR',
locale: string = 'en'
): string {
return new Intl.NumberFormat(locale || 'en', {
style: 'currency',
currency,
}).format(amount)
}
```
Key points:
- Third parameter `locale` defaults to `'en'` (replacing hardcoded `'de-DE'`)
- Defensive `locale || 'en'` guards against empty string (which throws RangeError)
- All existing call sites pass only 2 args — they will now get English formatting instead of German
- This is intentional and correct per FIX-01
</implementation>
</feature>
<verification>
cd frontend && bun vitest run src/lib/format.test.ts
</verification>
<success_criteria>
- format.test.ts has at least 6 test cases covering locale variations, defaults, and edge cases
- All tests pass green
- formatCurrency signature has 3 parameters: amount, currency, locale
- No hardcoded 'de-DE' remains in format.ts
</success_criteria>
<output>
After completion, create `.planning/phases/04-chart-polish-and-bug-fixes/04-01-SUMMARY.md`
</output>