init project
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user