import { describe, it, expect } from 'vitest'; import { PercentFormatter } from './PercentFormatter'; describe('PercentFormatter', () => { describe('format', () => { it('should format decimal value as percentage with 1 decimal place', () => { expect(PercentFormatter.format(0.1234)).toBe('12.3%'); expect(PercentFormatter.format(0.5)).toBe('50.0%'); expect(PercentFormatter.format(1.0)).toBe('100.0%'); }); it('should handle zero', () => { expect(PercentFormatter.format(0)).toBe('0.0%'); }); it('should handle null', () => { expect(PercentFormatter.format(null)).toBe('0.0%'); }); it('should handle undefined', () => { expect(PercentFormatter.format(undefined)).toBe('0.0%'); }); it('should handle negative values', () => { expect(PercentFormatter.format(-0.1234)).toBe('-12.3%'); }); it('should handle values greater than 1', () => { expect(PercentFormatter.format(1.5)).toBe('150.0%'); expect(PercentFormatter.format(2.0)).toBe('200.0%'); }); }); describe('formatWhole', () => { it('should format whole number as percentage', () => { expect(PercentFormatter.formatWhole(12)).toBe('12%'); expect(PercentFormatter.formatWhole(50)).toBe('50%'); expect(PercentFormatter.formatWhole(100)).toBe('100%'); }); it('should handle zero', () => { expect(PercentFormatter.formatWhole(0)).toBe('0%'); }); it('should handle null', () => { expect(PercentFormatter.formatWhole(null)).toBe('0%'); }); it('should handle undefined', () => { expect(PercentFormatter.formatWhole(undefined)).toBe('0%'); }); it('should round decimal values', () => { expect(PercentFormatter.formatWhole(12.3)).toBe('12%'); expect(PercentFormatter.formatWhole(12.7)).toBe('13%'); }); it('should handle negative values', () => { expect(PercentFormatter.formatWhole(-12)).toBe('-12%'); }); }); });