diff --git a/__mocks__/@ua/react-native-airship.js b/__mocks__/@ua/react-native-airship.js deleted file mode 100644 index 65e7c1a8b97e..000000000000 --- a/__mocks__/@ua/react-native-airship.js +++ /dev/null @@ -1,42 +0,0 @@ -const EventType = { - NotificationResponse: 'notificationResponse', - PushReceived: 'pushReceived', -}; - -const iOS = { - ForegroundPresentationOption: { - Alert: 'alert', - Sound: 'sound', - Badge: 'badge', - }, -}; - -const Airship = { - setUserNotificationsEnabled: jest.fn(), - addListener: jest.fn(), - removeAllListeners: jest.fn(), - setBadgeNumber: jest.fn(), - push: { - iOS: { - setBadgeNumber: jest.fn(), - setForegroundPresentationOptions: jest.fn(), - setForegroundPresentationOptionsCallback: jest.fn(), - }, - android: { - setForegroundDisplayPredicate: jest.fn(), - }, - enableUserNotifications: () => Promise.resolve(false), - clearNotifications: jest.fn(), - getNotificationStatus: () => Promise.resolve({airshipOptIn: false, systemEnabled: false}), - getActiveNotifications: () => Promise.resolve([]), - }, - contact: { - identify: jest.fn(), - getNamedUserId: () => Promise.resolve(undefined), - reset: jest.fn(), - }, -}; - -export default Airship; - -export {EventType, iOS}; diff --git a/__mocks__/@ua/react-native-airship.ts b/__mocks__/@ua/react-native-airship.ts new file mode 100644 index 000000000000..ae7661ab672f --- /dev/null +++ b/__mocks__/@ua/react-native-airship.ts @@ -0,0 +1,53 @@ +import type {AirshipContact, AirshipPush, AirshipPushAndroid, AirshipPushIOS, AirshipRoot} from '@ua/react-native-airship'; +import {EventType as AirshipEventType, iOS as AirshipIOS} from '@ua/react-native-airship'; + +const EventType: Partial = { + NotificationResponse: AirshipEventType.NotificationResponse, + PushReceived: AirshipEventType.PushReceived, +}; + +const iOS: Partial = { + ForegroundPresentationOption: { + Sound: AirshipIOS.ForegroundPresentationOption.Sound, + Badge: AirshipIOS.ForegroundPresentationOption.Badge, + Banner: AirshipIOS.ForegroundPresentationOption.Banner, + List: AirshipIOS.ForegroundPresentationOption.List, + }, +}; + +const pushIOS: AirshipPushIOS = jest.fn().mockImplementation(() => ({ + setBadgeNumber: jest.fn(), + setForegroundPresentationOptions: jest.fn(), + setForegroundPresentationOptionsCallback: jest.fn(), +}))(); + +const pushAndroid: AirshipPushAndroid = jest.fn().mockImplementation(() => ({ + setForegroundDisplayPredicate: jest.fn(), +}))(); + +const push: AirshipPush = jest.fn().mockImplementation(() => ({ + iOS: pushIOS, + android: pushAndroid, + enableUserNotifications: () => Promise.resolve(false), + clearNotifications: jest.fn(), + getNotificationStatus: () => Promise.resolve({airshipOptIn: false, systemEnabled: false, airshipEnabled: false}), + getActiveNotifications: () => Promise.resolve([]), +}))(); + +const contact: AirshipContact = jest.fn().mockImplementation(() => ({ + identify: jest.fn(), + getNamedUserId: () => Promise.resolve(undefined), + reset: jest.fn(), + module: jest.fn(), +}))(); + +const Airship: Partial = { + addListener: jest.fn(), + removeAllListeners: jest.fn(), + push, + contact, +}; + +export default Airship; + +export {EventType, iOS}; diff --git a/jest/setup.ts b/jest/setup.ts index 55774ff136f1..6961ea17c79d 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -1,4 +1,3 @@ -import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock'; import '@shopify/flash-list/jestSetup'; import 'react-native-gesture-handler/jestSetup'; import mockStorage from 'react-native-onyx/dist/storage/__mocks__'; @@ -13,15 +12,14 @@ reanimatedJestUtils.setUpTests(); // https://reactnavigation.org/docs/testing/#mocking-native-modules jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); -// Clipboard requires mocking as NativeEmitter will be undefined with jest-runner. -// https://github.com/react-native-clipboard/clipboard#mocking-clipboard -jest.mock('@react-native-clipboard/clipboard', () => mockClipboard); - // Mock react-native-onyx storage layer because the SQLite storage layer doesn't work in jest. // Mocking this file in __mocks__ does not work because jest doesn't support mocking files that are not directly used in the testing project, // and we only want to mock the storage layer, not the whole Onyx module. jest.mock('react-native-onyx/dist/storage', () => mockStorage); +// Mock NativeEventEmitter as it is needed to provide mocks of libraries which include it +jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter'); + // Turn off the console logs for timing events. They are not relevant for unit tests and create a lot of noise jest.spyOn(console, 'debug').mockImplementation((...params) => { if (params[0].indexOf('Timing:') === 0) {