Files
Rental-operations-platform/tests/unit/format.test.ts
T
2026-06-25 19:06:59 -04:00

41 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
formatCurrency,
formatDate,
formatDateRange,
formatNumber,
formatPercent,
formatPhoneNumber,
formatRelativeTime,
preserveIdentifier,
} from '@/lib/localization/format';
import { describe, expect, it } from 'vitest';
const instant = new Date('2026-06-25T12:00:00.000Z');
describe('locale-aware formatting primitives', () => {
it('formats Gregorian dates with explicit time zones', () => {
expect(formatDate(instant, { locale: 'en', timeZone: 'UTC' })).toContain('2026');
expect(formatDate(instant, { locale: 'fr', timeZone: 'UTC' })).toContain('2026');
expect(formatDate(instant, { locale: 'ar', timeZone: 'UTC' })).toContain('2026');
});
it('formats ranges, numbers, percentages, and explicit currencies', () => {
expect(
formatDateRange(instant, new Date('2026-06-27T12:00:00.000Z'), {
locale: 'en',
timeZone: 'UTC',
}),
).toContain('2026');
expect(formatNumber(1234.5, 'fr')).toMatch(/1.*234/);
expect(formatPercent(0.125, 'en')).toContain('12.5');
expect(formatCurrency(125, 'en', 'USD')).toContain('$');
expect(() => formatCurrency(125, 'en', 'usd')).toThrow(/ISO 4217/);
});
it('formats relative time and preserves atomic mixed-direction values', () => {
expect(formatRelativeTime(-1, 'day', 'en')).toBe('yesterday');
expect(formatPhoneNumber('+1 (202) 555-0100')).toBe('+12025550100');
expect(preserveIdentifier('RES 2026 0042')).toBe('RES 2026 0042');
});
});