Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
2.7 kB · 89 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import {Share} from 'react-native'import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals'
jest.mock('#/components/Toast', () => ({show: jest.fn()}))
beforeEach(() => { jest.resetModules()})
afterEach(() => { jest.restoreAllMocks()})
function loadShareUrl({ platform, nativeModule,}: { platform: 'ios' | 'android' nativeModule?: { isAvailable: boolean shareText: jest.Mock<(text: string) => Promise<unknown>> }}) { jest.doMock('#/env', () => ({ IS_IOS: platform === 'ios', IS_ANDROID: platform === 'android', })) jest.doMock('@bsky.app/expo-bluesky-swiss-army', () => ({ Share: nativeModule ?? {isAvailable: false, shareText: jest.fn()}, })) const sharing: typeof import('./sharing') = require('./sharing') return sharing.shareUrl}
describe('shareUrl', () => { it('reports the chosen app on iOS', async () => { jest.spyOn(Share, 'share').mockResolvedValueOnce({ action: Share.sharedAction, activityType: 'net.whatsapp.WhatsApp.ShareExtension', }) const shareUrl = loadShareUrl({platform: 'ios'})
await expect(shareUrl('https://bsky.app/x')).resolves.toEqual({ status: 'shared', target: 'net.whatsapp.WhatsApp.ShareExtension', }) })
it('reports a dismissed share sheet on iOS', async () => { jest.spyOn(Share, 'share').mockResolvedValueOnce({ action: Share.dismissedAction, activityType: undefined, }) const shareUrl = loadShareUrl({platform: 'ios'})
await expect(shareUrl('https://bsky.app/x')).resolves.toEqual({ status: 'dismissed', }) })
it('uses the native module on Android when available', async () => { const shareText = jest .fn<(text: string) => Promise<unknown>>() .mockResolvedValue({action: 'sharedAction', target: 'com.whatsapp'}) const rnShare = jest.spyOn(Share, 'share') const shareUrl = loadShareUrl({ platform: 'android', nativeModule: {isAvailable: true, shareText}, })
await expect(shareUrl('https://bsky.app/x')).resolves.toEqual({ status: 'shared', target: 'com.whatsapp', }) expect(shareText).toHaveBeenCalledWith('https://bsky.app/x') expect(rnShare).not.toHaveBeenCalled() })
it('falls back to React Native Share on Android without the native module', async () => { const rnShare = jest.spyOn(Share, 'share').mockResolvedValueOnce({ action: Share.sharedAction, activityType: undefined, }) const shareUrl = loadShareUrl({platform: 'android'})
await expect(shareUrl('https://bsky.app/x')).resolves.toBeUndefined() expect(rnShare).toHaveBeenCalledWith({message: 'https://bsky.app/x'}) })})