d7fb7b7a7b
Build & Deploy / Build & Push Docker Image (push) Failing after 47s
Build & Deploy / Deploy to VPS (push) Has been skipped
Test / API Unit Tests (push) Failing after 5m4s
Test / Marketplace Unit Tests (push) Failing after 4m55s
Test / Admin Unit Tests (push) Successful in 9m37s
Test / Dashboard Unit Tests (push) Successful in 9m37s
Test / API Integration Tests (push) Successful in 9m54s
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
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');
|
||
});
|
||
});
|