mattermost-mobile/app/utils/push_notifications.test.js
Miguel Alatzar 5e5d3abd79 [MM-17145] [MM-18947] [MM-17110] [MM-14926] [MM-18646] Use patched v2.0.6 of react-native-notifications and fix Android badge number (#3382)
* Refactor custom push notification code

* Use react-native-notifications 2.0.6 and patch for scheduled notifs

* Fix patch

* iOS changes

* Fix delete

* Fix setting of badge number on Android

* Undo Reflect removal

* Undo removal of didReceiveRemoteNotification

* Use min importance for push notifs received while app is active

* Correctly set badge number after push notificaiton reply

* Fix tests

* Localize reply action text

* Add getDeliveredNotifications

* Fix identifier check and failing test

* Fix local push notif test for Android > 9
2019-10-22 21:18:59 +03:00

61 lines
No EOL
2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {PostTypes} from 'mattermost-redux/action_types';
import PushNotificationUtils from './push_notifications';
jest.mock('app/init/credentials', () => ({
getAppCredentials: jest.fn().mockReturnValue({
username: 'device-token,current-user-id',
password: 'token,url',
}),
getCurrentServerUrl: jest.fn().mockReturnValue('url'),
}));
jest.mock('app/actions/views/root', () => ({
createPostForNotificationReply: jest.fn().mockImplementation(() => {
return () => ({error: 'error'});
}),
}));
jest.mock('app/selectors/i18n', () => ({
getCurrentLocale: jest.fn().mockReturnValue('en'),
}));
jest.mock('react-native-notifications', () => {
return {
requestPermissions: jest.fn(),
addEventListener: jest.fn(),
NotificationAction: jest.fn(),
NotificationCategory: jest.fn(),
localNotification: jest.fn(),
};
});
const mockStore = configureMockStore([thunk]);
const store = mockStore({});
PushNotificationUtils.configure(store);
describe('PushNotifications', () => {
it('should add channel_id to failed push notification reply', async () => {
let notification = PushNotificationUtils.getNotification();
expect(notification).toBe(null);
const channelID = 'channel-id';
const data = {channel_id: channelID};
const text = 'text';
const completion = () => {};
await PushNotificationUtils.onPushNotificationReply(data, text, completion);
const storeActions = store.getActions();
const receivedPost = storeActions.some((action) => action.type === PostTypes.RECEIVED_POST);
expect(receivedPost).toBe(false);
notification = PushNotificationUtils.getNotification();
expect(notification.userInfo.channel_id).toBe(channelID);
});
});