|
| 1 | +import { |
| 2 | + formatCurrency, |
| 3 | + formatRelativeDate, |
| 4 | + formatBillingCycle, |
| 5 | + formatCategory |
| 6 | +} from '../formatting'; |
| 7 | +import { SubscriptionCategory, BillingCycle } from '../../types/subscription'; |
| 8 | + |
| 9 | +describe('Formatting Utilities', () => { |
| 10 | + describe('formatCurrency', () => { |
| 11 | + it('formats USD correctly', () => { |
| 12 | + expect(formatCurrency(19.99)).toBe('$19.99'); |
| 13 | + expect(formatCurrency(0)).toBe('$0.00'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('formats other currencies correctly', () => { |
| 17 | + expect(formatCurrency(19.99, 'EUR').replace(/\s/g, ' ')).toContain('19.99'); |
| 18 | + expect(formatCurrency(19.99, 'GBP')).toContain('£19.99'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('handles negative values correctly', () => { |
| 22 | + expect(formatCurrency(-10.50)).toBe('-$10.50'); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe('formatRelativeDate', () => { |
| 27 | + beforeAll(() => { |
| 28 | + jest.useFakeTimers(); |
| 29 | + jest.setSystemTime(new Date('2024-01-15T12:00:00Z')); |
| 30 | + }); |
| 31 | + |
| 32 | + afterAll(() => { |
| 33 | + jest.useRealTimers(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('returns "Today" for current date', () => { |
| 37 | + expect(formatRelativeDate(new Date('2024-01-15T15:00:00Z'))).toBe('Today'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('returns "Yesterday" for previous day', () => { |
| 41 | + expect(formatRelativeDate(new Date('2024-01-14T10:00:00Z'))).toBe('Yesterday'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('returns "Tomorrow" for next day', () => { |
| 45 | + expect(formatRelativeDate(new Date('2024-01-16T10:00:00Z'))).toBe('Tomorrow'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('formats days ago correctly', () => { |
| 49 | + expect(formatRelativeDate(new Date('2024-01-10T10:00:00Z'))).toBe('5 days ago'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('formats future days correctly', () => { |
| 53 | + expect(formatRelativeDate(new Date('2024-01-20T10:00:00Z'))).toBe('In 5 days'); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('formatBillingCycle', () => { |
| 58 | + it('capitalizes monthly correctly', () => { |
| 59 | + expect(formatBillingCycle(BillingCycle.MONTHLY)).toBe('Monthly'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('capitalizes yearly correctly', () => { |
| 63 | + expect(formatBillingCycle(BillingCycle.YEARLY)).toBe('Yearly'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('capitalizes weekly correctly', () => { |
| 67 | + expect(formatBillingCycle(BillingCycle.WEEKLY)).toBe('Weekly'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('capitalizes custom correctly', () => { |
| 71 | + expect(formatBillingCycle(BillingCycle.CUSTOM)).toBe('Custom'); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('formatCategory', () => { |
| 76 | + it('capitalizes streaming correctly', () => { |
| 77 | + expect(formatCategory(SubscriptionCategory.STREAMING)).toBe('Streaming'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('capitalizes software correctly', () => { |
| 81 | + expect(formatCategory(SubscriptionCategory.SOFTWARE)).toBe('Software'); |
| 82 | + }); |
| 83 | + |
| 84 | + it('capitalizes other enum values correctly', () => { |
| 85 | + expect(formatCategory(SubscriptionCategory.FITNESS)).toBe('Fitness'); |
| 86 | + expect(formatCategory(SubscriptionCategory.EDUCATION)).toBe('Education'); |
| 87 | + }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments