diff --git a/app/push_notifications/push_notifications.ios.js b/app/push_notifications/push_notifications.ios.js index f6b96b35f..fd8d22410 100644 --- a/app/push_notifications/push_notifications.ios.js +++ b/app/push_notifications/push_notifications.ios.js @@ -214,7 +214,6 @@ class PushNotification { } if (ids.length) { - badgeCount -= ids.length; NotificationsIOS.removeDeliveredNotifications(ids); } diff --git a/app/push_notifications/push_notifications.ios.test.js b/app/push_notifications/push_notifications.ios.test.js index 62ee2e6c5..67947a246 100644 --- a/app/push_notifications/push_notifications.ios.test.js +++ b/app/push_notifications/push_notifications.ios.test.js @@ -2,11 +2,14 @@ // See LICENSE.txt for license information. import NotificationsIOS from 'react-native-notifications'; + +import * as ViewSelectors from 'app/selectors/views'; + import PushNotification from './push_notifications.ios'; jest.mock('react-native-notifications', () => { let badgesCount = 0; - let deliveredNotifications = {}; + let deliveredNotifications = []; return { getBadgesCount: jest.fn((callback) => callback(badgesCount)), @@ -90,4 +93,29 @@ describe('PushNotification', () => { expect(cancelAllLocalNotifications).toHaveBeenCalled(); expect(NotificationsIOS.cancelAllLocalNotifications).toHaveBeenCalled(); }); + + it('clearChannelNotifications should set app badge number from to delivered notification count when redux store is not set', () => { + PushNotification.reduxStore = null; + const setApplicationIconBadgeNumber = jest.spyOn(PushNotification, 'setApplicationIconBadgeNumber'); + const deliveredNotifications = [{identifier: 1}, {identifier: 2}]; + NotificationsIOS.setDeliveredNotifications(deliveredNotifications); + + PushNotification.clearChannelNotifications(); + expect(setApplicationIconBadgeNumber).toHaveBeenCalledWith(deliveredNotifications.length); + }); + + it('clearChannelNotifications should set app badge number from redux store when set', () => { + PushNotification.reduxStore = { + getState: jest.fn(), + }; + const setApplicationIconBadgeNumber = jest.spyOn(PushNotification, 'setApplicationIconBadgeNumber'); + const deliveredNotifications = [{identifier: 1}, {identifier: 2}]; + NotificationsIOS.setDeliveredNotifications(deliveredNotifications); + + const stateBadgeCount = 2 * deliveredNotifications.length; + ViewSelectors.getBadgeCount = jest.fn().mockReturnValue(stateBadgeCount); + + PushNotification.clearChannelNotifications(); + expect(setApplicationIconBadgeNumber).toHaveBeenCalledWith(stateBadgeCount); + }); });