/** * Module stubs for native / third-party packages that cannot run under jest. * * Registered in tests/setup.ts via jest.mock factories. Each factory returns the * module shape the app expects (default export and/or named exports). * * These are deliberately permissive: tests that need to assert behaviour should * spy on the returned functions (e.g. `Linking.openURL`) or override the module * themselves. */ import React from 'react' import { View } from 'react-native' /** react-native-webview: render a plain View carrying the source html. */ export function webviewMock() { const WebView = ({ source }: { source?: { html?: string } }) => React.createElement(View, { testID: 'mock-webview', accessibilityLabel: source?.html }) return { __esModule: true, WebView, default: WebView } } /** expo-updates: no update available by default (UpdateChecker). */ export function updatesMock() { return { __esModule: true, checkForUpdateAsync: jest.fn(async () => ({ isAvailable: false })), fetchUpdateAsync: jest.fn(async () => ({})), reloadAsync: jest.fn(async () => {}), isEnabled: true, } } /** expo-linking. */ export function linkingMock() { return { __esModule: true, openURL: jest.fn(async () => true), canOpenURL: jest.fn(async () => true), createURL: (path: string) => path, getInitialURL: jest.fn(async () => null), addEventListener: jest.fn(() => ({ remove: jest.fn() })), } } /** expo-location: permissions granted, a fixed position, empty geocode. */ export function locationMock() { return { __esModule: true, Accuracy: { Lowest: 1, Low: 2, Balanced: 3, High: 4, Highest: 5 }, requestForegroundPermissionsAsync: jest.fn(async () => ({ status: 'granted', granted: true, })), getForegroundPermissionsAsync: jest.fn(async () => ({ status: 'granted', granted: true, })), hasServicesEnabledAsync: jest.fn(async () => true), getCurrentPositionAsync: jest.fn(async () => ({ coords: { latitude: 17.385, longitude: 78.4867, accuracy: 5 }, timestamp: Date.now(), })), reverseGeocodeAsync: jest.fn(async () => [ { street: 'Test Street', city: 'Hyderabad', region: 'Telangana', postalCode: '500001' }, ]), } } /** expo-notifications: benign no-ops so the provider mounts. */ export function notificationsMock() { return { __esModule: true, setNotificationHandler: jest.fn(), getPermissionsAsync: jest.fn(async () => ({ status: 'granted', granted: true })), requestPermissionsAsync: jest.fn(async () => ({ status: 'granted', granted: true })), getExpoPushTokenAsync: jest.fn(async () => ({ data: 'ExponentPushToken[test]' })), getDevicePushTokenAsync: jest.fn(async () => ({ data: 'test' })), setNotificationChannelAsync: jest.fn(async () => null), getLastNotificationResponseAsync: jest.fn(async () => null), addNotificationReceivedListener: jest.fn(() => ({ remove: jest.fn() })), addNotificationResponseReceivedListener: jest.fn(() => ({ remove: jest.fn() })), AndroidImportance: { MAX: 5, HIGH: 4, DEFAULT: 3 }, } } /** expo-secure-store: in-memory backing for common-ui's StorageService. */ export function secureStoreMock() { const store = new Map() return { __esModule: true, isAvailableAsync: jest.fn(async () => true), getItemAsync: jest.fn(async (key: string) => store.get(key) ?? null), setItemAsync: jest.fn(async (key: string, value: string) => { store.set(key, value) }), deleteItemAsync: jest.fn(async (key: string) => { store.delete(key) }), getItem: jest.fn((key: string) => store.get(key) ?? null), setItem: jest.fn((key: string, value: string) => { store.set(key, value) }), deleteItem: jest.fn((key: string) => { store.delete(key) }), } } /** react-native-razorpay: Checkout.open resolves with a success payload. */ export function razorpayMock() { class Checkout { static open = jest.fn(async () => ({ razorpay_payment_id: 'pay_test', razorpay_order_id: 'order_test', razorpay_signature: 'sig_test', })) } return { __esModule: true, default: Checkout } }