teqo-backup/tests/unit/homeSearchShare.unit.spec.ts
Cursor Agent b96bf190e8 B55 — Busca global: ações de linha (WA e compartilhar)
Adiciona trailing actions nas linhas de resultado da busca global:
- WhatsApp em lideranças e assessores (reusa whatsAppHrefForPhone)
- Compartilhar em demandas e atividades (Web Share nativo com fallback wa.me)
- trailingAction fora do Link da linha para não roubar navegação

Closes #9
2026-07-30 22:47:03 +00:00

35 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
buildHomeSearchShareText,
buildHomeSearchWhatsAppShareHref,
buildWhatsAppTextShareUrl,
resolveHomeSearchShareStrategy,
} from '@/lib/homeSearchShare'
describe('homeSearchShare', () => {
it('builds share text from title and absolute URL', () => {
expect(
buildHomeSearchShareText('Atividade X', 'https://campanha.test/campanha/atividades/x'),
).toBe('Atividade X\nhttps://campanha.test/campanha/atividades/x')
})
it('builds wa.me text-only share URL', () => {
const href = buildWhatsAppTextShareUrl('Olá\nhttps://example.com')
expect(href).toBe('https://wa.me/?text=Ol%C3%A1%0Ahttps%3A%2F%2Fexample.com')
})
it('falls back to whatsapp strategy when navigator.share is unavailable', () => {
expect(resolveHomeSearchShareStrategy()).toBe('whatsapp')
})
it('builds WhatsApp share href for desktop fallback', () => {
const href = buildHomeSearchWhatsAppShareHref(
'Demanda Y',
'https://campanha.test/campanha/demandas/y',
)
expect(href).toContain('https://wa.me/?text=')
expect(href).toContain('Demanda+Y')
expect(href).toContain(encodeURIComponent('https://campanha.test/campanha/demandas/y'))
})
})