Bundles the prior autonomous-session output that was sitting unstaged: - Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances) - country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk after the per-subpath dynamic-import approach silently failed in webpack) - Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index, redirects (ocr to ai, reports to dashboard, invitations to users), docs/admin-ia-proposal.md - Per-template email tester (registry + endpoint + UI on Email admin page) - Cancel-document mode picker (delete-from-Documenso vs keep-for-audit) - Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers - Customize-widgets per-region sortables at xl+ (charts/rails/feed); single flat sortable below xl when the layout stacks; per-viewport saved orders - Audit doc updates capturing each shipped item - Lint fixes: react-compiler immutability in DonutChart (reduce instead of let-reassign), set-state-in-effect disables in CountryFlag and UploadForSigning preview-bytes effect, unused 'confirm' destructures in interest contract + reservation tabs, unescaped apostrophe in test-template card copy
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
/**
|
|
* i18n PR2 - phone helpers.
|
|
*
|
|
* Validates:
|
|
* 1. parsePhone yields E.164 + country + display formats
|
|
* 2. parsePhone returns the empty record for unparseable input
|
|
* 3. AsYouType formats digits in the country's national style
|
|
* 4. isValidE164 accepts only E.164 form
|
|
* 5. callingCodeFor returns the dial prefix
|
|
* 6. International-format paste detects country
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { parsePhone, formatAsYouType, isValidE164, callingCodeFor } from '@/lib/i18n/phone';
|
|
|
|
describe('i18n phone', () => {
|
|
it('parses an international-format input regardless of defaultCountry', () => {
|
|
const r = parsePhone('+44 20 7946 0958');
|
|
expect(r.e164).toBe('+442079460958');
|
|
expect(r.country).toBe('GB');
|
|
expect(r.isValid).toBe(true);
|
|
expect(r.national).toMatch(/020 7946 0958/);
|
|
expect(r.international).toMatch(/\+44 20 7946 0958/);
|
|
});
|
|
|
|
it('parses a national-format input against the defaultCountry', () => {
|
|
const r = parsePhone('020 7946 0958', 'GB');
|
|
expect(r.e164).toBe('+442079460958');
|
|
expect(r.country).toBe('GB');
|
|
expect(r.isValid).toBe(true);
|
|
});
|
|
|
|
it('returns the empty record for empty / nonsense input', () => {
|
|
expect(parsePhone('').isValid).toBe(false);
|
|
expect(parsePhone('abc').isValid).toBe(false);
|
|
expect(parsePhone('').e164).toBeNull();
|
|
});
|
|
|
|
it('formatAsYouType produces national-format output', () => {
|
|
// GB national-format breaks 020 7946 0958.
|
|
const out = formatAsYouType('2079460958', 'GB');
|
|
expect(out.length).toBeGreaterThan(0);
|
|
// US national-format breaks (415) 555-1234.
|
|
const us = formatAsYouType('4155551234', 'US');
|
|
expect(us).toContain('415');
|
|
});
|
|
|
|
it('isValidE164 accepts only E.164', () => {
|
|
expect(isValidE164('+442079460958')).toBe(true);
|
|
expect(isValidE164('+1 415 555 1234')).toBe(true); // libphonenumber tolerates spaces
|
|
expect(isValidE164('020 7946 0958')).toBe(false); // missing +country prefix
|
|
expect(isValidE164('not a phone')).toBe(false);
|
|
});
|
|
|
|
it('callingCodeFor returns the dial prefix', () => {
|
|
expect(callingCodeFor('US')).toBe('+1');
|
|
expect(callingCodeFor('GB')).toBe('+44');
|
|
expect(callingCodeFor('PL')).toBe('+48');
|
|
});
|
|
});
|