diff --git a/scripts/lib/e2e-affected-manifest.mjs b/scripts/lib/e2e-affected-manifest.mjs index 459b3ffe..9b277020 100644 --- a/scripts/lib/e2e-affected-manifest.mjs +++ b/scripts/lib/e2e-affected-manifest.mjs @@ -71,6 +71,7 @@ export const E2E_AFFECTED_MANIFEST = [ 'src/utilities/homeSearch', 'src/utilities/campaignDashboardData', 'src/lib/campaignHomeSearchHits', + 'src/lib/homeSearchShare', ], specs: ['campaignHomeActions'], }, diff --git a/src/components/campaign/dashboard/HomeSearchShareAction.tsx b/src/components/campaign/dashboard/HomeSearchShareAction.tsx index 59bfe9c4..fdce62ca 100644 --- a/src/components/campaign/dashboard/HomeSearchShareAction.tsx +++ b/src/components/campaign/dashboard/HomeSearchShareAction.tsx @@ -21,11 +21,10 @@ export const HomeSearchShareAction = ({ title: string detailPath: string }) => { - const strategy = resolveHomeSearchShareStrategy() - const handleShare = async () => { const absoluteUrl = buildHomeSearchDetailUrl(detailPath) const shareText = buildHomeSearchShareText(title, absoluteUrl) + const strategy = resolveHomeSearchShareStrategy() if (strategy === 'native') { try { diff --git a/src/lib/homeSearchShare.ts b/src/lib/homeSearchShare.ts index 9ee7b79e..5c895717 100644 --- a/src/lib/homeSearchShare.ts +++ b/src/lib/homeSearchShare.ts @@ -10,7 +10,9 @@ export const buildWhatsAppTextShareUrl = (message: string): string => { } const canUseNativeWebShare = (): boolean => - typeof navigator !== 'undefined' && typeof navigator.share === 'function' + typeof window !== 'undefined' && + typeof navigator !== 'undefined' && + typeof navigator.share === 'function' export type HomeSearchShareStrategy = 'native' | 'whatsapp' diff --git a/tests/unit/homeSearchRowActions.unit.spec.tsx b/tests/unit/homeSearchRowActions.unit.spec.tsx index d0f0c76a..1e2a0050 100644 --- a/tests/unit/homeSearchRowActions.unit.spec.tsx +++ b/tests/unit/homeSearchRowActions.unit.spec.tsx @@ -1,10 +1,14 @@ -import { fireEvent, render, screen } from '@testing-library/react' -import { describe, expect, it, vi } from 'vitest' +import { cleanup, fireEvent, render, screen } from '@testing-library/react' +import { afterEach, describe, expect, it, vi } from 'vitest' import { HomeSearchHitRow } from '@/components/campaign/dashboard/HomeSearchHitRow' import { HomeSearchShareAction } from '@/components/campaign/dashboard/HomeSearchShareAction' import { HomeSearchWhatsAppAction } from '@/components/campaign/dashboard/HomeSearchWhatsAppAction' +afterEach(() => { + cleanup() +}) + describe('HomeSearchWhatsAppAction', () => { it('renders WhatsApp link when phone normalizes', () => { render()