diff --git a/frontend/src/lib/format.test.ts b/frontend/src/lib/format.test.ts new file mode 100644 index 0000000..4fec396 --- /dev/null +++ b/frontend/src/lib/format.test.ts @@ -0,0 +1,46 @@ +import { describe, it, expect } from 'vitest' +import { formatCurrency } from './format' + +describe('formatCurrency', () => { + it('formats with English locale by default', () => { + const result = formatCurrency(1234.56, 'EUR') + expect(result).toContain('1,234.56') + }) + + it('formats with explicit English locale using comma grouping and period decimal', () => { + const result = formatCurrency(1234.56, 'EUR', 'en') + expect(result).toContain('1,234.56') + }) + + it('formats with German locale using period grouping and comma decimal', () => { + const result = formatCurrency(1234.56, 'EUR', 'de') + expect(result).toContain('1.234,56') + }) + + it('formats USD with English locale including dollar sign', () => { + const result = formatCurrency(1234.56, 'USD', 'en') + expect(result).toContain('$') + expect(result).toContain('1,234.56') + }) + + it('formats zero correctly', () => { + const result = formatCurrency(0, 'EUR', 'en') + expect(result).toContain('0.00') + }) + + it('formats negative amounts correctly', () => { + const result = formatCurrency(-500, 'EUR', 'en') + expect(result).toContain('-') + expect(result).toContain('500.00') + }) + + it('falls back gracefully when locale is empty string (does not throw)', () => { + expect(() => formatCurrency(1234.56, 'EUR', '')).not.toThrow() + }) + + it('does NOT produce German formatting when called without locale arg', () => { + const result = formatCurrency(1234.56, 'EUR') + // English default should have comma grouping, not period grouping + expect(result).not.toContain('1.234,56') + }) +})