import { describe, it, expect } from 'vitest'; import { CurrencyFormatter } from './CurrencyFormatter'; describe('CurrencyFormatter', () => { describe('format', () => { it('should format USD with dollar sign and commas', () => { expect(CurrencyFormatter.format(1234.56, 'USD')).toBe('$1,234.56'); expect(CurrencyFormatter.format(1000000, 'USD')).toBe('$1,000,000.00'); }); it('should format EUR with euro sign and dots as thousands separator', () => { expect(CurrencyFormatter.format(1234.56, 'EUR')).toBe('€1.234,56'); expect(CurrencyFormatter.format(1000000, 'EUR')).toBe('€1.000.000,00'); }); it('should format with custom currency symbol', () => { expect(CurrencyFormatter.format(1234.56, 'GBP')).toBe('GBP 1,234.56'); expect(CurrencyFormatter.format(1234.56, 'JPY')).toBe('JPY 1,234.56'); }); it('should use USD as default currency', () => { expect(CurrencyFormatter.format(1234.56)).toBe('$1,234.56'); }); it('should handle zero amount', () => { expect(CurrencyFormatter.format(0, 'USD')).toBe('$0.00'); expect(CurrencyFormatter.format(0, 'EUR')).toBe('€0,00'); }); it('should handle negative amounts', () => { expect(CurrencyFormatter.format(-1234.56, 'USD')).toBe('$-1,234.56'); expect(CurrencyFormatter.format(-1234.56, 'EUR')).toBe('€-1.234,56'); }); it('should handle amounts with many decimal places', () => { expect(CurrencyFormatter.format(1234.5678, 'USD')).toBe('$1,234.57'); expect(CurrencyFormatter.format(1234.5678, 'EUR')).toBe('€1.234,57'); }); }); describe('formatCompact', () => { it('should format USD with dollar sign and no decimals', () => { expect(CurrencyFormatter.formatCompact(1234.56, 'USD')).toBe('$1,235'); expect(CurrencyFormatter.formatCompact(1000000, 'USD')).toBe('$1,000,000'); }); it('should format EUR with euro sign and dots as thousands separator', () => { expect(CurrencyFormatter.formatCompact(1234.56, 'EUR')).toBe('€1.235'); expect(CurrencyFormatter.formatCompact(1000000, 'EUR')).toBe('€1.000.000'); }); it('should format with custom currency symbol', () => { expect(CurrencyFormatter.formatCompact(1234.56, 'GBP')).toBe('GBP 1,235'); expect(CurrencyFormatter.formatCompact(1234.56, 'JPY')).toBe('JPY 1,235'); }); it('should use USD as default currency', () => { expect(CurrencyFormatter.formatCompact(1234.56)).toBe('$1,235'); }); it('should handle zero amount', () => { expect(CurrencyFormatter.formatCompact(0, 'USD')).toBe('$0'); expect(CurrencyFormatter.formatCompact(0, 'EUR')).toBe('€0'); }); it('should handle negative amounts', () => { expect(CurrencyFormatter.formatCompact(-1234.56, 'USD')).toBe('$-1,235'); expect(CurrencyFormatter.formatCompact(-1234.56, 'EUR')).toBe('€-1.235'); }); it('should round amounts correctly', () => { expect(CurrencyFormatter.formatCompact(1234.4, 'USD')).toBe('$1,234'); expect(CurrencyFormatter.formatCompact(1234.6, 'USD')).toBe('$1,235'); }); }); });