|
| 1 | +/* global jest */ |
| 2 | +/** @jest-environment jsdom */ |
| 3 | +require('react-native-gesture-handler/jestSetup'); |
| 4 | + |
| 5 | +jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); |
| 6 | + |
| 7 | +// Mock react-native-haptic-feedback |
| 8 | +jest.mock('react-native-haptic-feedback', () => ({ |
| 9 | + trigger: jest.fn(), |
| 10 | +})); |
| 11 | + |
| 12 | +// Mock Segment Analytics |
| 13 | +jest.mock('@segment/analytics-react-native', () => { |
| 14 | + const mockClient = { |
| 15 | + add: jest.fn(), |
| 16 | + track: jest.fn(), |
| 17 | + identify: jest.fn(), |
| 18 | + screen: jest.fn(), |
| 19 | + group: jest.fn(), |
| 20 | + alias: jest.fn(), |
| 21 | + reset: jest.fn(), |
| 22 | + }; |
| 23 | + |
| 24 | + return { |
| 25 | + createClient: jest.fn(() => mockClient), |
| 26 | + EventPlugin: jest.fn(), |
| 27 | + PluginType: { |
| 28 | + ENRICHMENT: 'enrichment', |
| 29 | + DESTINATION: 'destination', |
| 30 | + BEFORE: 'before', |
| 31 | + }, |
| 32 | + }; |
| 33 | +}); |
| 34 | + |
| 35 | +// Mock react-native-keychain |
| 36 | +jest.mock('react-native-keychain', () => ({ |
| 37 | + SECURITY_LEVEL_ANY: 'MOCK_SECURITY_LEVEL_ANY', |
| 38 | + SECURITY_LEVEL_SECURE_SOFTWARE: 'MOCK_SECURITY_LEVEL_SECURE_SOFTWARE', |
| 39 | + SECURITY_LEVEL_SECURE_HARDWARE: 'MOCK_SECURITY_LEVEL_SECURE_HARDWARE', |
| 40 | + setGenericPassword: jest.fn(), |
| 41 | + getGenericPassword: jest.fn(), |
| 42 | + resetGenericPassword: jest.fn(), |
| 43 | + ACCESSIBLE: { |
| 44 | + WHEN_UNLOCKED: 'AccessibleWhenUnlocked', |
| 45 | + AFTER_FIRST_UNLOCK: 'AccessibleAfterFirstUnlock', |
| 46 | + ALWAYS: 'AccessibleAlways', |
| 47 | + WHEN_PASSCODE_SET_THIS_DEVICE_ONLY: |
| 48 | + 'AccessibleWhenPasscodeSetThisDeviceOnly', |
| 49 | + WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'AccessibleWhenUnlockedThisDeviceOnly', |
| 50 | + AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: |
| 51 | + 'AccessibleAfterFirstUnlockThisDeviceOnly', |
| 52 | + ALWAYS_THIS_DEVICE_ONLY: 'AccessibleAlwaysThisDeviceOnly', |
| 53 | + }, |
| 54 | + ACCESS_CONTROL: { |
| 55 | + USER_PRESENCE: 'UserPresence', |
| 56 | + BIOMETRY_ANY: 'BiometryAny', |
| 57 | + BIOMETRY_CURRENT_SET: 'BiometryCurrentSet', |
| 58 | + DEVICE_PASSCODE: 'DevicePasscode', |
| 59 | + APPLICATION_PASSWORD: 'ApplicationPassword', |
| 60 | + BIOMETRY_ANY_OR_DEVICE_PASSCODE: 'BiometryAnyOrDevicePasscode', |
| 61 | + BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE: |
| 62 | + 'BiometryCurrentSetOrDevicePasscode', |
| 63 | + }, |
| 64 | +})); |
| 65 | + |
| 66 | +// Mock AsyncStorage |
| 67 | +jest.mock('@react-native-async-storage/async-storage', () => ({ |
| 68 | + setItem: jest.fn(), |
| 69 | + getItem: jest.fn(), |
| 70 | + removeItem: jest.fn(), |
| 71 | + mergeItem: jest.fn(), |
| 72 | + clear: jest.fn(), |
| 73 | + getAllKeys: jest.fn(), |
| 74 | + flushGetRequests: jest.fn(), |
| 75 | + multiGet: jest.fn(), |
| 76 | + multiSet: jest.fn(), |
| 77 | + multiRemove: jest.fn(), |
| 78 | + multiMerge: jest.fn(), |
| 79 | +})); |
| 80 | + |
| 81 | +// Mock react-native-check-version |
| 82 | +jest.mock('react-native-check-version', () => ({ |
| 83 | + checkVersion: jest.fn().mockResolvedValue({ |
| 84 | + needsUpdate: false, |
| 85 | + currentVersion: '1.0.0', |
| 86 | + latestVersion: '1.0.0', |
| 87 | + }), |
| 88 | +})); |
| 89 | + |
| 90 | +// Mock @react-native-community/netinfo |
| 91 | +jest.mock('@react-native-community/netinfo', () => ({ |
| 92 | + addEventListener: jest.fn(), |
| 93 | + useNetInfo: jest.fn().mockReturnValue({ |
| 94 | + type: 'wifi', |
| 95 | + isConnected: true, |
| 96 | + isInternetReachable: true, |
| 97 | + details: { |
| 98 | + isConnectionExpensive: false, |
| 99 | + cellularGeneration: '4g', |
| 100 | + }, |
| 101 | + }), |
| 102 | + fetch: jest.fn(), |
| 103 | +})); |
| 104 | + |
| 105 | +// Mock react-native-nfc-manager |
| 106 | +jest.mock('react-native-nfc-manager', () => ({ |
| 107 | + start: jest.fn(), |
| 108 | + isSupported: jest.fn().mockResolvedValue(true), |
| 109 | + isEnabled: jest.fn().mockResolvedValue(true), |
| 110 | + registerTagEvent: jest.fn(), |
| 111 | + unregisterTagEvent: jest.fn(), |
| 112 | + requestTechnology: jest.fn(), |
| 113 | + cancelTechnologyRequest: jest.fn(), |
| 114 | + getTag: jest.fn(), |
| 115 | + setAlertMessage: jest.fn(), |
| 116 | + sendMifareCommand: jest.fn(), |
| 117 | + sendCommandAPDU: jest.fn(), |
| 118 | + transceive: jest.fn(), |
| 119 | + getMaxTransceiveLength: jest.fn(), |
| 120 | + setTimeout: jest.fn(), |
| 121 | + connect: jest.fn(), |
| 122 | + close: jest.fn(), |
| 123 | + cleanUpTag: jest.fn(), |
| 124 | + default: { |
| 125 | + start: jest.fn(), |
| 126 | + isSupported: jest.fn().mockResolvedValue(true), |
| 127 | + isEnabled: jest.fn().mockResolvedValue(true), |
| 128 | + registerTagEvent: jest.fn(), |
| 129 | + unregisterTagEvent: jest.fn(), |
| 130 | + requestTechnology: jest.fn(), |
| 131 | + cancelTechnologyRequest: jest.fn(), |
| 132 | + getTag: jest.fn(), |
| 133 | + setAlertMessage: jest.fn(), |
| 134 | + sendMifareCommand: jest.fn(), |
| 135 | + sendCommandAPDU: jest.fn(), |
| 136 | + transceive: jest.fn(), |
| 137 | + getMaxTransceiveLength: jest.fn(), |
| 138 | + setTimeout: jest.fn(), |
| 139 | + connect: jest.fn(), |
| 140 | + close: jest.fn(), |
| 141 | + cleanUpTag: jest.fn(), |
| 142 | + }, |
| 143 | +})); |
| 144 | + |
| 145 | +// Mock react-native-passport-reader |
| 146 | +jest.mock('react-native-passport-reader', () => ({ |
| 147 | + default: { |
| 148 | + initialize: jest.fn(), |
| 149 | + scanPassport: jest.fn(), |
| 150 | + readPassport: jest.fn(), |
| 151 | + cancelPassportRead: jest.fn(), |
| 152 | + }, |
| 153 | +})); |
| 154 | + |
| 155 | +// Mock @stablelib packages |
| 156 | +jest.mock('@stablelib/cbor', () => ({ |
| 157 | + encode: jest.fn(), |
| 158 | + decode: jest.fn(), |
| 159 | +})); |
| 160 | + |
| 161 | +jest.mock('@stablelib/utf8', () => ({ |
| 162 | + encode: jest.fn(), |
| 163 | + decode: jest.fn(), |
| 164 | +})); |
| 165 | + |
| 166 | +// Mock @react-native-google-signin/google-signin |
| 167 | +jest.mock('@react-native-google-signin/google-signin', () => ({ |
| 168 | + GoogleSignin: { |
| 169 | + configure: jest.fn(), |
| 170 | + hasPlayServices: jest.fn().mockResolvedValue(true), |
| 171 | + signIn: jest.fn().mockResolvedValue({ |
| 172 | + user: { |
| 173 | + id: 'mock-user-id', |
| 174 | + |
| 175 | + name: 'Mock User', |
| 176 | + photo: 'mock-photo-url', |
| 177 | + }, |
| 178 | + }), |
| 179 | + signOut: jest.fn(), |
| 180 | + revokeAccess: jest.fn(), |
| 181 | + isSignedIn: jest.fn().mockResolvedValue(false), |
| 182 | + getCurrentUser: jest.fn().mockResolvedValue(null), |
| 183 | + getTokens: jest.fn().mockResolvedValue({ |
| 184 | + accessToken: 'mock-access-token', |
| 185 | + idToken: 'mock-id-token', |
| 186 | + }), |
| 187 | + }, |
| 188 | + statusCodes: { |
| 189 | + SIGN_IN_REQUIRED: 'SIGN_IN_REQUIRED', |
| 190 | + IN_PROGRESS: 'IN_PROGRESS', |
| 191 | + PLAY_SERVICES_NOT_AVAILABLE: 'PLAY_SERVICES_NOT_AVAILABLE', |
| 192 | + }, |
| 193 | +})); |
| 194 | + |
| 195 | +// Mock react-native-cloud-storage |
| 196 | +jest.mock('react-native-cloud-storage', () => { |
| 197 | + const mockCloudStorage = { |
| 198 | + setProviderOptions: jest.fn(), |
| 199 | + isCloudAvailable: jest.fn().mockResolvedValue(true), |
| 200 | + createFolder: jest.fn(), |
| 201 | + deleteFolder: jest.fn(), |
| 202 | + listFiles: jest.fn(), |
| 203 | + readFile: jest.fn(), |
| 204 | + writeFile: jest.fn(), |
| 205 | + deleteFile: jest.fn(), |
| 206 | + getFileInfo: jest.fn(), |
| 207 | + getStorageInfo: jest.fn(), |
| 208 | + getProvider: jest.fn(), |
| 209 | + mkdir: jest.fn(), |
| 210 | + exists: jest.fn(), |
| 211 | + rmdir: jest.fn(), |
| 212 | + }; |
| 213 | + |
| 214 | + return { |
| 215 | + __esModule: true, |
| 216 | + CloudStorage: mockCloudStorage, |
| 217 | + CloudStorageScope: { |
| 218 | + AppData: 'AppData', |
| 219 | + Documents: 'Documents', |
| 220 | + Full: 'Full', |
| 221 | + }, |
| 222 | + CloudStorageProvider: { |
| 223 | + GoogleDrive: 'GoogleDrive', |
| 224 | + ICloud: 'ICloud', |
| 225 | + }, |
| 226 | + }; |
| 227 | +}); |
| 228 | + |
| 229 | +// Mock @react-native-clipboard/clipboard |
| 230 | +jest.mock('@react-native-clipboard/clipboard', () => ({ |
| 231 | + getString: jest.fn().mockResolvedValue(''), |
| 232 | + setString: jest.fn(), |
| 233 | + hasString: jest.fn().mockResolvedValue(false), |
| 234 | +})); |
| 235 | + |
| 236 | +// Mock react-native-localize |
| 237 | +jest.mock('react-native-localize', () => ({ |
| 238 | + getLocales: jest.fn().mockReturnValue([ |
| 239 | + { |
| 240 | + countryCode: 'US', |
| 241 | + languageTag: 'en-US', |
| 242 | + languageCode: 'en', |
| 243 | + isRTL: false, |
| 244 | + }, |
| 245 | + ]), |
| 246 | + getCountry: jest.fn().mockReturnValue('US'), |
| 247 | + getTimeZone: jest.fn().mockReturnValue('America/New_York'), |
| 248 | + getCurrencies: jest.fn().mockReturnValue(['USD']), |
| 249 | + getTemperatureUnit: jest.fn().mockReturnValue('celsius'), |
| 250 | + getFirstWeekDay: jest.fn().mockReturnValue(0), |
| 251 | + uses24HourClock: jest.fn().mockReturnValue(false), |
| 252 | + usesMetricSystem: jest.fn().mockReturnValue(false), |
| 253 | + findBestAvailableLanguage: jest.fn().mockReturnValue({ |
| 254 | + languageTag: 'en-US', |
| 255 | + isRTL: false, |
| 256 | + }), |
| 257 | +})); |
0 commit comments