import { describe, expect, it } from 'vitest' import { parseVCard } from '../src/main/contacts' describe('parseVCard', () => { it('parses EDS-style cards with E164 params and remote photos', () => { const card = [ 'BEGIN:VCARD', 'VERSION:3.0', 'FN:Alex Example', 'N:Example;Alex;;;', 'TEL;X-EVOLUTION-E164=4435550143,;VALUE=UNKNOWN;TYPE=CELL:(443) 555-0143', 'TEL;X-EVOLUTION-E164=5415550142,"+1";X-NC-SCOPE="v2-local";TYPE=VOICE:+1541', ' 5550142', 'PHOTO;VALUE=BINARY:https://lh5.googleusercontent.com/-abc/photo.jpg', 'END:VCARD' ].join('\r\n') const c = parseVCard(card) expect(c.name).toBe('Alex Example') expect(c.tels).toEqual([ { number: '4435550143', label: 'cell' }, { number: '5415550142', label: undefined } ]) expect(c.photo).toEqual({ kind: 'url', url: 'https://lh5.googleusercontent.com/-abc/photo.jpg' }) }) it('parses file photos and falls back to N when FN is missing', () => { const c = parseVCard( 'BEGIN:VCARD\nN:Doe;Jane;;;\nTEL;TYPE=work:555-123-4567\nPHOTO;VALUE=uri:file:///home/x/.cache/evolution/addressbook/abc/PHOTO-1.image%2Fpng\nEND:VCARD' ) expect(c.name).toBe('Jane Doe') expect(c.tels).toEqual([{ number: '5551234567', label: 'work' }]) expect(c.photo).toEqual({ kind: 'file', path: '/home/x/.cache/evolution/addressbook/abc/PHOTO-1.image/png' }) }) it('parses inline base64 photos (vCard 3 and 4)', () => { const v3 = parseVCard('BEGIN:VCARD\nFN:A\nTEL:5551234567\nPHOTO;ENCODING=b;TYPE=PNG:iVBORw0KGgo\n AAAA\nEND:VCARD') expect(v3.photo).toEqual({ kind: 'inline', mime: 'image/png', data: 'iVBORw0KGgoAAAA' }) const v4 = parseVCard('BEGIN:VCARD\nFN:A\nTEL:5551234567\nPHOTO:data:image/jpeg;base64,/9j/4AAQ\nEND:VCARD') expect(v4.photo).toEqual({ kind: 'inline', mime: 'image/jpeg', data: '/9j/4AAQ' }) }) it('handles grouped properties and escaped text', () => { const c = parseVCard('BEGIN:VCARD\nitem1.FN:Smith\\, John\nitem1.TEL;type=CELL:+1 541 555 0142\nEND:VCARD') expect(c.name).toBe('Smith, John') expect(c.tels[0]).toEqual({ number: '5415550142', label: 'cell' }) }) })