Don't subtract from badge count (#4135)

This commit is contained in:
Miguel Alatzar 2020-04-09 11:18:54 -07:00 committed by GitHub
parent 1486a55aeb
commit 514f6a68d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View file

@ -214,7 +214,6 @@ class PushNotification {
}
if (ids.length) {
badgeCount -= ids.length;
NotificationsIOS.removeDeliveredNotifications(ids);
}

View file

@ -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);
});
});