Files
bubble/test/phone.test.ts
T
travandClaude Opus 5 a2b8f764db voip.ms Messages: Signal-style desktop SMS client
Electron + React app that imports the full voip.ms SMS history into a
local SQLite/FTS5 database, polls for new messages, sends SMS, resolves
names/photos from GNOME EDS address books, and supports global and
per-chat search with jump-to-message.

Data lives in ~/Documents/voipms-desktop-data (covered by Deja Dup) with
daily consistent snapshots.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 21:25:12 -07:00

40 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { formatNumber, normalizeNumber, splitMessage } from '@shared/phone'
describe('phone numbers', () => {
it('normalizes NANP numbers to 10 digits', () => {
expect(normalizeNumber('+1 (541) 555-0142')).toBe('5415550142')
expect(normalizeNumber('15415550142')).toBe('5415550142')
expect(normalizeNumber('541.555.0142')).toBe('5415550142')
expect(normalizeNumber('tel:+15415550142')).toBe('5415550142')
})
it('leaves short codes alone', () => {
expect(normalizeNumber('72975')).toBe('72975')
})
it('formats', () => {
expect(formatNumber('5415550142')).toBe('(541) 555-0142')
expect(formatNumber('72975')).toBe('72975')
})
})
describe('splitMessage', () => {
it('keeps short messages whole', () => {
expect(splitMessage('hi there')).toEqual(['hi there'])
})
it('splits long messages on word boundaries under 160 chars', () => {
const text = Array.from({ length: 80 }, (_, i) => `word${i}`).join(' ')
const parts = splitMessage(text)
expect(parts.length).toBeGreaterThan(1)
for (const p of parts) expect([...p].length).toBeLessThanOrEqual(160)
expect(parts.join(' ')).toBe(text)
})
it('hard-splits a long unbroken string', () => {
const parts = splitMessage('x'.repeat(400))
expect(parts.map((p) => p.length)).toEqual([160, 160, 80])
})
it('counts emoji as single characters', () => {
const parts = splitMessage('😀'.repeat(200))
expect(parts.map((p) => [...p].length)).toEqual([160, 40])
})
})