diff --git a/src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.ts b/src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.ts index 351c73fd63821..e5004ae2bf0b8 100644 --- a/src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.ts +++ b/src/libs/Notification/PushNotification/ForegroundNotifications/index.ios.ts @@ -1,6 +1,5 @@ import Airship, {iOS} from '@ua/react-native-airship'; import shouldShowPushNotification from '@libs/Notification/PushNotification/shouldShowPushNotification'; -import {getIsMuted} from '@libs/Sound/BaseSound'; import type ForegroundNotificationsModule from './types'; function configureForegroundNotifications() { @@ -15,15 +14,7 @@ function configureForegroundNotifications() { // Set a callback to override our foreground presentation per notification depending on the app's current state. // Returning null keeps the default presentation. Returning [] uses no presentation (hides the notification). - Airship.push.iOS.setForegroundPresentationOptionsCallback((pushPayload) => { - if (!shouldShowPushNotification(pushPayload)) { - return Promise.resolve([]); - } - if (getIsMuted()) { - return Promise.resolve([iOS.ForegroundPresentationOption.List, iOS.ForegroundPresentationOption.Banner, iOS.ForegroundPresentationOption.Badge]); - } - return Promise.resolve(null); - }); + Airship.push.iOS.setForegroundPresentationOptionsCallback((pushPayload) => Promise.resolve(shouldShowPushNotification(pushPayload) ? null : [])); } function disableForegroundNotifications() { diff --git a/tests/unit/ForegroundNotificationsTest.ts b/tests/unit/ForegroundNotificationsTest.ts deleted file mode 100644 index 64c8fc99a9067..0000000000000 --- a/tests/unit/ForegroundNotificationsTest.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type {PushPayload} from '@ua/react-native-airship'; -import {iOS} from '@ua/react-native-airship'; - -const mockShouldShowPushNotification = jest.fn(); -jest.mock('@libs/Notification/PushNotification/shouldShowPushNotification', () => mockShouldShowPushNotification); - -const mockGetIsMuted = jest.fn(); -jest.mock('@libs/Sound/BaseSound', () => ({ - getIsMuted: mockGetIsMuted, -})); - -const fakePushPayload: PushPayload = { - alert: 'test notification', - extras: {payload: '{}'}, - notificationId: 'test-id', - title: 'Test', - subtitle: '', -}; - -type ForegroundCallback = (push: PushPayload) => Promise; - -function setupAndGetCallback(method: 'configureForegroundNotifications' | 'disableForegroundNotifications'): ForegroundCallback { - let callback: ForegroundCallback | undefined; - - jest.isolateModules(() => { - // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports - const AirshipModule = require('@ua/react-native-airship') as {default: {push: {iOS: {setForegroundPresentationOptionsCallback: jest.Mock}}}}; - const {setForegroundPresentationOptionsCallback} = AirshipModule.default.push.iOS; - setForegroundPresentationOptionsCallback.mockClear(); - - // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports - const ForegroundNotifications = require('@libs/Notification/PushNotification/ForegroundNotifications/index.ios') as { - default: {configureForegroundNotifications: () => void; disableForegroundNotifications: () => void}; - }; - ForegroundNotifications.default[method](); - - const lastCall = setForegroundPresentationOptionsCallback.mock.calls.at(-1) as ForegroundCallback[] | undefined; - callback = lastCall?.[0]; - }); - - if (!callback) { - throw new Error('Failed to capture foreground presentation options callback'); - } - return callback; -} - -describe('ForegroundNotifications iOS', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - - it('returns empty array when notification should not be shown', async () => { - mockShouldShowPushNotification.mockReturnValue(false); - const callback = setupAndGetCallback('configureForegroundNotifications'); - - const result = await callback(fakePushPayload); - expect(result).toEqual([]); - }); - - it('returns null (default presentation with sound) when not muted', async () => { - mockShouldShowPushNotification.mockReturnValue(true); - mockGetIsMuted.mockReturnValue(false); - const callback = setupAndGetCallback('configureForegroundNotifications'); - - const result = await callback(fakePushPayload); - expect(result).toBeNull(); - }); - - it('returns List, Banner, Badge without Sound when muted', async () => { - mockShouldShowPushNotification.mockReturnValue(true); - mockGetIsMuted.mockReturnValue(true); - const callback = setupAndGetCallback('configureForegroundNotifications'); - - const result = await callback(fakePushPayload); - expect(result).toEqual([iOS.ForegroundPresentationOption.List, iOS.ForegroundPresentationOption.Banner, iOS.ForegroundPresentationOption.Badge]); - }); - - it('disableForegroundNotifications sets callback that returns empty array', async () => { - const callback = setupAndGetCallback('disableForegroundNotifications'); - - const result = await callback(fakePushPayload); - expect(result).toEqual([]); - }); -});